From c42a7745bc1a8272bb97fd080bcacc730ceb41f8 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 14 Mar 2020 19:00:20 +0100 Subject: [PATCH] Add most used buttons --- apps/note/models/transactions.py | 1 + apps/note/views.py | 7 +++++-- locale/fr/LC_MESSAGES/django.po | 4 ++-- static/js/consos.js | 1 + templates/note/conso_form.html | 18 +++++++++++++++--- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index 8997411a..89982fc6 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -68,6 +68,7 @@ class TransactionTemplate(models.Model): description = models.CharField( verbose_name=_('description'), max_length=255, + blank=True, ) class Meta: diff --git a/apps/note/views.py b/apps/note/views.py index 23326e5f..bf9021ba 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -124,8 +124,11 @@ class ConsoView(LoginRequiredMixin, SingleTableView): Add some context variables in template such as page title """ context = super().get_context_data(**kwargs) - context['transaction_templates'] = TransactionTemplate.objects.filter(display=True) \ - .order_by('category__name', 'name') + from django.db.models import Count + buttons = TransactionTemplate.objects.filter(display=True) \ + .annotate(clicks=Count('templatetransaction')).order_by('category__name', 'name') + context['transaction_templates'] = buttons + context['most_used'] = buttons.order_by('-clicks', 'name')[:10] context['title'] = _("Consumptions") context['polymorphic_ctype'] = ContentType.objects.get_for_model(TemplateTransaction).pk diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 99e1a6f1..78081ced 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -651,8 +651,8 @@ msgid "Consume!" msgstr "Consommer !" #: templates/note/conso_form.html:62 -msgid "The most used buttons will display here." -msgstr "Les boutons les plus utilisés apparaîtront ici." +msgid "Most used buttons" +msgstr "Boutons les plus utilisés" #: templates/note/conso_form.html:107 msgid "Edit" diff --git a/static/js/consos.js b/static/js/consos.js index df50bda2..dedcd75c 100644 --- a/static/js/consos.js +++ b/static/js/consos.js @@ -6,6 +6,7 @@ */ function refreshHistory() { $("#history").load("/note/consos/ #history"); + $("#most_used").load("/note/consos/ #most_used"); } $(document).ready(function() { diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 94185c16..c34cf80a 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -59,11 +59,23 @@
{# Show last used buttons #}
-
-

- {% trans "The most used buttons will display here." %} +

+

+ {% trans "Most used buttons" %}

+
+
+ {% for button in most_used %} + {% if button.display %} + + {% endif %} + {% endfor %} +
+
{# Regroup buttons under categories #}