From 205fd5c17a0bcd83e69e1b2934078a7daea6b6a8 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Mon, 9 Mar 2020 19:03:36 +0100 Subject: [PATCH 1/5] initiate submodule for scripts --- .gitmodules | 3 +++ apps/scripts | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 apps/scripts diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..94cf1be6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "apps/scripts"] + path = apps/scripts + url = git@gitlab.crans.org:bde/nk20-scripts.git diff --git a/apps/scripts b/apps/scripts new file mode 160000 index 00000000..123466cf --- /dev/null +++ b/apps/scripts @@ -0,0 +1 @@ +Subproject commit 123466cfa914422422cd372197e64adf65ef05f7 From 94ab2c81f79852cee24e14c1851fe3c00f4eb402 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Tue, 10 Mar 2020 08:07:09 +0100 Subject: [PATCH 2/5] Use TableView for conso page --- apps/note/forms.py | 32 +------------------------------- apps/note/tables.py | 2 +- apps/note/views.py | 21 ++++++++++----------- templates/note/conso_form.html | 2 +- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/apps/note/forms.py b/apps/note/forms.py index 20804412..2e8e4456 100644 --- a/apps/note/forms.py +++ b/apps/note/forms.py @@ -6,7 +6,7 @@ from django import forms from django.utils.translation import gettext_lazy as _ from .models import Alias -from .models import Transaction, TransactionTemplate, TemplateTransaction +from .models import Transaction, TransactionTemplate class AliasForm(forms.ModelForm): @@ -99,33 +99,3 @@ class TransactionForm(forms.ModelForm): }, ), } - - -class ConsoForm(forms.ModelForm): - def save(self, commit=True): - button: TransactionTemplate = TransactionTemplate.objects.filter( - name=self.data['button']).get() - self.instance.destination = button.destination - self.instance.amount = button.amount - self.instance.reason = '{} ({})'.format(button.name, button.category) - self.instance.template = button - self.instance.category = button.category - super().save(commit) - - class Meta: - model = TemplateTransaction - fields = ('source',) - - # Le champ d'utilisateur est remplacé par un champ d'auto-complétion. - # Quand des lettres sont tapées, une requête est envoyée sur l'API d'auto-complétion - # et récupère les aliases de note valides - widgets = { - 'source': - autocomplete.ModelSelect2( - url='note:note_autocomplete', - attrs={ - 'data-placeholder': 'Note ...', - 'data-minimum-input-length': 1, - }, - ), - } diff --git a/apps/note/tables.py b/apps/note/tables.py index e85fcbae..d26ffedc 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -6,7 +6,7 @@ from django.db.models import F from django_tables2.utils import A from .models.notes import Alias -from .models.transactions import Transaction, TransactionTemplate +from .models.transactions import Transaction from .templatetags.pretty_money import pretty_money diff --git a/apps/note/views.py b/apps/note/views.py index 09846057..fb5e98c5 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -7,9 +7,11 @@ from django.db.models import Q 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 .forms import TransactionForm, TransactionTemplateForm +from .models import Transaction, TransactionTemplate, Alias +from .tables import HistoryTable class TransactionCreate(LoginRequiredMixin, CreateView): @@ -121,13 +123,16 @@ class TransactionTemplateUpdateView(LoginRequiredMixin, UpdateView): form_class = TransactionTemplateForm -class ConsoView(LoginRequiredMixin, CreateView): +class ConsoView(LoginRequiredMixin, SingleTableView): """ Consume """ - model = TemplateTransaction + model = Transaction template_name = "note/conso_form.html" - form_class = ConsoForm + + # Transaction history table + table_class = HistoryTable + table_pagination = {"per_page": 10} def get_context_data(self, **kwargs): """ @@ -142,9 +147,3 @@ class ConsoView(LoginRequiredMixin, CreateView): context['no_cache'] = True return context - - def get_success_url(self): - """ - When clicking a button, reload the same page - """ - return reverse('note:consos') diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 10b06589..286b4285 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% load i18n static pretty_money %} +{% load i18n static pretty_money django_tables2 %} {# Remove page title #} {% block contenttitle %}{% endblock %} From f3b44f3170c1223c580a39748f2152b13d01ffe4 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Tue, 10 Mar 2020 08:11:43 +0100 Subject: [PATCH 3/5] Bootstrap for conso page --- templates/base.html | 3 - templates/note/conso_form.html | 174 +++++++++++++++++++++------------ 2 files changed, 114 insertions(+), 63 deletions(-) diff --git a/templates/base.html b/templates/base.html index 887bc970..dbe59c41 100644 --- a/templates/base.html +++ b/templates/base.html @@ -75,9 +75,6 @@ SPDX-License-Identifier: GPL-3.0-or-later - diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 286b4285..2c2066e8 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -6,75 +6,129 @@ {% block contenttitle %}{% endblock %} {% block content %} - {# Regroup buttons under categories #} - {% regroup transaction_templates by category as categories %} - -
- {% csrf_token %} - -
-
- {% if form.non_field_errors %} -

- {% for error in form.non_field_errors %} - {{ error }} - {% endfor %} -

- {% endif %} - {% for field in form %} -
- {{ field.errors }} -
- {{ field.label_tag }} - {% if field.is_readonly %} -
{{ field.contents }}
- {% else %} - {{ field }} - {% endif %} - {% if field.field.help_text %} -
{{ field.field.help_text|safe }}
- {% endif %} +
+
+
+ {# User details column #} +
+
+ +
+ Paquito (aka. PAC) : -230 €
- {% endfor %} -
+
-
-
- {# Tabs for button categories #} -
-
- + + {# Buttons column #} +
+ {# Show last used buttons #} +
+
+

+ Les boutons les plus utilisés s'afficheront ici. +

+
+
+ + {# Regroup buttons under categories #} + {% regroup transaction_templates by template_type as template_types %} + +
+ {# Tabs for button categories #} +
+ +
+ + {# Tabs content #} +
+
+ {% for template_type in template_types %} +
+
+ {% for button in template_type.list %} + + {% endfor %} +
+
+ {% endfor %} +
+
+ + {# Mode switch #} + +
+
+
+ +
+
+

+ Historique des transactions récentes +

+
+ {% render_table table %} +
+{% endblock %} + +{% block extracss %} + {% endblock %} {% block extrajavascript %} From c8f5451ea4e2055a5b028722798ef0ff39a5db28 Mon Sep 17 00:00:00 2001 From: Benjamin Graillot Date: Wed, 11 Mar 2020 13:46:47 +0100 Subject: [PATCH 4/5] Added indexes for Transaction, Alias and Profile --- apps/member/models.py | 1 + apps/note/models/notes.py | 4 ++++ apps/note/models/transactions.py | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/apps/member/models.py b/apps/member/models.py index 50b0bea1..b596357f 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -46,6 +46,7 @@ class Profile(models.Model): class Meta: verbose_name = _('user profile') verbose_name_plural = _('user profile') + indexes = [ models.Index(fields=['user']) ] def get_absolute_url(self): return reverse('user_detail', args=(self.pk,)) diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 74cda3ea..70810ad8 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -209,6 +209,10 @@ class Alias(models.Model): class Meta: verbose_name = _("alias") verbose_name_plural = _("aliases") + indexes = [ + models.Index(fields=['name']), + models.Index(fields=['normalized_name']), + ] def __str__(self): return self.name diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index 3bb7ca76..809e7c44 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -119,6 +119,11 @@ class Transaction(PolymorphicModel): class Meta: verbose_name = _("transaction") verbose_name_plural = _("transactions") + indexes = [ + models.Index(fields=['created_at']), + models.Index(fields=['source']), + models.Index(fields=['destination']), + ] def save(self, *args, **kwargs): """ From b17ff59984844709bd69be53e19d61910d2371cd Mon Sep 17 00:00:00 2001 From: Benjamin Graillot Date: Wed, 11 Mar 2020 13:51:26 +0100 Subject: [PATCH 5/5] Added indexes for Membership --- apps/member/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/member/models.py b/apps/member/models.py index b596357f..5cdc4c77 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -153,6 +153,7 @@ class Membership(models.Model): class Meta: verbose_name = _('membership') verbose_name_plural = _('memberships') + indexes = [ models.Index(fields=['user']) ] # @receiver(post_save, sender=settings.AUTH_USER_MODEL) # def save_user_profile(instance, created, **_kwargs):