Skip to content
Snippets Groups Projects
Unverified Commit b57f6e32 authored by Luke Murphy's avatar Luke Murphy
Browse files

Filter by tag from the table view.

parent 6b528b64
No related branches found
No related tags found
1 merge request!93Filter by tags.
Pipeline #2668 passed
......@@ -11,6 +11,7 @@ class HidAppConfig(AppConfig):
CategoryFilter,
LocationFilter,
TimeRangeFilter,
TagsFilter,
)
from hid.tabs.view_and_edit_table import ViewAndEditTableTab
from hid.widgets.term_count_chart import TermCountChartWidget
......@@ -21,6 +22,7 @@ class HidAppConfig(AppConfig):
register_filter('category', CategoryFilter())
register_filter('time_range', TimeRangeFilter())
register_filter('location', LocationFilter())
register_filter('tags', TagsFilter())
register_tab('view-and-edit-table', ViewAndEditTableTab())
......
......@@ -9,6 +9,13 @@ class CategoryFilter(object):
)
class TagsFilter(object):
def apply(self, filters, query_dict, **kwargs):
tags = kwargs.get('tags', None)
if tags is not None:
filters.update(tags=tags)
class TimeRangeFilter(object):
def apply(self, filters, query_dict, **kwargs):
start_time = query_dict.get('start_time', None)
......
......@@ -293,7 +293,7 @@
"name": "feedback",
"page": 1,
"position": 2,
"settings": "{\"label\":\"Feedback\",\"columns\":[\"select_item\",\"created\",\"timestamp\",\"body\",\"translation\",\"category\",\"location\"],\"filters\":{\"terms\":[]},\"dynamic_filters\":[\"time_range\",\"category\", \"location\"],\"categories\":[\"bangladesh-refugee-crisis-sectors\"]}",
"settings": "{\"label\":\"Feedback\",\"columns\":[\"select_item\",\"created\",\"timestamp\",\"body\",\"translation\",\"category\",\"location\"],\"filters\":{\"terms\":[]},\"dynamic_filters\":[\"time_range\",\"category\", \"location\", \"tags\"],\"categories\":[\"bangladesh-refugee-crisis-sectors\"]}",
"tab_type": "view-and-edit-table"
},
"model": "tabbed_page.tabinstance",
......
......@@ -84,7 +84,7 @@ class ItemTable(tables.Table):
Template = loader.get_template('hid/tags_column.html')
try:
tags = [term['name'] for term in record['terms']]
tags = filter(None, [term['name'] for term in record['terms']])
ctx = {'tags': ', '.join(tags)}
except KeyError:
ctx = {'tags': []}
......
......@@ -196,6 +196,8 @@ class ViewAndEditTableTab(object):
request.GET.pop('start_time')
if request.GET.get('end_time'):
request.GET.pop('end_time')
if request.GET.get('tags'):
request.GET.pop('tags')
else:
filters = kwargs.get('filters', {})
......@@ -223,6 +225,9 @@ class ViewAndEditTableTab(object):
if previously_selected_location is not False:
location_options.update({'selected': previously_selected_location})
if request.GET.get('tags', False):
filters.update(tags=request.GET['tags'])
items = self._get_items(request, **kwargs)
# Build the table
......
{% load i18n %}
<div class="filter-tags form-group input-group">
<label class="col-sm-3 control-label" for="tags-selector">{% trans "Tags" %}</label>
<div class="text-container">
<input style="width:140px;" type="text" placeholder="All Tags" name="tags">
</div>
</div>
......@@ -67,6 +67,10 @@ class ItemViewSet(viewsets.ModelViewSet, BulkDestroyModelMixin):
items = items.filter(terms__id=matches[0].id)
tags = self.request.query_params.get('tags', None)
if tags is not None:
items = items.filter(terms__name__icontains=tags)
location = self.request.query_params.get('location', None)
if location is not None:
items = items.filter(location__icontains=location)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment