From f4fe0c98666f87ef79b48200706733d36c0f8840 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Mon, 9 Mar 2020 20:59:04 +0100 Subject: [PATCH 01/17] use django_tables2 for transactionTemplate --- apps/note/tables.py | 11 ++++++++++ apps/note/views.py | 8 ++++--- templates/note/transactiontemplate_list.html | 22 +++----------------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index e85fcbae..580cb91d 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -54,3 +54,14 @@ class AliasTable(tables.Table): 'td': {'class': 'col-sm-2'}, 'a': {'class': 'btn btn-danger'}}, text='delete', accessor='pk') + +class ButtonTable(tables.Table): + class Meta: + attrs = { + 'class': + 'table table condensed table-striped table-hover' + } + model = TransactionTemplate + + def render_amount(self, value): + return pretty_money(value) diff --git a/apps/note/views.py b/apps/note/views.py index 09846057..a3441ab3 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -8,9 +8,11 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, ListView, UpdateView +from django_tables2 import SingleTableView + from .forms import TransactionForm, TransactionTemplateForm, ConsoForm from .models import Transaction, TransactionTemplate, Alias, TemplateTransaction - +from .tables import ButtonTable class TransactionCreate(LoginRequiredMixin, CreateView): """ @@ -106,12 +108,12 @@ class TransactionTemplateCreateView(LoginRequiredMixin, CreateView): form_class = TransactionTemplateForm -class TransactionTemplateListView(LoginRequiredMixin, ListView): +class TransactionTemplateListView(LoginRequiredMixin, SingleTableView): """ List TransactionsTemplates """ model = TransactionTemplate - form_class = TransactionTemplateForm + table = ButtonTable class TransactionTemplateUpdateView(LoginRequiredMixin, UpdateView): diff --git a/templates/note/transactiontemplate_list.html b/templates/note/transactiontemplate_list.html index 62e4d164..e8881988 100644 --- a/templates/note/transactiontemplate_list.html +++ b/templates/note/transactiontemplate_list.html @@ -1,23 +1,7 @@ {% extends "base.html" %} {% load pretty_money %} +{% load render_table from django_tables2 %} {% block content %} - - - - - - - - -{% for object in object_list %} - - - - - - - -{% endfor %} -
IDNomDestinataireMontantCatégorie
{{object.pk}}{{ object.name }}{{ object.destination }}{{ object.amount | pretty_money }}{{ object.template_type }}
-Créer un bouton +Créer un bouton +{% render_table table %} {% endblock %} From 8abc7898957196c5860f3c82d127b60a360e4d98 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 10 Mar 2020 20:17:56 +0100 Subject: [PATCH 02/17] fix parameter name, works better. --- apps/note/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/note/views.py b/apps/note/views.py index a3441ab3..e0105140 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -113,7 +113,7 @@ class TransactionTemplateListView(LoginRequiredMixin, SingleTableView): List TransactionsTemplates """ model = TransactionTemplate - table = ButtonTable + table_class = ButtonTable class TransactionTemplateUpdateView(LoginRequiredMixin, UpdateView): From 3cdb3f6d3820867c2490a45a9ff379015d4abf32 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Mon, 23 Mar 2020 15:28:09 +0100 Subject: [PATCH 03/17] Refactor and comment noteView --- apps/note/urls.py | 2 +- apps/note/views.py | 27 ++++++++++++++++++--------- apps/scripts | 1 + 3 files changed, 20 insertions(+), 10 deletions(-) create mode 160000 apps/scripts diff --git a/apps/note/urls.py b/apps/note/urls.py index fea911f6..59316069 100644 --- a/apps/note/urls.py +++ b/apps/note/urls.py @@ -8,7 +8,7 @@ from .models import Note app_name = 'note' urlpatterns = [ - path('transfer/', views.TransactionCreate.as_view(), name='transfer'), + path('transfer/', views.TransactionCreateView.as_view(), name='transfer'), path('buttons/create/', views.TransactionTemplateCreateView.as_view(), name='template_create'), path('buttons/update//', views.TransactionTemplateUpdateView.as_view(), name='template_update'), path('buttons/', views.TransactionTemplateListView.as_view(), name='template_list'), diff --git a/apps/note/views.py b/apps/note/views.py index e0105140..63d951cb 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -14,12 +14,13 @@ from .forms import TransactionForm, TransactionTemplateForm, ConsoForm from .models import Transaction, TransactionTemplate, Alias, TemplateTransaction from .tables import ButtonTable -class TransactionCreate(LoginRequiredMixin, CreateView): +class TransactionCreateView(LoginRequiredMixin, SingleTableView): """ - Show transfer page + View for the creation of Transaction between two note which are not :models:`transactions.RecurrentTransaction`. + e.g. for donation/transfer between people and clubs or for credit/debit with :models:`note.NoteSpecial` + """ + template_name = "note/transaction_form.html" - TODO: If user have sufficient rights, they can transfer from an other note - """ model = Transaction form_class = TransactionForm @@ -53,13 +54,14 @@ class TransactionCreate(LoginRequiredMixin, CreateView): class NoteAutocomplete(autocomplete.Select2QuerySetView): """ - Auto complete note by aliases + Auto complete note by aliases. Used in every search field for note + ex: :view:`ConsoView`, :view:`TransactionCreateView` """ def get_queryset(self): """ - Quand une personne cherche un alias, une requête est envoyée sur l'API dédiée à l'auto-complétion. - Cette fonction récupère la requête, et renvoie la liste filtrée des aliases. + When someone look for an :models:`note.Alias`, a query is sent to the dedicated API. + This function handles the result and return a filtered list of aliases. """ # Un utilisateur non connecté n'a accès à aucune information if not self.request.user.is_authenticated: @@ -88,6 +90,10 @@ class NoteAutocomplete(autocomplete.Select2QuerySetView): return qs def get_result_label(self, result): + """ + Show the selected alias and the username associated + (aka. ) + """ # Gère l'affichage de l'alias dans la recherche res = result.name note_name = str(result.note) @@ -96,7 +102,9 @@ class NoteAutocomplete(autocomplete.Select2QuerySetView): return res def get_result_value(self, result): - # Le résultat renvoyé doit être l'identifiant de la note, et non de l'alias + """ + The value used for the transactions will be the id of the Note. + """ return str(result.note.pk) @@ -125,7 +133,8 @@ class TransactionTemplateUpdateView(LoginRequiredMixin, UpdateView): class ConsoView(LoginRequiredMixin, CreateView): """ - Consume + 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) """ model = TemplateTransaction template_name = "note/conso_form.html" diff --git a/apps/scripts b/apps/scripts new file mode 160000 index 00000000..b9fdced3 --- /dev/null +++ b/apps/scripts @@ -0,0 +1 @@ +Subproject commit b9fdced3c2ce34168b8f0d6004a20a69ca16e0de From 41a0529d0c168c2d37f3bfb8c2fc0673b472c05a Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Mon, 23 Mar 2020 15:35:24 +0100 Subject: [PATCH 04/17] fixin the merge... --- apps/note/tables.py | 2 +- apps/note/views.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index 050c8981..f50379c4 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -9,7 +9,7 @@ from django_tables2.utils import A from django.utils.translation import gettext_lazy as _ from .models.notes import Alias -from .models.transactions import Transaction +from .models.transactions import Transaction, TransactionTemplate from .templatetags.pretty_money import pretty_money diff --git a/apps/note/views.py b/apps/note/views.py index 4f13f749..d656d7fc 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -13,7 +13,7 @@ from permission.backends import PermissionBackend from .forms import TransactionTemplateForm from .models import Transaction, TransactionTemplate, Alias, RecurrentTransaction, NoteSpecial from .models.transactions import SpecialTransaction -from .tables import HistoryTable +from .tables import HistoryTable, ButtonTable class TransactionCreateView(LoginRequiredMixin, SingleTableView): @@ -24,7 +24,6 @@ class TransactionCreateView(LoginRequiredMixin, SingleTableView): template_name = "note/transaction_form.html" model = Transaction - form_class = TransactionForm # Transaction history table table_class = HistoryTable table_pagination = {"per_page": 50} From 1ce7dc011814ce7df0fc8d14a30e14aa7ff37323 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Mon, 23 Mar 2020 15:53:10 +0100 Subject: [PATCH 05/17] reorganize tabs of nav bar --- templates/base.html | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/templates/base.html b/templates/base.html index fae86443..2f07a6cc 100644 --- a/templates/base.html +++ b/templates/base.html @@ -79,6 +79,9 @@ SPDX-License-Identifier: GPL-3.0-or-later {% trans 'Consumptions' %} {% endif %} + {% if "member.club"|not_empty_model_list %} {% endif %} - {% if "note.transactiontemplate"|not_empty_model_change_list %} - - {% endif %} -