From a4cb19e5b187116bee5364d3b049ab44a82a1cf7 Mon Sep 17 00:00:00 2001 From: Benjamin Graillot Date: Mon, 23 Mar 2020 09:07:39 +0100 Subject: [PATCH 01/26] [member] Added parent_club field to Club --- apps/member/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/member/models.py b/apps/member/models.py index cdbb9332..41f5bdf3 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -67,6 +67,13 @@ class Club(models.Model): email = models.EmailField( verbose_name=_('email'), ) + parent_club = models.ForeignKey( + 'self', + null=True, + blank=True, + on_delete=models.PROTECT, + verbose_name=_('parent club'), + ) # Memberships membership_fee = models.PositiveIntegerField( From 23db42e448639c6f55ee82e974bb76531a96b59f Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 25 Mar 2020 13:13:01 +0100 Subject: [PATCH 02/26] Give a reason when a transaction is invalidated --- apps/note/models/transactions.py | 12 ++++++++++++ apps/note/tables.py | 29 +++++++++++++++++++++-------- static/js/base.js | 30 ++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index 0e40edf6..93d1071a 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -115,11 +115,19 @@ class Transaction(PolymorphicModel): verbose_name=_('reason'), max_length=255, ) + valid = models.BooleanField( verbose_name=_('valid'), default=True, ) + invalidity_reason = models.CharField( + verbose_name=_('invalidity reason'), + max_length=255, + default=None, + null=True, + ) + class Meta: verbose_name = _("transaction") verbose_name_plural = _("transactions") @@ -152,6 +160,10 @@ class Transaction(PolymorphicModel): self.source.balance -= to_transfer self.destination.balance += to_transfer + # When a transaction is declared valid, we ensure that the invalidity reason is null, if it was + # previously invalid + self.invalidity_reason = None + # We save first the transaction, in case of the user has no right to transfer money super().save(*args, **kwargs) diff --git a/apps/note/tables.py b/apps/note/tables.py index 20054d2c..ea7bdaa7 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -5,6 +5,7 @@ import html import django_tables2 as tables from django.db.models import F +from django.utils.html import format_html from django_tables2.utils import A from django.utils.translation import gettext_lazy as _ @@ -20,19 +21,26 @@ class HistoryTable(tables.Table): 'table table-condensed table-striped table-hover' } model = Transaction - exclude = ("id", "polymorphic_ctype", ) + exclude = ("id", "polymorphic_ctype", "invalidity_reason") template_name = 'django_tables2/bootstrap4.html' - sequence = ('...', 'type', 'total', 'valid', ) + sequence = ('...', 'type', 'total', 'valid',) orderable = False type = tables.Column() total = tables.Column() # will use Transaction.total() !! - valid = tables.Column(attrs={"td": {"id": lambda record: "validate_" + str(record.id), - "class": lambda record: str(record.valid).lower() + ' validate', - "onclick": lambda record: 'de_validate(' + str(record.id) + ', ' - + str(record.valid).lower() + ')'}}) + valid = tables.Column( + attrs={ + "td": { + "id": lambda record: "validate_" + str(record.id), + "class": lambda record: str(record.valid).lower() + ' validate', + "onclick": lambda record: 'in_validate(' + str(record.id) + ', ' + str(record.valid).lower() + ')', + "onmouseover": lambda record: 'hover_validation_btn(' + str(record.id) + ', true)', + "onmouseout": lambda record: 'hover_validation_btn(' + str(record.id) + ', false)', + } + } + ) def order_total(self, queryset, is_descending): # needed for rendering @@ -53,8 +61,13 @@ class HistoryTable(tables.Table): def render_reason(self, value): return html.unescape(value) - def render_valid(self, value): - return "✔" if value else "✖" + def render_valid(self, value, record): + val = "✔" if value else "✖" + val += "
" + return format_html(val) # function delete_button(id) provided in template file diff --git a/static/js/base.js b/static/js/base.js index f7085850..4a78e811 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -260,8 +260,29 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes }); } +function hover_validation_btn(id, show) { + let reason_obj = $("#invalidity_reason_" + id); + console.log(reason_obj.val()); + + if (show) { + reason_obj.show(); + reason_obj.focus(); + } + else + reason_obj.hide(); +} + // When a validate button is clicked, we switch the validation status -function de_validate(id, validated) { +function in_validate(id, validated) { + + let invalidity_reason; + let reason_obj = $("#invalidity_reason_" + id); + + if (validated) + invalidity_reason = reason_obj.val(); + else + invalidity_reason = null; + $("#validate_" + id).html("⟳ ..."); // Perform a PATCH request to the API in order to update the transaction @@ -274,12 +295,13 @@ function de_validate(id, validated) { "X-CSRFTOKEN": CSRF_TOKEN }, data: { - "resourcetype": "RecurrentTransaction", - valid: !validated + resourcetype: "RecurrentTransaction", + valid: !validated, + invalidity_reason: invalidity_reason, }, success: function () { // Refresh jQuery objects - $(".validate").click(de_validate); + $(".validate").click(in_validate); refreshBalance(); // error if this method doesn't exist. Please define it. From e5ab391236ecaebd2a656bf6e81240d072f1484b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 25 Mar 2020 14:50:21 +0100 Subject: [PATCH 03/26] Better user interface --- apps/note/tables.py | 16 ++- locale/de/LC_MESSAGES/django.po | 243 ++++++++++++++++++++------------ locale/fr/LC_MESSAGES/django.po | 243 ++++++++++++++++++++------------ static/js/base.js | 12 -- 4 files changed, 309 insertions(+), 205 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index ea7bdaa7..c02fdf32 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -35,9 +35,13 @@ class HistoryTable(tables.Table): "td": { "id": lambda record: "validate_" + str(record.id), "class": lambda record: str(record.valid).lower() + ' validate', + "data-toggle": "tooltip", + "title": lambda record: _("Click to invalidate") if record.valid else _("Click to validate"), "onclick": lambda record: 'in_validate(' + str(record.id) + ', ' + str(record.valid).lower() + ')', - "onmouseover": lambda record: 'hover_validation_btn(' + str(record.id) + ', true)', - "onmouseout": lambda record: 'hover_validation_btn(' + str(record.id) + ', false)', + "onmouseover": lambda record: '$("#invalidity_reason_' + + str(record.id) + '").show();$("#invalidity_reason_' + + str(record.id) + '").focus();', + "onmouseout": lambda record: '$("#invalidity_reason_' + str(record.id) + '").hide()', } } ) @@ -63,10 +67,12 @@ class HistoryTable(tables.Table): def render_valid(self, value, record): val = "✔" if value else "✖" - val += "
" + + " placeholder='" + html.escape(_("invalidity reason").capitalize()) + "'" \ + + " style='position: absolute; width: 15em; margin-left: -15.5em; margin-top: -2em; display: none;'>" return format_html(val) diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index e61efb2a..519cf289 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-16 11:53+0100\n" +"POT-Creation-Date: 2020-03-25 14:46+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -23,9 +23,9 @@ msgid "activity" msgstr "" #: apps/activity/models.py:19 apps/activity/models.py:44 -#: apps/member/models.py:61 apps/member/models.py:112 +#: apps/member/models.py:63 apps/member/models.py:114 #: apps/note/models/notes.py:188 apps/note/models/transactions.py:24 -#: apps/note/models/transactions.py:44 apps/note/models/transactions.py:202 +#: apps/note/models/transactions.py:44 apps/note/models/transactions.py:210 #: templates/member/profile_detail.html:15 msgid "name" msgstr "" @@ -47,11 +47,12 @@ msgid "activity types" msgstr "" #: apps/activity/models.py:48 apps/note/models/transactions.py:69 +#: apps/permission/models.py:91 msgid "description" msgstr "" #: apps/activity/models.py:54 apps/note/models/notes.py:164 -#: apps/note/models/transactions.py:62 apps/note/models/transactions.py:115 +#: apps/note/models/transactions.py:62 msgid "type" msgstr "" @@ -119,11 +120,11 @@ msgstr "" msgid "create" msgstr "" -#: apps/logs/models.py:61 +#: apps/logs/models.py:61 apps/note/tables.py:126 msgid "edit" msgstr "" -#: apps/logs/models.py:62 +#: apps/logs/models.py:62 apps/note/tables.py:130 msgid "delete" msgstr "" @@ -143,114 +144,114 @@ msgstr "" msgid "member" msgstr "" -#: apps/member/models.py:23 +#: apps/member/models.py:25 msgid "phone number" msgstr "" -#: apps/member/models.py:29 templates/member/profile_detail.html:28 +#: apps/member/models.py:31 templates/member/profile_detail.html:28 msgid "section" msgstr "" -#: apps/member/models.py:30 +#: apps/member/models.py:32 msgid "e.g. \"1A0\", \"9A♥\", \"SAPHIRE\"" msgstr "" -#: apps/member/models.py:36 templates/member/profile_detail.html:31 +#: apps/member/models.py:38 templates/member/profile_detail.html:31 msgid "address" msgstr "" -#: apps/member/models.py:42 +#: apps/member/models.py:44 msgid "paid" msgstr "" -#: apps/member/models.py:47 apps/member/models.py:48 +#: apps/member/models.py:49 apps/member/models.py:50 msgid "user profile" msgstr "" -#: apps/member/models.py:66 +#: apps/member/models.py:68 msgid "email" msgstr "" -#: apps/member/models.py:71 +#: apps/member/models.py:73 msgid "membership fee" msgstr "" -#: apps/member/models.py:75 +#: apps/member/models.py:77 msgid "membership duration" msgstr "" -#: apps/member/models.py:76 +#: apps/member/models.py:78 msgid "The longest time a membership can last (NULL = infinite)." msgstr "" -#: apps/member/models.py:81 +#: apps/member/models.py:83 msgid "membership start" msgstr "" -#: apps/member/models.py:82 +#: apps/member/models.py:84 msgid "How long after January 1st the members can renew their membership." msgstr "" -#: apps/member/models.py:87 +#: apps/member/models.py:89 msgid "membership end" msgstr "" -#: apps/member/models.py:88 +#: apps/member/models.py:90 msgid "" "How long the membership can last after January 1st of the next year after " "members can renew their membership." msgstr "" -#: apps/member/models.py:94 apps/note/models/notes.py:139 +#: apps/member/models.py:96 apps/note/models/notes.py:139 msgid "club" msgstr "" -#: apps/member/models.py:95 +#: apps/member/models.py:97 msgid "clubs" msgstr "" -#: apps/member/models.py:118 +#: apps/member/models.py:120 apps/permission/models.py:276 msgid "role" msgstr "" -#: apps/member/models.py:119 +#: apps/member/models.py:121 msgid "roles" msgstr "" -#: apps/member/models.py:143 +#: apps/member/models.py:145 msgid "membership starts on" msgstr "" -#: apps/member/models.py:146 +#: apps/member/models.py:148 msgid "membership ends on" msgstr "" -#: apps/member/models.py:150 +#: apps/member/models.py:152 msgid "fee" msgstr "" -#: apps/member/models.py:154 +#: apps/member/models.py:162 msgid "membership" msgstr "" -#: apps/member/models.py:155 +#: apps/member/models.py:163 msgid "memberships" msgstr "" -#: apps/member/views.py:69 templates/member/profile_detail.html:46 +#: apps/member/views.py:80 templates/member/profile_detail.html:46 msgid "Update Profile" msgstr "" -#: apps/member/views.py:82 +#: apps/member/views.py:93 msgid "An alias with a similar name already exists." msgstr "" -#: apps/member/views.py:132 +#: apps/member/views.py:146 #, python-format msgid "Account #%(id)s: %(username)s" msgstr "" -#: apps/member/views.py:202 +#: apps/member/views.py:216 msgid "Alias successfully deleted" msgstr "" @@ -415,84 +416,114 @@ msgstr "" msgid "quantity" msgstr "" -#: apps/note/models/transactions.py:117 templates/note/transaction_form.html:15 -msgid "Gift" -msgstr "" - -#: apps/note/models/transactions.py:118 templates/base.html:90 -#: templates/note/transaction_form.html:19 -#: templates/note/transaction_form.html:126 -msgid "Transfer" -msgstr "" - -#: apps/note/models/transactions.py:119 -msgid "Template" -msgstr "" - -#: apps/note/models/transactions.py:120 templates/note/transaction_form.html:23 -msgid "Credit" -msgstr "" - -#: apps/note/models/transactions.py:121 templates/note/transaction_form.html:27 -msgid "Debit" -msgstr "" - -#: apps/note/models/transactions.py:122 apps/note/models/transactions.py:230 -msgid "membership transaction" -msgstr "" - -#: apps/note/models/transactions.py:129 +#: apps/note/models/transactions.py:115 msgid "reason" msgstr "" -#: apps/note/models/transactions.py:133 +#: apps/note/models/transactions.py:120 msgid "valid" msgstr "" -#: apps/note/models/transactions.py:138 +#: apps/note/models/transactions.py:125 apps/note/tables.py:74 +msgid "invalidity reason" +msgstr "" + +#: apps/note/models/transactions.py:132 msgid "transaction" msgstr "" -#: apps/note/models/transactions.py:139 +#: apps/note/models/transactions.py:133 msgid "transactions" msgstr "" -#: apps/note/models/transactions.py:207 +#: apps/note/models/transactions.py:180 templates/base.html:83 +#: templates/note/transaction_form.html:19 +#: templates/note/transaction_form.html:145 +msgid "Transfer" +msgstr "" + +#: apps/note/models/transactions.py:200 +msgid "Template" +msgstr "" + +#: apps/note/models/transactions.py:215 msgid "first_name" msgstr "" -#: apps/note/models/transactions.py:212 +#: apps/note/models/transactions.py:220 msgid "bank" msgstr "" -#: apps/note/models/transactions.py:231 +#: apps/note/models/transactions.py:226 templates/note/transaction_form.html:24 +msgid "Credit" +msgstr "" + +#: apps/note/models/transactions.py:226 templates/note/transaction_form.html:28 +msgid "Debit" +msgstr "" + +#: apps/note/models/transactions.py:242 apps/note/models/transactions.py:247 +msgid "membership transaction" +msgstr "" + +#: apps/note/models/transactions.py:243 msgid "membership transactions" msgstr "" -#: apps/note/views.py:31 +#: apps/note/tables.py:39 +msgid "Click to invalidate" +msgstr "" + +#: apps/note/tables.py:39 +msgid "Click to validate" +msgstr "" + +#: apps/note/tables.py:72 +msgid "No reason specified" +msgstr "" + +#: apps/note/views.py:42 msgid "Transfer money" msgstr "" -#: apps/note/views.py:132 templates/base.html:78 +#: apps/note/views.py:158 templates/base.html:79 msgid "Consumptions" msgstr "" -#: note_kfet/settings/__init__.py:61 +#: apps/permission/models.py:70 apps/permission/models.py:263 +#, python-brace-format +msgid "Can {type} {model}.{field} in {query}" +msgstr "" + +#: apps/permission/models.py:72 apps/permission/models.py:265 +#, python-brace-format +msgid "Can {type} {model} in {query}" +msgstr "" + +#: apps/permission/models.py:85 +msgid "rank" +msgstr "" + +#: apps/permission/models.py:148 +msgid "Specifying field applies only to view and change permission types." +msgstr "" + +#: note_kfet/settings/__init__.py:63 msgid "" "The Central Authentication Service grants you access to most of our websites " "by authenticating only once, so you don't need to type your credentials " "again unless your session expires or you logout." msgstr "" -#: note_kfet/settings/base.py:156 +#: note_kfet/settings/base.py:151 msgid "German" msgstr "" -#: note_kfet/settings/base.py:157 +#: note_kfet/settings/base.py:152 msgid "English" msgstr "" -#: note_kfet/settings/base.py:158 +#: note_kfet/settings/base.py:153 msgid "French" msgstr "" @@ -500,18 +531,14 @@ msgstr "" msgid "The ENS Paris-Saclay BDE note." msgstr "" -#: templates/base.html:81 +#: templates/base.html:87 msgid "Clubs" msgstr "" -#: templates/base.html:84 +#: templates/base.html:92 msgid "Activities" msgstr "" -#: templates/base.html:87 -msgid "Buttons" -msgstr "" - #: templates/cas_server/base.html:7 msgid "Central Authentication Service" msgstr "" @@ -653,7 +680,7 @@ msgstr "" msgid "Sign up" msgstr "" -#: templates/note/conso_form.html:28 templates/note/transaction_form.html:38 +#: templates/note/conso_form.html:28 templates/note/transaction_form.html:50 msgid "Select emitters" msgstr "" @@ -681,49 +708,53 @@ msgstr "" msgid "Double consumptions" msgstr "" -#: templates/note/conso_form.html:141 +#: templates/note/conso_form.html:141 templates/note/transaction_form.html:152 msgid "Recent transactions history" msgstr "" -#: templates/note/transaction_form.html:55 +#: templates/note/transaction_form.html:15 +msgid "Gift" +msgstr "" + +#: templates/note/transaction_form.html:68 msgid "External payment" msgstr "" -#: templates/note/transaction_form.html:63 +#: templates/note/transaction_form.html:76 msgid "Transfer type" msgstr "" -#: templates/note/transaction_form.html:73 +#: templates/note/transaction_form.html:86 msgid "Name" msgstr "" -#: templates/note/transaction_form.html:79 +#: templates/note/transaction_form.html:92 msgid "First name" msgstr "" -#: templates/note/transaction_form.html:85 +#: templates/note/transaction_form.html:98 msgid "Bank" msgstr "" -#: templates/note/transaction_form.html:97 -#: templates/note/transaction_form.html:179 -#: templates/note/transaction_form.html:186 +#: templates/note/transaction_form.html:111 +#: templates/note/transaction_form.html:169 +#: templates/note/transaction_form.html:176 msgid "Select receivers" msgstr "" -#: templates/note/transaction_form.html:114 +#: templates/note/transaction_form.html:128 msgid "Amount" msgstr "" -#: templates/note/transaction_form.html:119 +#: templates/note/transaction_form.html:138 msgid "Reason" msgstr "" -#: templates/note/transaction_form.html:193 +#: templates/note/transaction_form.html:183 msgid "Credit note" msgstr "" -#: templates/note/transaction_form.html:200 +#: templates/note/transaction_form.html:190 msgid "Debit note" msgstr "" @@ -731,6 +762,22 @@ msgstr "" msgid "Buttons list" msgstr "" +#: templates/note/transactiontemplate_list.html:9 +msgid "search button" +msgstr "" + +#: templates/note/transactiontemplate_list.html:20 +msgid "buttons listing " +msgstr "" + +#: templates/note/transactiontemplate_list.html:71 +msgid "button successfully deleted " +msgstr "" + +#: templates/note/transactiontemplate_list.html:75 +msgid "Unable to delete button " +msgstr "" + #: templates/registration/logged_out.html:8 msgid "Thanks for spending some quality time with the Web site today." msgstr "" @@ -740,7 +787,7 @@ msgid "Log in again" msgstr "" #: templates/registration/login.html:7 templates/registration/login.html:8 -#: templates/registration/login.html:26 +#: templates/registration/login.html:28 #: templates/registration/password_reset_complete.html:10 msgid "Log in" msgstr "" @@ -752,7 +799,15 @@ msgid "" "page. Would you like to login to a different account?" msgstr "" -#: templates/registration/login.html:27 +#: templates/registration/login.html:22 +msgid "You can also register via the central authentification server " +msgstr "" + +#: templates/registration/login.html:23 +msgid "using this link " +msgstr "" + +#: templates/registration/login.html:29 msgid "Forgotten your password or username?" msgstr "" diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 5e6e9470..d07c4f21 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-16 11:53+0100\n" +"POT-Creation-Date: 2020-03-25 14:46+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,9 +18,9 @@ msgid "activity" msgstr "activité" #: apps/activity/models.py:19 apps/activity/models.py:44 -#: apps/member/models.py:61 apps/member/models.py:112 +#: apps/member/models.py:63 apps/member/models.py:114 #: apps/note/models/notes.py:188 apps/note/models/transactions.py:24 -#: apps/note/models/transactions.py:44 apps/note/models/transactions.py:202 +#: apps/note/models/transactions.py:44 apps/note/models/transactions.py:210 #: templates/member/profile_detail.html:15 msgid "name" msgstr "nom" @@ -42,11 +42,12 @@ msgid "activity types" msgstr "types d'activité" #: apps/activity/models.py:48 apps/note/models/transactions.py:69 +#: apps/permission/models.py:91 msgid "description" msgstr "description" #: apps/activity/models.py:54 apps/note/models/notes.py:164 -#: apps/note/models/transactions.py:62 apps/note/models/transactions.py:115 +#: apps/note/models/transactions.py:62 msgid "type" msgstr "type" @@ -114,11 +115,11 @@ msgstr "Nouvelles données" msgid "create" msgstr "Créer" -#: apps/logs/models.py:61 +#: apps/logs/models.py:61 apps/note/tables.py:126 msgid "edit" msgstr "Modifier" -#: apps/logs/models.py:62 +#: apps/logs/models.py:62 apps/note/tables.py:130 msgid "delete" msgstr "Supprimer" @@ -138,61 +139,61 @@ msgstr "Les logs ne peuvent pas être détruits." msgid "member" msgstr "adhérent" -#: apps/member/models.py:23 +#: apps/member/models.py:25 msgid "phone number" msgstr "numéro de téléphone" -#: apps/member/models.py:29 templates/member/profile_detail.html:28 +#: apps/member/models.py:31 templates/member/profile_detail.html:28 msgid "section" msgstr "section" -#: apps/member/models.py:30 +#: apps/member/models.py:32 msgid "e.g. \"1A0\", \"9A♥\", \"SAPHIRE\"" msgstr "e.g. \"1A0\", \"9A♥\", \"SAPHIRE\"" -#: apps/member/models.py:36 templates/member/profile_detail.html:31 +#: apps/member/models.py:38 templates/member/profile_detail.html:31 msgid "address" msgstr "adresse" -#: apps/member/models.py:42 +#: apps/member/models.py:44 msgid "paid" msgstr "payé" -#: apps/member/models.py:47 apps/member/models.py:48 +#: apps/member/models.py:49 apps/member/models.py:50 msgid "user profile" msgstr "profil utilisateur" -#: apps/member/models.py:66 +#: apps/member/models.py:68 msgid "email" msgstr "courriel" -#: apps/member/models.py:71 +#: apps/member/models.py:73 msgid "membership fee" msgstr "cotisation pour adhérer" -#: apps/member/models.py:75 +#: apps/member/models.py:77 msgid "membership duration" msgstr "durée de l'adhésion" -#: apps/member/models.py:76 +#: apps/member/models.py:78 msgid "The longest time a membership can last (NULL = infinite)." msgstr "La durée maximale d'une adhésion (NULL = infinie)." -#: apps/member/models.py:81 +#: apps/member/models.py:83 msgid "membership start" msgstr "début de l'adhésion" -#: apps/member/models.py:82 +#: apps/member/models.py:84 msgid "How long after January 1st the members can renew their membership." msgstr "" "Combien de temps après le 1er Janvier les adhérents peuvent renouveler leur " "adhésion." -#: apps/member/models.py:87 +#: apps/member/models.py:89 msgid "membership end" msgstr "fin de l'adhésion" -#: apps/member/models.py:88 +#: apps/member/models.py:90 msgid "" "How long the membership can last after January 1st of the next year after " "members can renew their membership." @@ -200,56 +201,56 @@ msgstr "" "Combien de temps l'adhésion peut durer après le 1er Janvier de l'année " "suivante avant que les adhérents peuvent renouveler leur adhésion." -#: apps/member/models.py:94 apps/note/models/notes.py:139 +#: apps/member/models.py:96 apps/note/models/notes.py:139 msgid "club" msgstr "club" -#: apps/member/models.py:95 +#: apps/member/models.py:97 msgid "clubs" msgstr "clubs" -#: apps/member/models.py:118 +#: apps/member/models.py:120 apps/permission/models.py:276 msgid "role" msgstr "rôle" -#: apps/member/models.py:119 +#: apps/member/models.py:121 msgid "roles" msgstr "rôles" -#: apps/member/models.py:143 +#: apps/member/models.py:145 msgid "membership starts on" msgstr "l'adhésion commence le" -#: apps/member/models.py:146 +#: apps/member/models.py:148 msgid "membership ends on" msgstr "l'adhésion finie le" -#: apps/member/models.py:150 +#: apps/member/models.py:152 msgid "fee" msgstr "cotisation" -#: apps/member/models.py:154 +#: apps/member/models.py:162 msgid "membership" msgstr "adhésion" -#: apps/member/models.py:155 +#: apps/member/models.py:163 msgid "memberships" msgstr "adhésions" -#: apps/member/views.py:69 templates/member/profile_detail.html:46 +#: apps/member/views.py:80 templates/member/profile_detail.html:46 msgid "Update Profile" msgstr "Modifier le profil" -#: apps/member/views.py:82 +#: apps/member/views.py:93 msgid "An alias with a similar name already exists." msgstr "Un alias avec un nom similaire existe déjà." -#: apps/member/views.py:132 +#: apps/member/views.py:146 #, python-format msgid "Account #%(id)s: %(username)s" msgstr "Compte n°%(id)s : %(username)s" -#: apps/member/views.py:202 +#: apps/member/views.py:216 msgid "Alias successfully deleted" msgstr "L'alias a bien été supprimé" @@ -415,84 +416,114 @@ msgstr "modèles de transaction" msgid "quantity" msgstr "quantité" -#: apps/note/models/transactions.py:117 templates/note/transaction_form.html:15 -msgid "Gift" -msgstr "Don" - -#: apps/note/models/transactions.py:118 templates/base.html:90 -#: templates/note/transaction_form.html:19 -#: templates/note/transaction_form.html:126 -msgid "Transfer" -msgstr "Virement" - -#: apps/note/models/transactions.py:119 -msgid "Template" -msgstr "Bouton" - -#: apps/note/models/transactions.py:120 templates/note/transaction_form.html:23 -msgid "Credit" -msgstr "Crédit" - -#: apps/note/models/transactions.py:121 templates/note/transaction_form.html:27 -msgid "Debit" -msgstr "Retrait" - -#: apps/note/models/transactions.py:122 apps/note/models/transactions.py:230 -msgid "membership transaction" -msgstr "transaction d'adhésion" - -#: apps/note/models/transactions.py:129 +#: apps/note/models/transactions.py:115 msgid "reason" msgstr "raison" -#: apps/note/models/transactions.py:133 +#: apps/note/models/transactions.py:120 msgid "valid" msgstr "valide" -#: apps/note/models/transactions.py:138 +#: apps/note/models/transactions.py:125 apps/note/tables.py:74 +msgid "invalidity reason" +msgstr "Motif d'invalidité" + +#: apps/note/models/transactions.py:132 msgid "transaction" msgstr "transaction" -#: apps/note/models/transactions.py:139 +#: apps/note/models/transactions.py:133 msgid "transactions" msgstr "transactions" -#: apps/note/models/transactions.py:207 +#: apps/note/models/transactions.py:180 templates/base.html:83 +#: templates/note/transaction_form.html:19 +#: templates/note/transaction_form.html:145 +msgid "Transfer" +msgstr "Virement" + +#: apps/note/models/transactions.py:200 +msgid "Template" +msgstr "Bouton" + +#: apps/note/models/transactions.py:215 msgid "first_name" msgstr "Prénom" -#: apps/note/models/transactions.py:212 +#: apps/note/models/transactions.py:220 msgid "bank" msgstr "Banque" -#: apps/note/models/transactions.py:231 +#: apps/note/models/transactions.py:226 templates/note/transaction_form.html:24 +msgid "Credit" +msgstr "Crédit" + +#: apps/note/models/transactions.py:226 templates/note/transaction_form.html:28 +msgid "Debit" +msgstr "Retrait" + +#: apps/note/models/transactions.py:242 apps/note/models/transactions.py:247 +msgid "membership transaction" +msgstr "transaction d'adhésion" + +#: apps/note/models/transactions.py:243 msgid "membership transactions" msgstr "transactions d'adhésion" -#: apps/note/views.py:31 +#: apps/note/tables.py:39 +msgid "Click to invalidate" +msgstr "Cliquez pour dévalider" + +#: apps/note/tables.py:39 +msgid "Click to validate" +msgstr "Cliquez pour valider" + +#: apps/note/tables.py:72 +msgid "No reason specified" +msgstr "Pas de motif spécifié" + +#: apps/note/views.py:42 msgid "Transfer money" msgstr "Transferts d'argent" -#: apps/note/views.py:132 templates/base.html:78 +#: apps/note/views.py:158 templates/base.html:79 msgid "Consumptions" msgstr "Consommations" -#: note_kfet/settings/__init__.py:61 +#: apps/permission/models.py:70 apps/permission/models.py:263 +#, python-brace-format +msgid "Can {type} {model}.{field} in {query}" +msgstr "" + +#: apps/permission/models.py:72 apps/permission/models.py:265 +#, python-brace-format +msgid "Can {type} {model} in {query}" +msgstr "" + +#: apps/permission/models.py:85 +msgid "rank" +msgstr "rang" + +#: apps/permission/models.py:148 +msgid "Specifying field applies only to view and change permission types." +msgstr "" + +#: note_kfet/settings/__init__.py:63 msgid "" "The Central Authentication Service grants you access to most of our websites " "by authenticating only once, so you don't need to type your credentials " "again unless your session expires or you logout." msgstr "" -#: note_kfet/settings/base.py:156 +#: note_kfet/settings/base.py:151 msgid "German" msgstr "" -#: note_kfet/settings/base.py:157 +#: note_kfet/settings/base.py:152 msgid "English" msgstr "" -#: note_kfet/settings/base.py:158 +#: note_kfet/settings/base.py:153 msgid "French" msgstr "" @@ -500,18 +531,14 @@ msgstr "" msgid "The ENS Paris-Saclay BDE note." msgstr "La note du BDE de l'ENS Paris-Saclay." -#: templates/base.html:81 +#: templates/base.html:87 msgid "Clubs" msgstr "Clubs" -#: templates/base.html:84 +#: templates/base.html:92 msgid "Activities" msgstr "Activités" -#: templates/base.html:87 -msgid "Buttons" -msgstr "Boutons" - #: templates/cas_server/base.html:7 msgid "Central Authentication Service" msgstr "" @@ -655,7 +682,7 @@ msgstr "Sauvegarder les changements" msgid "Sign up" msgstr "Inscription" -#: templates/note/conso_form.html:28 templates/note/transaction_form.html:38 +#: templates/note/conso_form.html:28 templates/note/transaction_form.html:50 msgid "Select emitters" msgstr "Sélection des émetteurs" @@ -683,49 +710,53 @@ msgstr "Consos simples" msgid "Double consumptions" msgstr "Consos doubles" -#: templates/note/conso_form.html:141 +#: templates/note/conso_form.html:141 templates/note/transaction_form.html:152 msgid "Recent transactions history" msgstr "Historique des transactions récentes" -#: templates/note/transaction_form.html:55 +#: templates/note/transaction_form.html:15 +msgid "Gift" +msgstr "Don" + +#: templates/note/transaction_form.html:68 msgid "External payment" msgstr "Paiement extérieur" -#: templates/note/transaction_form.html:63 +#: templates/note/transaction_form.html:76 msgid "Transfer type" msgstr "Type de transfert" -#: templates/note/transaction_form.html:73 +#: templates/note/transaction_form.html:86 msgid "Name" msgstr "Nom" -#: templates/note/transaction_form.html:79 +#: templates/note/transaction_form.html:92 msgid "First name" msgstr "Prénom" -#: templates/note/transaction_form.html:85 +#: templates/note/transaction_form.html:98 msgid "Bank" msgstr "Banque" -#: templates/note/transaction_form.html:97 -#: templates/note/transaction_form.html:179 -#: templates/note/transaction_form.html:186 +#: templates/note/transaction_form.html:111 +#: templates/note/transaction_form.html:169 +#: templates/note/transaction_form.html:176 msgid "Select receivers" msgstr "Sélection des destinataires" -#: templates/note/transaction_form.html:114 +#: templates/note/transaction_form.html:128 msgid "Amount" msgstr "Montant" -#: templates/note/transaction_form.html:119 +#: templates/note/transaction_form.html:138 msgid "Reason" msgstr "Raison" -#: templates/note/transaction_form.html:193 +#: templates/note/transaction_form.html:183 msgid "Credit note" msgstr "Note à créditer" -#: templates/note/transaction_form.html:200 +#: templates/note/transaction_form.html:190 msgid "Debit note" msgstr "Note à débiter" @@ -733,6 +764,22 @@ msgstr "Note à débiter" msgid "Buttons list" msgstr "Liste des boutons" +#: templates/note/transactiontemplate_list.html:9 +msgid "search button" +msgstr "Chercher un bouton" + +#: templates/note/transactiontemplate_list.html:20 +msgid "buttons listing " +msgstr "Liste des boutons" + +#: templates/note/transactiontemplate_list.html:71 +msgid "button successfully deleted " +msgstr "Le bouton a bien été supprimé" + +#: templates/note/transactiontemplate_list.html:75 +msgid "Unable to delete button " +msgstr "Impossible de supprimer le bouton " + #: templates/registration/logged_out.html:8 msgid "Thanks for spending some quality time with the Web site today." msgstr "" @@ -742,7 +789,7 @@ msgid "Log in again" msgstr "" #: templates/registration/login.html:7 templates/registration/login.html:8 -#: templates/registration/login.html:26 +#: templates/registration/login.html:28 #: templates/registration/password_reset_complete.html:10 msgid "Log in" msgstr "" @@ -754,7 +801,15 @@ msgid "" "page. Would you like to login to a different account?" msgstr "" -#: templates/registration/login.html:27 +#: templates/registration/login.html:22 +msgid "You can also register via the central authentification server " +msgstr "" + +#: templates/registration/login.html:23 +msgid "using this link " +msgstr "" + +#: templates/registration/login.html:29 msgid "Forgotten your password or username?" msgstr "" diff --git a/static/js/base.js b/static/js/base.js index 4a78e811..81f9f323 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -260,18 +260,6 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes }); } -function hover_validation_btn(id, show) { - let reason_obj = $("#invalidity_reason_" + id); - console.log(reason_obj.val()); - - if (show) { - reason_obj.show(); - reason_obj.focus(); - } - else - reason_obj.hide(); -} - // When a validate button is clicked, we switch the validation status function in_validate(id, validated) { From bc3fdbe7a711bc607bc1288bb2fb372f7927ea98 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 25 Mar 2020 14:54:26 +0100 Subject: [PATCH 04/26] Add docstring --- apps/note/tables.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/note/tables.py b/apps/note/tables.py index c02fdf32..328f620a 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -66,6 +66,9 @@ class HistoryTable(tables.Table): return html.unescape(value) def render_valid(self, value, record): + """ + When the validation status is hovered, an input field is displayed to let the user specify an invalidity reason + """ val = "✔" if value else "✖" val += " Date: Wed, 25 Mar 2020 15:27:38 +0100 Subject: [PATCH 05/26] When a transaction can't becreated because the user don't have the permission to take too much money, then we create an invalid transaction --- apps/permission/fixtures/initial.json | 4 +- static/js/consos.js | 24 ++++++++-- static/js/transfer.js | 66 +++++++++++++++++++++------ 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/apps/permission/fixtures/initial.json b/apps/permission/fixtures/initial.json index 4c7de16d..43d39a36 100644 --- a/apps/permission/fixtures/initial.json +++ b/apps/permission/fixtures/initial.json @@ -327,7 +327,7 @@ "note", "transaction" ], - "query": "[\"AND\", {\"source\": [\"user\", \"note\"]}, {\"amount__lte\": [\"user\", \"note\", \"balance\"]}]", + "query": "[\"AND\", {\"source\": [\"user\", \"note\"]}, [\"OR\", {\"amount__lte\": [\"user\", \"note\", \"balance\"]}, {\"valid\": false}]]", "type": "add", "mask": 1, "field": "", @@ -387,7 +387,7 @@ "note", "recurrenttransaction" ], - "query": "[\"AND\", {\"destination\": [\"club\", \"note\"]}, {\"amount__lte\": {\"F\": [\"ADD\", [\"F\", \"source__balance\"], 5000]}}]", + "query": "[\"AND\", {\"destination\": [\"club\", \"note\"]}, [\"OR\", {\"amount__lte\": {\"F\": [\"ADD\", [\"F\", \"source__balance\"], 5000]}}, {\"valid\": false}]]", "type": "add", "mask": 2, "field": "", diff --git a/static/js/consos.js b/static/js/consos.js index 896f996c..b201e748 100644 --- a/static/js/consos.js +++ b/static/js/consos.js @@ -199,8 +199,26 @@ function consume(source, dest, quantity, amount, reason, type, category, templat "category": category, "template": template }, reset).fail(function (e) { - reset(); - - addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger"); + $.post("/api/note/transaction/transaction/", + { + "csrfmiddlewaretoken": CSRF_TOKEN, + "quantity": quantity, + "amount": amount, + "reason": reason, + "valid": false, + "invalidity_reason": "Solde insuffisant", + "polymorphic_ctype": type, + "resourcetype": "RecurrentTransaction", + "source": source, + "destination": dest, + "category": category, + "template": template + }).done(function() { + reset(); + addMsg("La transaction n'a pas pu être validée pour cause de solde insuffisant.", "danger"); + }).fail(function () { + reset(); + addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger"); + }); }); } diff --git a/static/js/transfer.js b/static/js/transfer.js index c615f932..cfa4f1f9 100644 --- a/static/js/transfer.js +++ b/static/js/transfer.js @@ -73,18 +73,38 @@ $("#transfer").click(function() { "resourcetype": "Transaction", "source": user_id, "destination": dest.id - }, function () { + }).done(function () { addMsg("Le transfert de " + pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note " + " vers la note " + dest.name + " a été fait avec succès !", "success"); reset(); - }).fail(function (err) { - addMsg("Le transfert de " - + pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note " - + " vers la note " + dest.name + " a échoué : " + err.responseText, "danger"); + }).fail(function () { + $.post("/api/note/transaction/transaction/", + { + "csrfmiddlewaretoken": CSRF_TOKEN, + "quantity": dest.quantity, + "amount": 100 * $("#amount").val(), + "reason": $("#reason").val(), + "valid": false, + "invalidity_reason": "Solde insuffisant", + "polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE, + "resourcetype": "Transaction", + "source": user_id, + "destination": dest.id + }).done(function () { + addMsg("Le transfert de " + + pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note " + + " vers la note " + dest.name + " a échoué : Solde insuffisant", "danger"); - reset(); + reset(); + }).fail(function (err) { + addMsg("Le transfert de " + + pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note " + + " vers la note " + dest.name + " a échoué : " + err.responseText, "danger"); + + reset(); + }); }); }); } @@ -102,18 +122,38 @@ $("#transfer").click(function() { "resourcetype": "Transaction", "source": source.id, "destination": dest.id - }, function () { + }).done(function () { addMsg("Le transfert de " + pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name + " vers la note " + dest.name + " a été fait avec succès !", "success"); reset(); }).fail(function (err) { - addMsg("Le transfert de " - + pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name - + " vers la note " + dest.name + " a échoué : " + err.responseText, "danger"); + $.post("/api/note/transaction/transaction/", + { + "csrfmiddlewaretoken": CSRF_TOKEN, + "quantity": source.quantity * dest.quantity, + "amount": 100 * $("#amount").val(), + "reason": $("#reason").val(), + "valid": false, + "invalidity_reason": "Solde insuffisant", + "polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE, + "resourcetype": "Transaction", + "source": source.id, + "destination": dest.id + }).done(function () { + addMsg("Le transfert de " + + pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name + + " vers la note " + dest.name + " a échoué : Solde insuffisant", "danger"); - reset(); + reset(); + }).fail(function (err) { + addMsg("Le transfert de " + + pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name + + " vers la note " + dest.name + " a échoué : " + err.responseText, "danger"); + + reset(); + }); }); }); }); @@ -150,11 +190,11 @@ $("#transfer").click(function() { "last_name": $("#last_name").val(), "first_name": $("#first_name").val(), "bank": $("#bank").val() - }, function () { + }).done(function () { addMsg("Le crédit/retrait a bien été effectué !", "success"); reset(); }).fail(function (err) { - addMsg("Le crédit/transfert a échoué : " + err.responseText, "danger"); + addMsg("Le crédit/retrait a échoué : " + err.responseText, "danger"); reset(); }); } From 26d70c4ef97ae838ef09ceec0277f8d439c25057 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Wed, 25 Mar 2020 17:25:44 +0100 Subject: [PATCH 06/26] page title and edit buttons --- apps/member/views.py | 4 ---- templates/member/club_info.html | 11 +++++++++++ templates/member/profile_info.html | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index 7d3ed748..b518ad24 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -143,10 +143,6 @@ class UserDetailView(LoginRequiredMixin, DetailView): club_list = \ Membership.objects.all().filter(user=user).only("club") context['club_list'] = ClubTable(club_list) - context['title'] = _("Account #%(id)s: %(username)s") % { - 'id': user.pk, - 'username': user.username, - } return context diff --git a/templates/member/club_info.html b/templates/member/club_info.html index a88527fc..d720b64f 100644 --- a/templates/member/club_info.html +++ b/templates/member/club_info.html @@ -1,5 +1,8 @@ {% load i18n static pretty_money %}
+
+

Club {{ club.name }}

+
+
diff --git a/templates/member/profile_info.html b/templates/member/profile_info.html index 30383866..9ff20385 100644 --- a/templates/member/profile_info.html +++ b/templates/member/profile_info.html @@ -1,6 +1,9 @@ {% load i18n static pretty_money %}
+
+

{% trans "Account #" %} {{ object.pk }}

+
From a41e51e23ad66e45e2d88fc1290e9abdd54dcb55 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Wed, 25 Mar 2020 17:42:54 +0100 Subject: [PATCH 07/26] add member get side information --- apps/member/views.py | 4 ++-- templates/member/add_members.html | 12 ++++++++---- templates/member/club_info.html | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index b518ad24..14322dcf 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -391,12 +391,12 @@ class ClubAddMemberView(LoginRequiredMixin, CreateView): return super().get_queryset().filter(PermissionBackend.filter_queryset(self.request.user, Membership, "view") | PermissionBackend.filter_queryset(self.request.user, Membership, "change")) - def get_context_data(self, **kwargs): + club = Club.objects.get(pk=self.kwargs["pk"]) context = super().get_context_data(**kwargs) context['formset'] = MemberFormSet() context['helper'] = FormSetHelper() - + context['club'] = club context['no_cache'] = True return context diff --git a/templates/member/add_members.html b/templates/member/add_members.html index 8032af30..8b57e7d4 100644 --- a/templates/member/add_members.html +++ b/templates/member/add_members.html @@ -1,7 +1,11 @@ -{% extends "base.html" %} +{% extends "member/noteowner_detail.html" %} {% load crispy_forms_tags %} {% load static %} -{% block content %} + +{% block profile_info %} +{% include "member/club_info.html" %} +{% endblock %} +{% block profile_content %}
{% csrf_token %} @@ -10,9 +14,9 @@
+{% endblock %} - - +{% block extrajavascript %} +{% endblock%} From a00e43bc265cf5cd0977309cbcfda7fc8fa09815 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 26 Mar 2020 21:04:32 +0100 Subject: [PATCH 20/26] Fix alias deletion --- apps/note/tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index 3d8be58e..6e998fbb 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -77,7 +77,7 @@ class AliasTable(tables.Table): show_header = False name = tables.Column(attrs={'td': {'class': 'text-center'}}) - delete = tables.TemplateColumn(template_code=DELETE_TEMPLATE, + delete_btn = tables.TemplateColumn(template_code=DELETE_TEMPLATE, extra_context={"delete_trans": _('delete')}, attrs={'td': {'class': 'col-sm-1'}}) From 61b6aceb36c1cc7ccf88ec68d3fbd54ec0fab5f1 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 26 Mar 2020 23:04:14 +0100 Subject: [PATCH 21/26] crappy name -> crappy behavior --- apps/note/tables.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index 6e998fbb..4ef9b594 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -77,7 +77,7 @@ class AliasTable(tables.Table): show_header = False name = tables.Column(attrs={'td': {'class': 'text-center'}}) - delete_btn = tables.TemplateColumn(template_code=DELETE_TEMPLATE, + delete_col = tables.TemplateColumn(template_code=DELETE_TEMPLATE, extra_context={"delete_trans": _('delete')}, attrs={'td': {'class': 'col-sm-1'}}) @@ -104,7 +104,7 @@ class ButtonTable(tables.Table): text=_('edit'), accessor='pk') - delete = tables.TemplateColumn(template_code=DELETE_TEMPLATE, + delete_col = tables.TemplateColumn(template_code=DELETE_TEMPLATE, extra_context={"delete_trans": _('delete')}, attrs={'td': {'class': 'col-sm-1'}}) From 49dd88dbb7d53aa8af9c6dc8bc90fdf6fbbf2895 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 26 Mar 2020 23:04:51 +0100 Subject: [PATCH 22/26] add errMsg function --- static/js/base.js | 10 +++++++++- static/js/consos.js | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/static/js/base.js b/static/js/base.js index f7085850..d06c2fbe 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -28,7 +28,15 @@ function addMsg(msg, alert_type) { + msg + "
\n"; msgDiv.html(html); } - +/** + * add Muliple error message from err_obj + * @param err_obj {error_code:erro_message} + */ +function errMsg(errs_obj){ + for (const err_msg of Object.values(errs_obj)) { + addMsg(err_msg,'danger'); + } +} /** * Reload the balance of the user on the right top corner */ diff --git a/static/js/consos.js b/static/js/consos.js index 896f996c..27173365 100644 --- a/static/js/consos.js +++ b/static/js/consos.js @@ -200,7 +200,6 @@ function consume(source, dest, quantity, amount, reason, type, category, templat "template": template }, reset).fail(function (e) { reset(); - - addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger"); + errMsg(e.responseJSON); }); } From f7a66920e0d1bcbba112a8a8f4db71118f9d3699 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 26 Mar 2020 23:05:08 +0100 Subject: [PATCH 23/26] move common script to alias.js --- static/js/alias.js | 37 +++++++++++++++++++++++++++++ templates/member/club_alias.html | 4 ++++ templates/member/profile_alias.html | 32 +------------------------ 3 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 static/js/alias.js diff --git a/static/js/alias.js b/static/js/alias.js new file mode 100644 index 00000000..267410da --- /dev/null +++ b/static/js/alias.js @@ -0,0 +1,37 @@ + + $("#alias_input").on('keypress',function(e) { + if(e.which == 13) { + $("#alias_submit").click(); + } + }); + + function create_alias(note_id){ + $.post("/api/note/alias/", + { + "csrfmiddlewaretoken": CSRF_TOKEN, + "name": $("#alias_input").val(), + "note": note_id + } + ).done(function(){ + $("#alias_table").load(location.href+ " #alias_table"); + addMsg("Alias ajouté","success"); + }) + .fail(function(xhr, textStatus, error){ + errMsg(xhr.responseJSON); + }); +} + // on click of button "delete" , call the API + function delete_button(button_id){ + $.ajax({ + url:"/api/note/alias/"+button_id+"/", + method:"DELETE", + headers: {"X-CSRFTOKEN": CSRF_TOKEN} + }) + .done(function(){ + addMsg('Alias supprimé','success'); + $("#alias_table").load(location.href + " #alias_table"); + }) + .fail(function(xhr,textStatus, error){ + errMsg(xhr.responseJSON); + }); + } diff --git a/templates/member/club_alias.html b/templates/member/club_alias.html index 394b1c95..4b6f2882 100644 --- a/templates/member/club_alias.html +++ b/templates/member/club_alias.html @@ -4,3 +4,7 @@ {% block profile_content %} {% include "member/alias_update.html" %} {% endblock %} + +{% block extrajavascript %} + +{% endblock%} diff --git a/templates/member/profile_alias.html b/templates/member/profile_alias.html index 9d2c34a3..eb6e499a 100644 --- a/templates/member/profile_alias.html +++ b/templates/member/profile_alias.html @@ -6,35 +6,5 @@ {% endblock %} {% block extrajavascript %} - + {% endblock%} From c50e17c55519507d8bf4ffa1c70e7d0a511b84aa Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 26 Mar 2020 23:05:37 +0100 Subject: [PATCH 24/26] error handling up to client --- apps/note/api/views.py | 17 +++++++++++++++-- apps/note/models/notes.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/note/api/views.py b/apps/note/api/views.py index 3a29b522..40fc4f4e 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -2,10 +2,14 @@ # SPDX-License-Identifier: GPL-3.0-or-later from django.db.models import Q +from django.core.exceptions import ValidationError from django_filters.rest_framework import DjangoFilterBackend from rest_framework.filters import OrderingFilter, SearchFilter -from api.viewsets import ReadProtectedModelViewSet, ReadOnlyProtectedModelViewSet from rest_framework import viewsets +from rest_framework.response import Response +from rest_framework import status + +from api.viewsets import ReadProtectedModelViewSet, ReadOnlyProtectedModelViewSet from .serializers import NotePolymorphicSerializer, AliasSerializer, TemplateCategorySerializer, \ TransactionTemplateSerializer, TransactionPolymorphicSerializer @@ -59,7 +63,16 @@ class AliasViewSet(viewsets.ModelViewSet): #alias owner cannot be change once establish setattr(serializer_class.Meta, 'read_only_fields', ('note',)) return serializer_class - + + def destroy(self, request, *args, **kwargs): + instance = self.get_object() + try: + self.perform_destroy(instance) + except ValidationError as e: + print(e) + return Response({e.code:e.message},status.HTTP_400_BAD_REQUEST) + return Response(status=status.HTTP_204_NO_CONTENT) + def get_queryset(self): """ Parse query and apply filters. diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 2fa63906..43faabfe 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -249,5 +249,5 @@ class Alias(models.Model): def delete(self, using=None, keep_parents=False): if self.name == str(self.note): raise ValidationError(_("You can't delete your main alias."), - code="cant_delete_main_alias") + code="main_alias") return super().delete(using, keep_parents) From a3a8fd601ce5a2426db6d5408da63534235b2112 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Fri, 27 Mar 2020 13:26:47 +0100 Subject: [PATCH 25/26] revert to ReadProtectedViewset --- apps/note/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/note/api/views.py b/apps/note/api/views.py index 40fc4f4e..e70eb49e 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -45,7 +45,7 @@ class NotePolymorphicViewSet(ReadOnlyProtectedModelViewSet): return queryset.distinct() -class AliasViewSet(viewsets.ModelViewSet): +class AliasViewSet(ReadProtectedModelViewSet): """ REST API View set. The djangorestframework plugin will get all `Alias` objects, serialize it to JSON with the given serializer, From ee3d441a56f7650584e33360e9e360d35914c9ff Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Fri, 27 Mar 2020 14:04:30 +0100 Subject: [PATCH 26/26] add parent club link --- templates/member/club_info.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/member/club_info.html b/templates/member/club_info.html index b63c1e85..539d9867 100644 --- a/templates/member/club_info.html +++ b/templates/member/club_info.html @@ -13,6 +13,9 @@
{% trans 'name'|capfirst %}
{{ club.name}}
+
{% trans 'Club Parent'|capfirst %}
+
{{ club.parent_club.name}}
+
{% trans 'membership start'|capfirst %}
{{ club.membership_start }}