Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: tests/test_site/globals/get_pages_metadata.py

Issue 29370597: Issue 4687 - Add Context Function get_pages_metadata to Test Site (Closed)
Left Patch Set: realized that later when we add json the filter syntax will have to change anyway. Created March 10, 2017, 11:53 a.m.
Right Patch Set: Created March 17, 2017, 8:34 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « tests/expected_output/sitemap ('k') | tests/test_site/pages/sitemap.tmpl » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import re 1 import re
2 from jinja2 import contextfunction 2 from jinja2 import contextfunction
3 3
4 4
5 @contextfunction 5 @contextfunction
6 def get_pages_metadata(context, filters=None): 6 def get_pages_metadata(context, filters=None):
7 if not isinstance(filters, dict) and filters: 7 if not isinstance(filters, dict) and filters:
8 raise TypeError('Filters are not a dictionary') 8 raise TypeError('Filters are not a dictionary')
9 9
10 return_data = [] 10 return_data = []
(...skipping 21 matching lines...) Expand all
32 return page_metadata 32 return page_metadata
33 33
34 34
35 def filter_metadata(filters, metadata): 35 def filter_metadata(filters, metadata):
36 if filters is None: 36 if filters is None:
37 return True 37 return True
38 for filter_name, filter_value in filters.items(): 38 for filter_name, filter_value in filters.items():
39 if filter_name not in metadata: 39 if filter_name not in metadata:
40 return False 40 return False
41 if isinstance(metadata[filter_name], list): 41 if isinstance(metadata[filter_name], list):
42 if isinstance(filter_value, basestring):
43 filter_value = [filter_value]
42 for option in filter_value: 44 for option in filter_value:
Vasily Kuznetsov 2017/03/15 18:02:58 How about the situation when the field is a list b
Jon Sonesen 2017/03/17 07:53:33 Odd, I thought I had actually changed this. But pe
43 if str(option) not in metadata[filter_name]: 45 if str(option) not in metadata[filter_name]:
44 return False 46 return False
45 if filter_value != metadata[filter_name]: 47 elif filter_value != metadata[filter_name]:
Vasily Kuznetsov 2017/03/15 18:02:58 Should not this be `elif` instead of `if`. It seem
Jon Sonesen 2017/03/17 07:53:33 Oh yeah, that is a good catch.
46 return False 48 return False
47 return True 49 return True
LEFTRIGHT

Powered by Google App Engine
This is Rietveld