Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 20 matching lines...) Expand all Loading... | |
31 page_metadata[name.strip()] = value | 31 page_metadata[name.strip()] = value |
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 for option in filter_value.split(','): | 41 if isinstance(metadata[filter_name], list): |
Vasily Kuznetsov
2017/03/10 10:23:38
We should probably only split if the `metadata[fil
Jon Sonesen
2017/03/10 11:01:32
I guess I thought that this didnt matter since jul
Jon Sonesen
2017/03/10 11:43:38
Actually in this case we will have to change the f
Vasily Kuznetsov
2017/03/15 18:02:57
Yeah, this is better. Splitting the filter values
| |
42 if isinstance(metadata[filter_name], list): | 42 if isinstance(filter_value, basestring): |
43 if option not in metadata[filter_name]: | 43 filter_value = [filter_value] |
44 for option in filter_value: | |
45 if str(option) not in metadata[filter_name]: | |
44 return False | 46 return False |
45 return True | 47 elif filter_value != metadata[filter_name]: |
Vasily Kuznetsov
2017/03/10 10:23:38
But if you return `True` here, would not this igno
Jon Sonesen
2017/03/10 11:01:32
I thought we were doing an 'or' selection so if on
Vasily Kuznetsov
2017/03/15 18:02:57
Yes, the docstring of the function in the issue sa
| |
46 if option != metadata[filter_name]: | |
47 return False | 48 return False |
48 return True | 49 return True |
LEFT | RIGHT |