diff --git a/apps/note/templates/note/amount_input.html b/apps/note/templates/note/amount_input.html index f451523409b40e285369c6c64234d495df44813b..43ac1687ea89922e20daf16583fe377d701f0bb5 100644 --- a/apps/note/templates/note/amount_input.html +++ b/apps/note/templates/note/amount_input.html @@ -1,12 +1,14 @@ +{# Select amount to transfert in € #} <div class="input-group"> <input class="form-control mx-auto d-block" type="number" {% if not widget.attrs.negative %}min="0"{% endif %} step="0.01" {% if widget.value != None and widget.value != "" %}value="{{ widget.value }}"{% endif %} name="{{ widget.name }}" - {% for name, value in widget.attrs.items %} + {# Other attributes are loaded #} + {% for name, value in widget.attrs.items %} {% ifnotequal value False %}{{ name }}{% ifnotequal value True %}="{{ value|stringformat:'s' }}"{% endifnotequal %}{% endifnotequal %} {% endfor %}> <div class="input-group-append"> <span class="input-group-text">€</span> </div> <p id="amount-required" class="invalid-feedback"></p> -</div> \ No newline at end of file +</div> diff --git a/apps/note/templates/note/conso_form.html b/apps/note/templates/note/conso_form.html index 29acb3de3af28d02993e30752cbc9642ce0edaad..18cac578ec0f7e0dccc46ea97c437fa98f4ee9c1 100644 --- a/apps/note/templates/note/conso_form.html +++ b/apps/note/templates/note/conso_form.html @@ -45,7 +45,7 @@ </div> </div> </div> - + {# Summary of consumption and consume button #} <div class="col-xl-5 d-none" id="consos_list_div"> <div class="card border-info shadow mb-4"> <div class="card-header"> @@ -91,7 +91,6 @@ </div> {# Regroup buttons under categories #} - {# {% regroup transaction_templates by category as categories %} #} <div class="card border-primary text-center shadow mb-4"> {# Tabs for button categories #} @@ -148,7 +147,7 @@ </div> </div> </div> - + {# history of transaction #} <div class="card shadow mb-4" id="history"> <div class="card-header"> <p class="card-text font-weight-bold"> diff --git a/apps/note/templates/note/transaction_form.html b/apps/note/templates/note/transaction_form.html index 4715e79f51d2ad934275e1aedb543ac0adc4616e..aec1f2e27ad1b0f8f13da8738d3357954a08a6c5 100644 --- a/apps/note/templates/note/transaction_form.html +++ b/apps/note/templates/note/transaction_form.html @@ -6,7 +6,7 @@ SPDX-License-Identifier: GPL-2.0-or-later {% load i18n static django_tables2 perms %} {% block content %} - +{# bandeau transfert/crédit/débit/activité #} <div class="row"> <div class="col-xl-12"> <div class="btn-group btn-group-toggle" style="width: 100%; padding: 0 0 2em 0" data-toggle="buttons"> @@ -34,8 +34,8 @@ SPDX-License-Identifier: GPL-2.0-or-later </div> </div> </div> - <div class="row"> + {# Preview note profile (picture, username and balance) #} <div class="col-md-3" id="note_infos_div"> <div class="card border-success shadow mb-4"> <a id="profile_pic_link" href="#"><img src="/media/pic/default.png" @@ -45,7 +45,7 @@ SPDX-License-Identifier: GPL-2.0-or-later </div> </div> </div> - + {# list of emitters #} <div class="col-md-3" id="emitters_div"> <div class="card border-success shadow mb-4"> <div class="card-header"> @@ -66,7 +66,7 @@ SPDX-License-Identifier: GPL-2.0-or-later </div> </div> </div> - +{# list of receiver #} <div class="col-md-3" id="dests_div"> <div class="card border-info shadow mb-4"> <div class="card-header"> @@ -83,7 +83,7 @@ SPDX-License-Identifier: GPL-2.0-or-later </div> </div> </div> - +{# Information on transaction (amount, reason, name,...) #} <div class="col-md-3" id="external_div"> <div class="card border-warning shadow mb-4"> <div class="card-header"> @@ -108,7 +108,7 @@ SPDX-License-Identifier: GPL-2.0-or-later <p id="reason-required" class="invalid-feedback"></p> </div> </div> - + {# in case of special transaction add identity information #} <div class="d-none" id="special_transaction_div"> <div class="form-row"> <div class="col-md-12"> @@ -149,7 +149,7 @@ SPDX-License-Identifier: GPL-2.0-or-later </div> </div> </div> - +{# transaction history #} <div class="card shadow mb-4" id="history"> <div class="card-header"> <p class="card-text font-weight-bold"> diff --git a/apps/note/templates/note/transactiontemplate_list.html b/apps/note/templates/note/transactiontemplate_list.html index 91b347285475ac5e111a1c78a936dab97cea78d0..76b116e993077fdc6362cf9153e589510ab22c16 100644 --- a/apps/note/templates/note/transactiontemplate_list.html +++ b/apps/note/templates/note/transactiontemplate_list.html @@ -5,6 +5,7 @@ {% block content %} <div class="row justify-content-center mb-4"> <div class="col-md-10 text-center"> + {# Search field , see js #} <input class="form-control mx-auto w-25" type="text" id="search_field" placeholder="{% trans "Name of the button..." %}" value="{{ request.GET.search }}"> <hr> <a class="btn btn-primary text-center my-1" href="{% url 'note:template_create' %}" data-turbolinks="false">{% trans "New button" %}</a> diff --git a/apps/note/views.py b/apps/note/views.py index 6aadb4ab674f96f5708dbcd88649aa202463c1a8..9b383b1f0205c44ef36c983c853302c76cad9911 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -29,21 +29,19 @@ class TransactionCreateView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTabl e.g. for donation/transfer between people and clubs or for credit/debit with :models:`note.NoteSpecial` """ template_name = "note/transaction_form.html" - + # SingleTableView creates `context["table"]` we will load it with transaction history model = Transaction # Transaction history table table_class = HistoryTable extra_context = {"title": _("Transfer money")} def get_queryset(self, **kwargs): + # retrieves only Transaction that user has the right to see. return Transaction.objects.filter( PermissionBackend.filter_queryset(self.request.user, Transaction, "view") ).order_by("-created_at").all()[:20] def get_context_data(self, **kwargs): - """ - Add some context variables in template such as page title - """ context = super().get_context_data(**kwargs) context['amount_widget'] = AmountInput(attrs={"id": "amount"}) context['polymorphic_ctype'] = ContentType.objects.get_for_model(Transaction).pk @@ -146,7 +144,7 @@ class TransactionTemplateUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, Up class ConsoView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): """ The Magic View that make people pay their beer and burgers. - (Most of the magic happens in the dark world of Javascript see consos.js) + (Most of the magic happens in the dark world of Javascript see `note_kfet/static/js/consos.js`) """ model = Transaction template_name = "note/conso_form.html" @@ -168,21 +166,25 @@ class ConsoView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): return super().dispatch(request, *args, **kwargs) def get_queryset(self, **kwargs): + """ + restrict to the transaction history the user can see. + """ return Transaction.objects.filter( PermissionBackend.filter_queryset(self.request.user, Transaction, "view") ).order_by("-created_at").all()[:20] def get_context_data(self, **kwargs): - """ - Add some context variables in template such as page title - """ context = super().get_context_data(**kwargs) + categories = TemplateCategory.objects.order_by('name').all() + # for each category, find which transaction templates the user can see. for category in categories: category.templates_filtered = category.templates.filter( PermissionBackend().filter_queryset(self.request.user, TransactionTemplate, "view") ).filter(display=True).order_by('name').all() + context['categories'] = [cat for cat in categories if cat.templates_filtered] + # some transactiontemplate are put forward to find them easily context['highlighted'] = TransactionTemplate.objects.filter(highlighted=True).filter( PermissionBackend().filter_queryset(self.request.user, TransactionTemplate, "view") ).order_by('name').all()