diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index 8997411aefaa617122fb7141425294a1a16347ff..89982fc68861e78fe884d5b8a1f85403f8711fa0 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 23326e5fb3387c4ab7321fe3c17f384ca2e3757b..bf9021ba5e4539620acec31a125acb3ba4c7db76 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 99e1a6f1df69d28ed972ab0293e921f9892aac73..78081ceda11dea7b8144132926b75265bac96935 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 df50bda27e820593b09c42db3dbe68c547c2affe..dedcd75cfe30a51b830839acc18f381bb180f8a9 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 94185c16ba3a5955def5c20b77e0ec7e31f5999b..c34cf80ae570be6fc552d2638c445f1e95409c05 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -59,11 +59,23 @@ <div class="col-sm-7 col-md-8" id="buttons_div"> {# Show last used buttons #} <div class="card shadow mb-4"> - <div class="card-body text-nowrap" style="overflow:auto hidden"> - <p class="card-text text-muted font-weight-light font-italic"> - {% trans "The most used buttons will display here." %} + <div class="card-header"> + <p class="card-text font-weight-bold"> + {% trans "Most used buttons" %} </p> </div> + <div class="card-body text-nowrap" style="overflow:auto hidden"> + <div class="d-inline-flex flex-wrap justify-content-center" id="most_used"> + {% for button in most_used %} + {% if button.display %} + <button class="btn btn-outline-dark rounded-0 flex-fill" + id="button{{ button.id }}" name="button" value="{{ button.name }}"> + {{ button.name }} ({{ button.amount | pretty_money }}) + </button> + {% endif %} + {% endfor %} + </div> + </div> </div> {# Regroup buttons under categories #}