--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+import django_filters
+from django.utils.functional import lazy
+from django_filters.filters import ModelMultipleChoiceFilter
+
+from catalogue.models import Document, Category
+
+
+def tag_filter(dc_tag):
+ category = Category.objects.get(dc_tag=dc_tag)
+ return ModelMultipleChoiceFilter(
+ queryset=category.tag_set.all(), label=lazy(lambda: category.label, unicode)(), method='filter_by_tag')
+
+
+class DocumentFilterSet(django_filters.FilterSet):
+ language = tag_filter('language')
+ license = tag_filter('rights')
+ audience = tag_filter('audience')
+
+ class Meta:
+ model = Document
+ fields = []
+
+ def filter_by_tag(self, queryset, name, value):
+ if not value:
+ return queryset
+ return queryset.filter(tags__in=value).distinct()
{% block inner_content %}
<h1>{% trans "Finished resources" %}</h1>
- {% for doc in objects_list %}
+ <form action="" method="get">
+ {{ filter_set.form.as_p }}
+ <input type="submit" />
+ </form>
+ {% for doc in filter_set.qs %}
{% include "catalogue/resource_box.html" with link_url='catalogue_html' %}
{% endfor %}
{% endblock %}
{% block inner_content %}
<h1>{% trans "Upcoming resources" %}</h1>
- {% for doc in objects_list %}
+ <form action="" method="get">
+ {{ filter_set.form.as_p }}
+ <input type="submit" />
+ </form>
+ {% for doc in filter_set.qs %}
{% include "catalogue/resource_box.html" with link_url='catalogue_preview' %}
{% endfor %}
{% endblock %}
from unidecode import unidecode
from catalogue import forms
+from catalogue.filters import DocumentFilterSet
from catalogue.forms import TagMultipleForm, TagSingleForm
from catalogue.helpers import active_tab
from catalogue.models import Category
def upcoming(request):
+ f = DocumentFilterSet(request.GET, queryset=Document.objects.filter(deleted=False).filter(publish_log=None))
return render(request, "catalogue/upcoming.html", {
- 'objects_list': Document.objects.filter(deleted=False).filter(publish_log=None),
+ 'filter_set': f,
})
def finished(request):
+ f = DocumentFilterSet(request.GET, queryset=Document.objects.filter(deleted=False).exclude(publish_log=None))
return render(request, "catalogue/finished.html", {
- 'objects_list': Document.objects.filter(deleted=False).exclude(publish_log=None),
+ 'filter_set': f,
})
'constance',
'constance.backends.database',
'honeypot',
+ 'django_filters',
'catalogue',
# 'cover',
django-modeltranslation>=0.12,<0.13
django-constance[database]
django-honeypot
+django-filter
celery>=3.1.12,<3.2
kombu>3.0,<3.1