From ddf19efc791510fde4615c00cc85299c213d5924 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Tue, 25 Apr 2017 14:05:46 +0200 Subject: [PATCH] organization filters --- apps/organizations/filters.py | 29 ++++++++++++++++ .../organizations/organization_box.html | 12 +++++++ .../organizations/organizations.html | 34 ++++++++++--------- apps/organizations/views.py | 5 ++- redakcja/templates/main.html | 12 +------ 5 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 apps/organizations/filters.py create mode 100644 apps/organizations/templates/organizations/organization_box.html diff --git a/apps/organizations/filters.py b/apps/organizations/filters.py new file mode 100644 index 00000000..f0556ced --- /dev/null +++ b/apps/organizations/filters.py @@ -0,0 +1,29 @@ +# -*- 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.forms.widgets import TextInput +from django.utils.translation import ugettext_lazy as _ + +from catalogue.filters import tag_filter +from organizations.models import Organization + + +class OrganizationFilterSet(django_filters.FilterSet): + name = django_filters.CharFilter( + lookup_expr='icontains', label='', + widget=TextInput(attrs={'placeholder': _('name')})) + language = tag_filter('language') + license = tag_filter('rights') + audience = tag_filter('audience') + + class Meta: + model = Organization + fields = [] + + def filter_by_tag(self, queryset, name, value): + if not value: + return queryset + return queryset.filter(document__tags__in=value).distinct() diff --git a/apps/organizations/templates/organizations/organization_box.html b/apps/organizations/templates/organizations/organization_box.html new file mode 100644 index 00000000..c5133da1 --- /dev/null +++ b/apps/organizations/templates/organizations/organization_box.html @@ -0,0 +1,12 @@ +{% load thumbnail %} + +
+ + {% if org.logo %} + {% thumbnail org.logo "160x100" format="PNG" padding=True as th %} + + {% endthumbnail %} + {% endif %} +
{{ org.name }}
+
+
diff --git a/apps/organizations/templates/organizations/organizations.html b/apps/organizations/templates/organizations/organizations.html index 89710c9f..98a65f6c 100644 --- a/apps/organizations/templates/organizations/organizations.html +++ b/apps/organizations/templates/organizations/organizations.html @@ -1,21 +1,23 @@ {% extends "catalogue/base.html" %} -{% load i18n thumbnail %} +{% load i18n %} -{% block inner_content %} - -

{% trans "Organizations" %}

-{% for org in organizations %} -
- - {% if org.logo %} - {% thumbnail org.logo "160x100" format="PNG" padding=True as th %} - - {% endthumbnail %} - {% endif %} -
{{ org.name }}
-
+{% block content %} +
+

{% trans "Organizations" %}

+
+
+
+

{% trans "Filters" %}

+
+ {{ filter_set.form.as_p }} + +
+
+
+ {% for org in filter_set.qs %} + {% include "organizations/organization_box.html" %} + {% endfor %} +
-{% endfor %} - {% endblock %} diff --git a/apps/organizations/views.py b/apps/organizations/views.py index 24f2436f..47aa5d34 100644 --- a/apps/organizations/views.py +++ b/apps/organizations/views.py @@ -7,6 +7,8 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.shortcuts import render, redirect from django.http import Http404 + +from organizations.filters import OrganizationFilterSet from .forms import OrganizationForm, UserCardForm from .models import Organization, Membership, UserCard @@ -120,6 +122,7 @@ def membership(request, pk): def organizations(request): + f = OrganizationFilterSet(request.GET, queryset=Organization.objects.all()) return render(request, "organizations/organizations.html", { - 'organizations': Organization.objects.all(), + 'filter_set': f, }) diff --git a/redakcja/templates/main.html b/redakcja/templates/main.html index 51ef989c..ef14a514 100644 --- a/redakcja/templates/main.html +++ b/redakcja/templates/main.html @@ -1,6 +1,5 @@ {% extends "catalogue/base.html" %} {% load i18n %} -{% load thumbnail %} {% load static %} @@ -46,16 +45,7 @@

{% trans "See active organizations and join" %}

{% for org in organizations %} -
- - {% if org.logo %} - {% thumbnail org.logo "160x100" format="PNG" padding=True as th %} - - {% endthumbnail %} - {% endif %} -
{{ org.name }}
-
-
+ {% include "organizations/organization_box.html" %} {% endfor %} {% if more_organizations %}

{% trans "More organizations" %}

-- 2.20.1