From 7660dbc5fd4c6be46cb38ee7234b3c5e01efea11 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Sat, 29 Sep 2018 20:14:37 +0200 Subject: [PATCH] Add handy 'add_get_parameters' templatetag --- profiles/templates/profiles/profile_list.html | 2 ++ profiles/views.py | 4 ++++ scipost/templatetags/add_get_parameters.py | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 scipost/templatetags/add_get_parameters.py diff --git a/profiles/templates/profiles/profile_list.html b/profiles/templates/profiles/profile_list.html index ae62b5c60..8b05b7979 100644 --- a/profiles/templates/profiles/profile_list.html +++ b/profiles/templates/profiles/profile_list.html @@ -1,6 +1,7 @@ {% extends 'scipost/_personal_page_base.html' %} {% load bootstrap %} +{% load add_get_parameters %} {% block breadcrumb_items %} {{ block.super }} @@ -15,6 +16,7 @@ <div class="row"> <div class="col-12"> <p> + View Profiles <a href="{% add_get_parameters contributor=True %}">with</a> or <a href="{% add_get_parameters contributor=False %}">without</a> an associated Contributor <ul class="list-inline"> <li class="list-inline-item"> <a href="{% url 'profiles:profiles' %}">View all</a> or view by discipline/subject area: diff --git a/profiles/views.py b/profiles/views.py index acffe4e3e..04ea25cd2 100644 --- a/profiles/views.py +++ b/profiles/views.py @@ -85,6 +85,10 @@ class ProfileListView(PermissionsMixin, ListView): queryset = queryset.filter(discipline=self.request.GET['discipline'].lower()) if self.request.GET.get('expertise', None): queryset = queryset.filter(expertises__contains=[self.request.GET['expertise']]) + if self.request.GET.get('contributor', None) == 'False': + queryset = queryset.filter(contributor=None) + elif self.request.GET.get('contributor', None) == 'True': + queryset = queryset.exclude(contributor=None) return queryset def get_context_data(self, **kwargs): diff --git a/scipost/templatetags/add_get_parameters.py b/scipost/templatetags/add_get_parameters.py new file mode 100644 index 000000000..36f74ca82 --- /dev/null +++ b/scipost/templatetags/add_get_parameters.py @@ -0,0 +1,21 @@ +__copyright__ = "Copyright 2016-2018, Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +from django import template + +register = template.Library() + + +@register.simple_tag(takes_context=True) +def add_get_parameters(context, **kwargs): + parameters = context['request'].GET.copy() + for k, v in kwargs.items(): + if v is not None: + parameters[k] = v + if parameters: + params = '?' + for k, v in parameters.items(): + params += '&%s=%s' % (k, v) + return params.replace('?&', '?') + return '' -- GitLab