1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Refactor and comment noteView

This commit is contained in:
Pierre-antoine Comby 2020-03-23 15:28:09 +01:00
parent 8abc789895
commit 3cdb3f6d38
3 changed files with 20 additions and 10 deletions

View File

@ -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/<int:pk>/', views.TransactionTemplateUpdateView.as_view(), name='template_update'),
path('buttons/', views.TransactionTemplateListView.as_view(), name='template_list'),

View File

@ -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
<Alias> (aka. <Username> )
"""
# 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"

1
apps/scripts Submodule

@ -0,0 +1 @@
Subproject commit b9fdced3c2ce34168b8f0d6004a20a69ca16e0de