From 3cdb3f6d3820867c2490a45a9ff379015d4abf32 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Mon, 23 Mar 2020 15:28:09 +0100 Subject: [PATCH] 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