From 9d8c588b78aa27a5ffd3a8a8646174c986f6de10 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 30 Jul 2020 15:49:59 +0200 Subject: [PATCH] Buttons list didn't work as well --- apps/note/tables.py | 2 - apps/note/views.py | 14 ++++ locale/de/LC_MESSAGES/django.po | 4 - locale/fr/LC_MESSAGES/django.po | 4 - static/js/alias.js | 4 +- templates/activity/activity_detail.html | 2 +- templates/activity/activity_entry.html | 2 +- templates/member/club_list.html | 2 +- templates/member/user_list.html | 2 +- templates/note/transactiontemplate_list.html | 77 ++++++-------------- templates/registration/future_user_list.html | 2 +- 11 files changed, 42 insertions(+), 73 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index a1385abc..cbfd2424 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -131,12 +131,10 @@ class ButtonTable(tables.Table): row_attrs = { 'class': lambda record: 'table-row ' + ('table-success' if record.display else 'table-danger'), 'id': lambda record: "row-" + str(record.pk), - 'data-href': lambda record: record.pk } model = TransactionTemplate exclude = ('id',) - order_by = ('type', '-display', 'destination__name', 'name',) edit = tables.LinkColumn('note:template_update', args=[A('pk')], diff --git a/apps/note/views.py b/apps/note/views.py index b62b0ae1..e856eec0 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -5,6 +5,7 @@ import json from django.conf import settings from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.contenttypes.models import ContentType +from django.db.models import Q from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, UpdateView from django_tables2 import SingleTableView @@ -72,6 +73,19 @@ class TransactionTemplateListView(ProtectQuerysetMixin, LoginRequiredMixin, Sing model = TransactionTemplate table_class = ButtonTable + def get_queryset(self, **kwargs): + """ + Filter the user list with the given pattern. + """ + qs = super().get_queryset().distinct() + if "search" in self.request.GET: + pattern = self.request.GET["search"] + qs = qs.filter(Q(name__iregex="^" + pattern) | Q(destination__club__name__iregex="^" + pattern)) + + qs = qs.order_by('-display', 'category__name', 'destination__club__name', 'name') + + return qs + class TransactionTemplateUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView): """ diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index 8618d9e5..fffde96a 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -1784,10 +1784,6 @@ msgstr "" msgid "Name of the button..." msgstr "" -#: templates/note/transactiontemplate_list.html:16 -msgid "Display visible buttons only" -msgstr "" - #: templates/note/transactiontemplate_list.html:21 msgid "New button" msgstr "" diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 16548d3b..2f499334 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -1846,10 +1846,6 @@ msgstr "Chercher un bouton" msgid "Name of the button..." msgstr "Nom du bouton ..." -#: templates/note/transactiontemplate_list.html:16 -msgid "Display visible buttons only" -msgstr "N'afficher que les boutons visibles uniquement" - #: templates/note/transactiontemplate_list.html:21 msgid "New button" msgstr "Nouveau bouton" diff --git a/static/js/alias.js b/static/js/alias.js index 267410da..cdb21b2b 100644 --- a/static/js/alias.js +++ b/static/js/alias.js @@ -13,7 +13,7 @@ "note": note_id } ).done(function(){ - $("#alias_table").load(location.href+ " #alias_table"); + $("#alias_table").load(location.pathname+ " #alias_table"); addMsg("Alias ajouté","success"); }) .fail(function(xhr, textStatus, error){ @@ -29,7 +29,7 @@ }) .done(function(){ addMsg('Alias supprimé','success'); - $("#alias_table").load(location.href + " #alias_table"); + $("#alias_table").load(location.pathname + " #alias_table"); }) .fail(function(xhr,textStatus, error){ errMsg(xhr.responseJSON); diff --git a/templates/activity/activity_detail.html b/templates/activity/activity_detail.html index 3a3de8d0..a955d194 100644 --- a/templates/activity/activity_detail.html +++ b/templates/activity/activity_detail.html @@ -92,7 +92,7 @@ }) .done(function() { addMsg('Invité supprimé','success'); - $("#guests_table").load(location.href + " #guests_table"); + $("#guests_table").load(location.pathname + " #guests_table"); }) .fail(function(xhr, textStatus, error) { errMsg(xhr.responseJSON); diff --git a/templates/activity/activity_entry.html b/templates/activity/activity_entry.html index a712228d..abf4eef8 100644 --- a/templates/activity/activity_entry.html +++ b/templates/activity/activity_entry.html @@ -51,7 +51,7 @@ if ((pattern === old_pattern || pattern === "") && !force) return; - $("#entry_table").load(location.href + "?search=" + pattern.replace(" ", "%20") + " #entry_table", init); + $("#entry_table").load(location.pathname + "?search=" + pattern.replace(" ", "%20") + " #entry_table", init); refreshBalance(); } diff --git a/templates/member/club_list.html b/templates/member/club_list.html index b43a186c..a69de324 100644 --- a/templates/member/club_list.html +++ b/templates/member/club_list.html @@ -36,7 +36,7 @@ function reloadTable() { let pattern = searchbar_obj.val(); - $("#club_table").load(location.href + "?search=" + pattern.replace(" ", "%20") + " #club_table", init); + $("#club_table").load(location.pathname + "?search=" + pattern.replace(" ", "%20") + " #club_table", init); } searchbar_obj.keyup(function() { diff --git a/templates/member/user_list.html b/templates/member/user_list.html index d7628882..bad37468 100644 --- a/templates/member/user_list.html +++ b/templates/member/user_list.html @@ -34,7 +34,7 @@ if (pattern === old_pattern || pattern === "") return; - $("#user_table").load(location.href + "?search=" + pattern.replace(" ", "%20") + " #user_table", init); + $("#user_table").load(location.pathname + "?search=" + pattern.replace(" ", "%20") + " #user_table", init); } searchbar_obj.keyup(function() { diff --git a/templates/note/transactiontemplate_list.html b/templates/note/transactiontemplate_list.html index 280f9faf..1d2342b9 100644 --- a/templates/note/transactiontemplate_list.html +++ b/templates/note/transactiontemplate_list.html @@ -9,14 +9,6 @@ {% trans "Search button" %} -
-
- -
-

{% trans "New button" %} @@ -36,66 +28,39 @@ {% endblock %} {% block extrajavascript %} - {% endblock %} diff --git a/templates/registration/future_user_list.html b/templates/registration/future_user_list.html index 1e10dcbb..c2c888fd 100644 --- a/templates/registration/future_user_list.html +++ b/templates/registration/future_user_list.html @@ -32,7 +32,7 @@ if (pattern === old_pattern || pattern === "") return; - $("#user_table").load(location.href + "?search=" + pattern.replace(" ", "%20") + " #user_table", init); + $("#user_table").load(location.pathname + "?search=" + pattern.replace(" ", "%20") + " #user_table", init); $(".table-row").click(function() { window.document.location = $(this).data("href");