organization filters
authorJan Szejko <janek37@gmail.com>
Tue, 25 Apr 2017 12:05:46 +0000 (14:05 +0200)
committerJan Szejko <janek37@gmail.com>
Tue, 25 Apr 2017 12:05:46 +0000 (14:05 +0200)
apps/organizations/filters.py [new file with mode: 0644]
apps/organizations/templates/organizations/organization_box.html [new file with mode: 0644]
apps/organizations/templates/organizations/organizations.html
apps/organizations/views.py
redakcja/templates/main.html

diff --git a/apps/organizations/filters.py b/apps/organizations/filters.py
new file mode 100644 (file)
index 0000000..f0556ce
--- /dev/null
@@ -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 (file)
index 0000000..c5133da
--- /dev/null
@@ -0,0 +1,12 @@
+{% load thumbnail %}
+
+<div style="width: 182px; height: 180px; position: relative; border: 1px solid #aaa; margin: 10px; display: inline-block; padding: 0; vertical-align: bottom">
+    <a style='display:block' href="{% url 'organizations_main' org.pk %}">
+    {% if org.logo %}
+        {% thumbnail org.logo "160x100" format="PNG"  padding=True as th %}
+        <img src="{{ th.url }}" style="margin: 10px;">
+        {% endthumbnail %}
+    {% endif %}
+    <div style="position: absolute; bottom: 10px; left: 10px; width: 160px; height: 40px; overflow:hidden">{{ org.name }}</div>
+    </a>
+</div>
index 89710c9..98a65f6 100644 (file)
@@ -1,21 +1,23 @@
 {% extends "catalogue/base.html" %}
 {% extends "catalogue/base.html" %}
-{% load i18n thumbnail %}
+{% load i18n %}
 
 
 
 
-{% block inner_content %}
-
-<h1>{% trans "Organizations" %}</h1>
-{% for org in organizations %}
-    <div style="width: 182px; height: 180px; position: relative; border: 1px solid #aaa; margin: 10px; display: inline-block; padding: 0px; vertical-align: bottom">
-        <a style='display:block' href="{% url 'organizations_main' org.pk %}">
-        {% if org.logo %}
-            {% thumbnail org.logo "160x100" format="PNG"  padding=True as th %}
-            <img src="{{ th.url }}" style="margin: 10px;">
-            {% endthumbnail %}
-        {% endif %}
-        <div style="position: absolute; bottom: 10px; left: 10px; width: 160px; height: 40px; overflow:hidden">{{ org.name }}</div>
-        </a>
+{% block content %}
+    <div class="row">
+        <h1 class="col-md-8 col-md-offset-3">{% trans "Organizations" %}</h1>
+    </div>
+    <div class="row">
+        <div class="col-md-2 col-md-offset-1">
+            <h3>{% trans "Filters" %}</h3>
+            <form action="" method="get">
+                {{ filter_set.form.as_p }}
+                <input type="submit" value="{% trans "Apply" %}" />
+            </form>
+        </div>
+        <div class="col-md-8">
+            {% for org in filter_set.qs %}
+                {% include "organizations/organization_box.html" %}
+            {% endfor %}
+        </div>
     </div>
     </div>
-{% endfor %}
-
 {% endblock %}
 {% endblock %}
index 24f2436..47aa5d3 100644 (file)
@@ -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 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
 
 from .forms import OrganizationForm, UserCardForm
 from .models import Organization, Membership, UserCard
 
@@ -120,6 +122,7 @@ def membership(request, pk):
 
 
 def organizations(request):
 
 
 def organizations(request):
+    f = OrganizationFilterSet(request.GET, queryset=Organization.objects.all())
     return render(request, "organizations/organizations.html", {
     return render(request, "organizations/organizations.html", {
-        'organizations': Organization.objects.all(),
+        'filter_set': f,
     })
     })
index 51ef989..ef14a51 100644 (file)
@@ -1,6 +1,5 @@
 {% extends "catalogue/base.html" %}
 {% load i18n %}
 {% extends "catalogue/base.html" %}
 {% load i18n %}
-{% load thumbnail %}
 {% load static %}
 
 
 {% load static %}
 
 
 <section>
 <h1>{% trans "See active organizations and join" %}</h1>
 {% for org in organizations %}
 <section>
 <h1>{% trans "See active organizations and join" %}</h1>
 {% for org in organizations %}
-    <div style="width: 182px; height: 180px; position: relative; border: 1px solid #aaa; margin: 10px; display: inline-block; padding: 0; vertical-align: bottom">
-        <a style='display:block' href="{% url 'organizations_main' org.pk %}">
-        {% if org.logo %}
-            {% thumbnail org.logo "160x100" format="PNG"  padding=True as th %}
-            <img src="{{ th.url }}" style="margin: 10px;">
-            {% endthumbnail %}
-        {% endif %}
-        <div style="position: absolute; bottom: 10px; left: 10px; width: 160px; height: 40px; overflow:hidden">{{ org.name }}</div>
-        </a>
-    </div>
+    {% include "organizations/organization_box.html" %}
 {% endfor %}
 {% if more_organizations %}
 <p style="text-align: right"><a href="{% url 'organizations' %}">{% trans "More organizations" %}</a></p>
 {% endfor %}
 {% if more_organizations %}
 <p style="text-align: right"><a href="{% url 'organizations' %}">{% trans "More organizations" %}</a></p>