Add most used buttons

This commit is contained in:
Yohann D'ANELLO 2020-03-14 19:00:20 +01:00 committed by Bombar Maxime
parent ad66380e1b
commit c42a7745bc
5 changed files with 24 additions and 7 deletions

View File

@ -68,6 +68,7 @@ class TransactionTemplate(models.Model):
description = models.CharField( description = models.CharField(
verbose_name=_('description'), verbose_name=_('description'),
max_length=255, max_length=255,
blank=True,
) )
class Meta: class Meta:

View File

@ -124,8 +124,11 @@ class ConsoView(LoginRequiredMixin, SingleTableView):
Add some context variables in template such as page title Add some context variables in template such as page title
""" """
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['transaction_templates'] = TransactionTemplate.objects.filter(display=True) \ from django.db.models import Count
.order_by('category__name', 'name') 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['title'] = _("Consumptions")
context['polymorphic_ctype'] = ContentType.objects.get_for_model(TemplateTransaction).pk context['polymorphic_ctype'] = ContentType.objects.get_for_model(TemplateTransaction).pk

View File

@ -651,8 +651,8 @@ msgid "Consume!"
msgstr "Consommer !" msgstr "Consommer !"
#: templates/note/conso_form.html:62 #: templates/note/conso_form.html:62
msgid "The most used buttons will display here." msgid "Most used buttons"
msgstr "Les boutons les plus utilisés apparaîtront ici." msgstr "Boutons les plus utilisés"
#: templates/note/conso_form.html:107 #: templates/note/conso_form.html:107
msgid "Edit" msgid "Edit"

View File

@ -6,6 +6,7 @@
*/ */
function refreshHistory() { function refreshHistory() {
$("#history").load("/note/consos/ #history"); $("#history").load("/note/consos/ #history");
$("#most_used").load("/note/consos/ #most_used");
} }
$(document).ready(function() { $(document).ready(function() {

View File

@ -59,11 +59,23 @@
<div class="col-sm-7 col-md-8" id="buttons_div"> <div class="col-sm-7 col-md-8" id="buttons_div">
{# Show last used buttons #} {# Show last used buttons #}
<div class="card shadow mb-4"> <div class="card shadow mb-4">
<div class="card-body text-nowrap" style="overflow:auto hidden"> <div class="card-header">
<p class="card-text text-muted font-weight-light font-italic"> <p class="card-text font-weight-bold">
{% trans "The most used buttons will display here." %} {% trans "Most used buttons" %}
</p> </p>
</div> </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> </div>
{# Regroup buttons under categories #} {# Regroup buttons under categories #}