Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include date hierarchy in quick removal links #218

Merged
6 changes: 5 additions & 1 deletion admin_interface/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: django-admin-interface\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-26 02:56-0600\n"
"POT-Creation-Date: 2022-11-29 11:47-0600\n"
"PO-Revision-Date: 2018-12-30 19:13-0500\n"
"Last-Translator: Martin Vuelta <martin.vuelta@softbutterfly.io>\n"
"Language-Team: Spanish <dev@softbutterfly.io>\n"
Expand Down Expand Up @@ -296,3 +296,7 @@ msgstr " Por %(filter_title)s "
#: admin_interface/templates/admin/popup_response.html
msgid "Popup closing..."
msgstr "Cerando popup..."

#: admin_interface/templates/admin_interface/date_hierarchy_removal_link.html
msgid "Date filter"
msgstr ""
6 changes: 5 additions & 1 deletion admin_interface/locale/fa/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: django-admin-interface\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-26 02:56-0600\n"
"POT-Creation-Date: 2022-11-29 11:47-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Amir Ajorloo <amirajorloo@gmail.com>\n"
"Language-Team: Farsi <LL@li.org>\n"
Expand Down Expand Up @@ -295,3 +295,7 @@ msgstr " توسط %(filter_title)s "
#: admin_interface/templates/admin/popup_response.html
msgid "Popup closing..."
msgstr "پاپ آپ در حال بسته شدن..."

#: admin_interface/templates/admin_interface/date_hierarchy_removal_link.html
msgid "Date filter"
msgstr ""
Binary file modified admin_interface/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 5 additions & 1 deletion admin_interface/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-26 02:56-0600\n"
"POT-Creation-Date: 2022-11-29 11:47-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -292,3 +292,7 @@ msgstr " Par %(filter_title)s "
#: admin_interface/templates/admin/popup_response.html
msgid "Popup closing..."
msgstr "Fermeture de la modale..."

#: admin_interface/templates/admin_interface/date_hierarchy_removal_link.html
msgid "Date filter"
msgstr "Filtre de date"
6 changes: 5 additions & 1 deletion admin_interface/locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: django-admin-interface\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-26 02:56-0600\n"
"POT-Creation-Date: 2022-11-29 11:47-0600\n"
"PO-Revision-Date: 2018-12-30 19:13-0500\n"
"Last-Translator: Fabio Caccamo <fabio.caccamo@gmail.com>\n"
"Language-Team: Italian <LL@li.org>\n"
Expand Down Expand Up @@ -298,3 +298,7 @@ msgstr " Per %(filter_title)s "
#: admin_interface/templates/admin/popup_response.html
msgid "Popup closing..."
msgstr "Chiusura popup..."

#: admin_interface/templates/admin_interface/date_hierarchy_removal_link.html
msgid "Date filter"
msgstr ""
6 changes: 5 additions & 1 deletion admin_interface/locale/pl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: django-admin-interface\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-26 02:56-0600\n"
"POT-Creation-Date: 2022-11-29 11:47-0600\n"
"PO-Revision-Date: 2022-02-04 19:13-0500\n"
"Last-Translator: Kamil Paduszyński <kpaduszy@gmail.com>\n"
"Language-Team: Polish <LL@li.org>\n"
Expand Down Expand Up @@ -298,3 +298,7 @@ msgstr " po %(filter_title)s "
#: admin_interface/templates/admin/popup_response.html
msgid "Popup closing..."
msgstr "Zamykanie..."

#: admin_interface/templates/admin_interface/date_hierarchy_removal_link.html
msgid "Date filter"
msgstr ""
6 changes: 5 additions & 1 deletion admin_interface/locale/pt_BR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-26 02:56-0600\n"
"POT-Creation-Date: 2022-11-29 11:47-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -295,3 +295,7 @@ msgstr " por %(filter_title)s "
#: admin_interface/templates/admin/popup_response.html
msgid "Popup closing..."
msgstr "Pop-up fechando..."

#: admin_interface/templates/admin_interface/date_hierarchy_removal_link.html
msgid "Date filter"
msgstr ""
6 changes: 5 additions & 1 deletion admin_interface/locale/tr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: django-admin-interface\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-26 02:56-0600\n"
"POT-Creation-Date: 2022-11-29 11:47-0600\n"
"PO-Revision-Date: 2020-01-29 04:53+0300\n"
"Last-Translator: Ishak Okutan <ishak.oktn@gmail.com>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -300,3 +300,7 @@ msgstr " %(filter_title)s tarafından "
#: admin_interface/templates/admin/popup_response.html
msgid "Popup closing..."
msgstr "Popup kapanıyor..."

#: admin_interface/templates/admin_interface/date_hierarchy_removal_link.html
msgid "Date filter"
msgstr ""
13 changes: 10 additions & 3 deletions admin_interface/templates/admin/change_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
{% if cl.has_filters %}
<div id="changelist-filter">
<h2>{% translate 'Filter' %}</h2>
{% if cl.has_active_filters %}
{% get_admin_interface_active_date_hierarchy cl as active_date_hierarchy %}
{% get_admin_interface_setting "list_filter_removal_links" as list_filter_removal_links %}
{% if list_filter_removal_links %}
{% if cl.has_active_filters %}
{% if list_filter_removal_links %}
{% if active_date_hierarchy %}{% admin_interface_date_hierarchy_removal_link cl active_date_hierarchy %}{% endif %}
{% for spec in cl.filter_specs %}{% admin_interface_filter_removal_link cl spec %}{% endfor %}
<h3 id="changelist-filter-clear">
<a href="{{ cl.clear_all_filters_qs }}">{% translate "Clear all filters" %} &#10006;</a>
Expand All @@ -18,7 +20,12 @@ <h3 id="changelist-filter-clear">
{# Translators: don't translate this, the django catalog already contains it #}
<a href="{{ cl.clear_all_filters_qs }}">&#10006; {% translate "Clear all filters" %}</a>
</h3>
{% endif %}
{% endif %}
{% elif active_date_hierarchy and list_filter_removal_links %}
{% admin_interface_date_hierarchy_removal_link cl active_date_hierarchy %}
<h3 id="changelist-filter-clear">
<a href="{{ cl.clear_all_filters_qs }}">{% translate "Clear all filters" %} &#10006;</a>
</h3>
{% endif %}
{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
</div>
fabiocaccamo marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
<div class="changelist-filter-clear"><a href="{{ removal_link }}">
{% translate "Date filter" %}: <span>{{ date_value|date:date_format|capfirst }}</span> &#10006;
merwok marked this conversation as resolved.
Show resolved Hide resolved
</a></div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% load admin_interface_tags %}
{% if spec.lookup_val or spec.value %}
<div class="changelist-filter-clear"><a href="{% admin_interface_clear_filter_qs cl spec %}">
<div class="changelist-filter-clear"><a href="{{ removal_link }}">
{{ title|capfirst }}: <span>{{ selected_value }}</span> &#10006;
</a></div>
{% endif %}
53 changes: 49 additions & 4 deletions admin_interface/templatetags/admin_interface_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

import datetime
import hashlib
import re

Expand Down Expand Up @@ -103,9 +103,19 @@ def get_admin_interface_nocache():
return hash_string(__version__)


@simple_tag()
def admin_interface_clear_filter_qs(changelist, list_filter):
return changelist.get_query_string(remove=list_filter.expected_parameters())
@simple_tag(takes_context=False)
def get_admin_interface_active_date_hierarchy(changelist):
merwok marked this conversation as resolved.
Show resolved Hide resolved
date_field = changelist.date_hierarchy
if not date_field:
return

params = changelist.get_filters_params()
# link to clear all filters contains 'date_field__gte',
# only filters with specific year are really active
if f"{date_field}__year" not in params:
return

return date_field


@simple_tag()
Expand All @@ -120,11 +130,46 @@ def admin_interface_filter_removal_link(changelist, list_filter):
except (IndexError, KeyError):
value = "..."

removal_link = changelist.get_query_string(remove=list_filter.expected_parameters())

return template.render(
{
"cl": changelist,
"spec": list_filter,
"selected_value": value,
"title": title,
"removal_link": removal_link,
}
)


@simple_tag()
def admin_interface_date_hierarchy_removal_link(changelist, date_field):
tpl = get_template("admin_interface/date_hierarchy_removal_link.html")

params = changelist.get_filters_params()
date_params = [p for p in params if p.startswith(date_field)]

date_args = [int(params[f"{date_field}__year"]), 1, 1]
date_format = "Y"

if f"{date_field}__month" in params:
date_args[1] = int(params[f"{date_field}__month"])
date_format = "YEAR_MONTH_FORMAT"

if f"{date_field}__day" in params:
date_args[2] = int(params[f"{date_field}__day"])
date_format = "DATE_FORMAT"

date_value = datetime.date(*date_args)

removal_link = changelist.get_query_string(remove=date_params)

return tpl.render(
{
"cl": changelist,
"date_value": date_value,
"date_format": date_format,
"removal_link": removal_link,
}
)