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/24] 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/24] 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 28e7707bc5b86923823a18802a2169dae3cb86a1 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 22 Mar 2020 14:57:49 +0100 Subject: [PATCH 03/24] add submodule --- apps/scripts | 1 + 1 file changed, 1 insertion(+) create mode 160000 apps/scripts diff --git a/apps/scripts b/apps/scripts new file mode 160000 index 00000000..be8aa44e --- /dev/null +++ b/apps/scripts @@ -0,0 +1 @@ +Subproject commit be8aa44eb616fd75b8a1e4c12588616dff8703a9 From c200ae8c3cd7ce749ffa77148ff59f21ddb9ce06 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 22 Mar 2020 22:01:33 +0100 Subject: [PATCH 04/24] ask for cas only if available. --- templates/registration/login.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/templates/registration/login.html b/templates/registration/login.html index 5a4322d1..8e50fce1 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -16,11 +16,12 @@ SPDX-License-Identifier: GPL-2.0-or-later {% endblocktrans %}

{% endif %} - -
- Vous pouvez aussi vous connecter via l'authentification centralisée en suivant ce lien. + {%url 'cas_login' as cas_url %} + {% if cas_url %} +
+ Vous pouvez aussi vous connecter via l'authentification centralisée en suivant ce lien.
- + {%endif%}
{% csrf_token %} {{ form | crispy }} From b9fac82d895fd4dca7294b0983b1c2532276bcc4 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 22 Mar 2020 14:54:05 +0100 Subject: [PATCH 05/24] Fixtures are more natural --- apps/note/fixtures/initial.json | 473 ++++++++++++++------------ apps/permission/fixtures/initial.json | 167 +++++++-- 2 files changed, 389 insertions(+), 251 deletions(-) diff --git a/apps/note/fixtures/initial.json b/apps/note/fixtures/initial.json index 3654fa2f..63285e34 100644 --- a/apps/note/fixtures/initial.json +++ b/apps/note/fixtures/initial.json @@ -1,220 +1,259 @@ [ - { - "model": "note.note", - "pk": 1, - "fields": { - "polymorphic_ctype": 40, - "balance": 0, - "is_active": true, - "display_image": "", - "created_at": "2020-02-20T20:02:48.778Z" - } - }, - { - "model": "note.note", - "pk": 2, - "fields": { - "polymorphic_ctype": 40, - "balance": 0, - "is_active": true, - "display_image": "", - "created_at": "2020-02-20T20:06:39.546Z" - } - }, - { - "model": "note.note", - "pk": 3, - "fields": { - "polymorphic_ctype": 40, - "balance": 0, - "is_active": true, - "display_image": "", - "created_at": "2020-02-20T20:06:43.049Z" - } - }, - { - "model": "note.note", - "pk": 4, - "fields": { - "polymorphic_ctype": 40, - "balance": 0, - "is_active": true, - "display_image": "", - "created_at": "2020-02-20T20:06:50.996Z" - } - }, - { - "model": "note.note", - "pk": 5, - "fields": { - "polymorphic_ctype": 39, - "balance": 0, - "is_active": true, - "display_image": "", - "created_at": "2020-02-20T20:09:38.615Z" - } - }, - { - "model": "note.note", - "pk": 6, - "fields": { - "polymorphic_ctype": 39, - "balance": 0, - "is_active": true, - "display_image": "", - "created_at": "2020-02-20T20:16:14.753Z" - } - }, - { - "model": "note.notespecial", - "pk": 1, - "fields": { - "special_type": "Esp\u00e8ces" - } - }, - { - "model": "note.notespecial", - "pk": 2, - "fields": { - "special_type": "Carte bancaire" - } - }, - { - "model": "note.notespecial", - "pk": 3, - "fields": { - "special_type": "Ch\u00e8que" - } - }, - { - "model": "note.notespecial", - "pk": 4, - "fields": { - "special_type": "Virement bancaire" - } - }, - { - "model": "note.noteclub", - "pk": 5, - "fields": { - "club": 1 - } - }, - { - "model": "note.noteclub", - "pk": 6, - "fields": { - "club": 2 - } - }, - { - "model": "note.alias", - "pk": 1, - "fields": { - "name": "Esp\u00e8ces", - "normalized_name": "especes", - "note": 1 - } - }, - { - "model": "note.alias", - "pk": 2, - "fields": { - "name": "Carte bancaire", - "normalized_name": "cartebancaire", - "note": 2 - } - }, - { - "model": "note.alias", - "pk": 3, - "fields": { - "name": "Ch\u00e8que", - "normalized_name": "cheque", - "note": 3 - } - }, - { - "model": "note.alias", - "pk": 4, - "fields": { - "name": "Virement bancaire", - "normalized_name": "virementbancaire", - "note": 4 - } - }, - { - "model": "note.alias", - "pk": 5, - "fields": { - "name": "BDE", - "normalized_name": "bde", - "note": 5 - } - }, - { - "model": "note.alias", - "pk": 6, - "fields": { - "name": "Kfet", - "normalized_name": "kfet", - "note": 6 - } - }, - { - "model": "note.templatecategory", - "pk": 1, - "fields": { - "name": "Soft" - } - }, - { - "model": "note.templatecategory", - "pk": 2, - "fields": { - "name": "Pulls" - } - }, - { - "model": "note.templatecategory", - "pk": 3, - "fields": { - "name": "Gala" - } - }, - { - "model": "note.templatecategory", - "pk": 4, - "fields": { - "name": "Clubs" - } - }, - { - "model": "note.templatecategory", - "pk": 5, - "fields": { - "name": "Bouffe" - } - }, - { - "model": "note.templatecategory", - "pk": 6, - "fields": { - "name": "BDA" - } - }, - { - "model": "note.templatecategory", - "pk": 7, - "fields": { - "name": "Autre" - } - }, - { - "model": "note.templatecategory", - "pk": 8, - "fields": { - "name": "Alcool" - } + { + "model": "note.note", + "pk": 1, + "fields": { + "polymorphic_ctype": [ + "note", + "notespecial" + ], + "balance": 0, + "last_negative": null, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:02:48.778Z" } + }, + { + "model": "note.note", + "pk": 2, + "fields": { + "polymorphic_ctype": [ + "note", + "notespecial" + ], + "balance": 0, + "last_negative": null, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:06:39.546Z" + } + }, + { + "model": "note.note", + "pk": 3, + "fields": { + "polymorphic_ctype": [ + "note", + "notespecial" + ], + "balance": 0, + "last_negative": null, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:06:43.049Z" + } + }, + { + "model": "note.note", + "pk": 4, + "fields": { + "polymorphic_ctype": [ + "note", + "notespecial" + ], + "balance": 0, + "last_negative": null, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:06:50.996Z" + } + }, + { + "model": "note.note", + "pk": 5, + "fields": { + "polymorphic_ctype": [ + "note", + "noteclub" + ], + "balance": 0, + "last_negative": null, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:09:38.615Z" + } + }, + { + "model": "note.note", + "pk": 6, + "fields": { + "polymorphic_ctype": [ + "note", + "noteclub" + ], + "balance": 0, + "last_negative": null, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:16:14.753Z" + } + }, + { + "model": "note.note", + "pk": 7, + "fields": { + "polymorphic_ctype": [ + "note", + "noteuser" + ], + "balance": 0, + "last_negative": null, + "is_active": true, + "display_image": "pic/default.png", + "created_at": "2020-03-22T13:01:35.680Z" + } + }, + { + "model": "note.noteclub", + "pk": 5, + "fields": { + "club": 1 + } + }, + { + "model": "note.noteclub", + "pk": 6, + "fields": { + "club": 2 + } + }, + { + "model": "note.notespecial", + "pk": 1, + "fields": { + "special_type": "Esp\u00e8ces" + } + }, + { + "model": "note.notespecial", + "pk": 2, + "fields": { + "special_type": "Carte bancaire" + } + }, + { + "model": "note.notespecial", + "pk": 3, + "fields": { + "special_type": "Ch\u00e8que" + } + }, + { + "model": "note.notespecial", + "pk": 4, + "fields": { + "special_type": "Virement bancaire" + } + }, + { + "model": "note.alias", + "pk": 1, + "fields": { + "name": "Esp\u00e8ces", + "normalized_name": "especes", + "note": 1 + } + }, + { + "model": "note.alias", + "pk": 2, + "fields": { + "name": "Carte bancaire", + "normalized_name": "cartebancaire", + "note": 2 + } + }, + { + "model": "note.alias", + "pk": 3, + "fields": { + "name": "Ch\u00e8que", + "normalized_name": "cheque", + "note": 3 + } + }, + { + "model": "note.alias", + "pk": 4, + "fields": { + "name": "Virement bancaire", + "normalized_name": "virementbancaire", + "note": 4 + } + }, + { + "model": "note.alias", + "pk": 5, + "fields": { + "name": "BDE", + "normalized_name": "bde", + "note": 5 + } + }, + { + "model": "note.alias", + "pk": 6, + "fields": { + "name": "Kfet", + "normalized_name": "kfet", + "note": 6 + } + }, + { + "model": "note.templatecategory", + "pk": 1, + "fields": { + "name": "Soft" + } + }, + { + "model": "note.templatecategory", + "pk": 2, + "fields": { + "name": "Pulls" + } + }, + { + "model": "note.templatecategory", + "pk": 3, + "fields": { + "name": "Gala" + } + }, + { + "model": "note.templatecategory", + "pk": 4, + "fields": { + "name": "Clubs" + } + }, + { + "model": "note.templatecategory", + "pk": 5, + "fields": { + "name": "Bouffe" + } + }, + { + "model": "note.templatecategory", + "pk": 6, + "fields": { + "name": "BDA" + } + }, + { + "model": "note.templatecategory", + "pk": 7, + "fields": { + "name": "Autre" + } + }, + { + "model": "note.templatecategory", + "pk": 8, + "fields": { + "name": "Alcool" + } + } ] diff --git a/apps/permission/fixtures/initial.json b/apps/permission/fixtures/initial.json index 69900372..4c7de16d 100644 --- a/apps/permission/fixtures/initial.json +++ b/apps/permission/fixtures/initial.json @@ -83,7 +83,10 @@ "model": "permission.permission", "pk": 1, "fields": { - "model": 21, + "model": [ + "auth", + "user" + ], "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "view", "mask": 1, @@ -95,7 +98,10 @@ "model": "permission.permission", "pk": 2, "fields": { - "model": 31, + "model": [ + "member", + "profile" + ], "query": "{\"user\": [\"user\"]}", "type": "view", "mask": 1, @@ -107,7 +113,10 @@ "model": "permission.permission", "pk": 3, "fields": { - "model": 34, + "model": [ + "note", + "noteuser" + ], "query": "{\"pk\": [\"user\", \"note\", \"pk\"]}", "type": "view", "mask": 1, @@ -119,7 +128,10 @@ "model": "permission.permission", "pk": 4, "fields": { - "model": 25, + "model": [ + "authtoken", + "token" + ], "query": "{\"user\": [\"user\"]}", "type": "view", "mask": 1, @@ -131,7 +143,10 @@ "model": "permission.permission", "pk": 5, "fields": { - "model": 36, + "model": [ + "note", + "transaction" + ], "query": "[\"OR\", {\"source\": [\"user\", \"note\"]}, {\"destination\": [\"user\", \"note\"]}]", "type": "view", "mask": 1, @@ -143,7 +158,10 @@ "model": "permission.permission", "pk": 6, "fields": { - "model": 33, + "model": [ + "note", + "alias" + ], "query": "[\"OR\", {\"note__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__membership__club__name\": \"Kfet\"}], [\"all\"]]}, {\"note__in\": [\"NoteClub\", \"objects\", [\"all\"]]}]", "type": "view", "mask": 1, @@ -155,7 +173,10 @@ "model": "permission.permission", "pk": 7, "fields": { - "model": 21, + "model": [ + "auth", + "user" + ], "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -167,7 +188,10 @@ "model": "permission.permission", "pk": 8, "fields": { - "model": 21, + "model": [ + "auth", + "user" + ], "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -179,7 +203,10 @@ "model": "permission.permission", "pk": 9, "fields": { - "model": 21, + "model": [ + "auth", + "user" + ], "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -191,7 +218,10 @@ "model": "permission.permission", "pk": 10, "fields": { - "model": 21, + "model": [ + "auth", + "user" + ], "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -203,7 +233,10 @@ "model": "permission.permission", "pk": 11, "fields": { - "model": 21, + "model": [ + "auth", + "user" + ], "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -215,7 +248,10 @@ "model": "permission.permission", "pk": 12, "fields": { - "model": 25, + "model": [ + "authtoken", + "token" + ], "query": "{\"user\": [\"user\"]}", "type": "delete", "mask": 1, @@ -227,7 +263,10 @@ "model": "permission.permission", "pk": 13, "fields": { - "model": 25, + "model": [ + "authtoken", + "token" + ], "query": "{\"user\": [\"user\"]}", "type": "add", "mask": 1, @@ -239,7 +278,10 @@ "model": "permission.permission", "pk": 14, "fields": { - "model": 33, + "model": [ + "note", + "alias" + ], "query": "{\"note\": [\"user\", \"note\"]}", "type": "delete", "mask": 1, @@ -251,7 +293,10 @@ "model": "permission.permission", "pk": 15, "fields": { - "model": 33, + "model": [ + "note", + "alias" + ], "query": "{\"note\": [\"user\", \"note\"]}", "type": "add", "mask": 1, @@ -263,7 +308,10 @@ "model": "permission.permission", "pk": 16, "fields": { - "model": 34, + "model": [ + "note", + "noteuser" + ], "query": "{\"pk\": [\"user\", \"note\", \"pk\"]}", "type": "change", "mask": 1, @@ -275,7 +323,10 @@ "model": "permission.permission", "pk": 17, "fields": { - "model": 36, + "model": [ + "note", + "transaction" + ], "query": "[\"AND\", {\"source\": [\"user\", \"note\"]}, {\"amount__lte\": [\"user\", \"note\", \"balance\"]}]", "type": "add", "mask": 1, @@ -287,7 +338,10 @@ "model": "permission.permission", "pk": 18, "fields": { - "model": 34, + "model": [ + "note", + "note" + ], "query": "{}", "type": "change", "mask": 1, @@ -299,7 +353,10 @@ "model": "permission.permission", "pk": 19, "fields": { - "model": 34, + "model": [ + "note", + "note" + ], "query": "[\"OR\", {\"pk\": [\"club\", \"note\", \"pk\"]}, {\"pk__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__membership__club\": [\"club\"]}], [\"all\"]]}]", "type": "view", "mask": 2, @@ -311,7 +368,10 @@ "model": "permission.permission", "pk": 20, "fields": { - "model": 36, + "model": [ + "note", + "transaction" + ], "query": "[\"AND\", [\"OR\", {\"source\": [\"club\", \"note\"]}, {\"destination\": [\"club\", \"note\"]}], {\"amount__lte\": {\"F\": [\"ADD\", [\"F\", \"source__balance\"], 5000]}}]", "type": "add", "mask": 2, @@ -323,7 +383,10 @@ "model": "permission.permission", "pk": 21, "fields": { - "model": 42, + "model": [ + "note", + "recurrenttransaction" + ], "query": "[\"AND\", {\"destination\": [\"club\", \"note\"]}, {\"amount__lte\": {\"F\": [\"ADD\", [\"F\", \"source__balance\"], 5000]}}]", "type": "add", "mask": 2, @@ -335,7 +398,10 @@ "model": "permission.permission", "pk": 22, "fields": { - "model": 29, + "model": [ + "member", + "club" + ], "query": "{\"pk\": [\"club\", \"pk\"]}", "type": "view", "mask": 1, @@ -347,7 +413,10 @@ "model": "permission.permission", "pk": 23, "fields": { - "model": 36, + "model": [ + "note", + "transaction" + ], "query": "{}", "type": "change", "mask": 1, @@ -359,7 +428,10 @@ "model": "permission.permission", "pk": 24, "fields": { - "model": 36, + "model": [ + "note", + "transaction" + ], "query": "{}", "type": "view", "mask": 2, @@ -371,7 +443,10 @@ "model": "permission.permission", "pk": 25, "fields": { - "model": 40, + "model": [ + "note", + "notespecial" + ], "query": "{}", "type": "view", "mask": 2, @@ -383,7 +458,10 @@ "model": "permission.permission", "pk": 26, "fields": { - "model": 43, + "model": [ + "note", + "specialtransaction" + ], "query": "{}", "type": "add", "mask": 2, @@ -395,7 +473,10 @@ "model": "permission.permission", "pk": 27, "fields": { - "model": 35, + "model": [ + "note", + "templatecategory" + ], "query": "{}", "type": "view", "mask": 2, @@ -407,7 +488,10 @@ "model": "permission.permission", "pk": 28, "fields": { - "model": 35, + "model": [ + "note", + "templatecategory" + ], "query": "{}", "type": "change", "mask": 3, @@ -419,7 +503,10 @@ "model": "permission.permission", "pk": 29, "fields": { - "model": 35, + "model": [ + "note", + "templatecategory" + ], "query": "{}", "type": "add", "mask": 3, @@ -431,7 +518,10 @@ "model": "permission.permission", "pk": 30, "fields": { - "model": 37, + "model": [ + "note", + "transactiontemplate" + ], "query": "{}", "type": "view", "mask": 2, @@ -443,7 +533,10 @@ "model": "permission.permission", "pk": 31, "fields": { - "model": 37, + "model": [ + "note", + "transactiontemplate" + ], "query": "{}", "type": "add", "mask": 3, @@ -455,7 +548,10 @@ "model": "permission.permission", "pk": 32, "fields": { - "model": 37, + "model": [ + "note", + "transactiontemplate" + ], "query": "{}", "type": "change", "mask": 3, @@ -467,7 +563,10 @@ "model": "permission.permission", "pk": 33, "fields": { - "model": 36, + "model": [ + "note", + "transaction" + ], "query": "{}", "type": "add", "mask": 2, @@ -551,4 +650,4 @@ ] } } -] \ No newline at end of file +] From c3bea59f2fe7ebc5bad2ead706e450a774d48289 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 22 Mar 2020 22:09:45 +0100 Subject: [PATCH 06/24] update script projects --- apps/scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/scripts b/apps/scripts index be8aa44e..b9fdced3 160000 --- a/apps/scripts +++ b/apps/scripts @@ -1 +1 @@ -Subproject commit be8aa44eb616fd75b8a1e4c12588616dff8703a9 +Subproject commit b9fdced3c2ce34168b8f0d6004a20a69ca16e0de From c295e5cbc7ca8d06894528131bbb1f76f31ed4b2 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 22 Mar 2020 22:22:37 +0100 Subject: [PATCH 07/24] fix indentation --- templates/registration/login.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/templates/registration/login.html b/templates/registration/login.html index 8e50fce1..175d37e0 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -16,10 +16,11 @@ SPDX-License-Identifier: GPL-2.0-or-later {% endblocktrans %}

{% endif %} - {%url 'cas_login' as cas_url %} - {% if cas_url %} -
- Vous pouvez aussi vous connecter via l'authentification centralisée en suivant ce lien. + {%url 'cas_login' as cas_url %} + {% if cas_url %} +
+ {% trans "You can also register via the central authentification server " %} + {% trans "using this link "%}
{%endif%} {% csrf_token %} From da63bd75f12ac03c4b663b4d91ba01f618fb5d6a Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 22 Mar 2020 22:22:51 +0100 Subject: [PATCH 08/24] this is not the place for cas config --- note_kfet/settings/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/note_kfet/settings/base.py b/note_kfet/settings/base.py index 64016b27..216199de 100644 --- a/note_kfet/settings/base.py +++ b/note_kfet/settings/base.py @@ -127,7 +127,6 @@ PASSWORD_HASHERS = [ AUTHENTICATION_BACKENDS = ( 'permission.backends.PermissionBackend', # Custom role-based permission system - 'cas.backends.CASBackend', # For CAS connections ) REST_FRAMEWORK = { From 610a4f0b3ff3d4d834255c7cb913718d99cb9183 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 22 Mar 2020 22:35:07 +0100 Subject: [PATCH 09/24] show Note info always on left --- templates/note/transaction_form.html | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/templates/note/transaction_form.html b/templates/note/transaction_form.html index 347db056..d2cd85e9 100644 --- a/templates/note/transaction_form.html +++ b/templates/note/transaction_form.html @@ -33,6 +33,16 @@ SPDX-License-Identifier: GPL-2.0-or-later
+ +
+
+ +
+ +
+
+
{% endblock %} + +{% block extrajavascript %} + +{% endblock %} From d4b8d35206f9429d501cc4c4e89704284397c5cd Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 24 Mar 2020 20:16:56 +0100 Subject: [PATCH 15/24] check permission with PermissionBackend. taking connection permission mask into account. --- apps/permission/backends.py | 1 + apps/permission/permissions.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/permission/backends.py b/apps/permission/backends.py index e61b0719..62b0c09f 100644 --- a/apps/permission/backends.py +++ b/apps/permission/backends.py @@ -89,6 +89,7 @@ class PermissionBackend(ModelBackend): query = query | perm.query return query + @staticmethod def has_perm(self, user_obj, perm, obj=None): if user_obj is None or isinstance(user_obj, AnonymousUser): return False diff --git a/apps/permission/permissions.py b/apps/permission/permissions.py index d9816a63..9fb36f35 100644 --- a/apps/permission/permissions.py +++ b/apps/permission/permissions.py @@ -41,8 +41,8 @@ class StrongDjangoObjectPermissions(DjangoObjectPermissions): user = request.user perms = self.get_required_object_permissions(request.method, model_cls) - - if not user.has_perms(perms, obj): + # if not user.has_perms(perms, obj): + if not all(PermissionBackend.has_perm(user, perm, obj) for perm in perms): # If the user does not have permissions we need to determine if # they have read permissions to see 403, or not, and simply see # a 404 response. From 8ab142c122229b3c264dc22934807c241a51e22a Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 24 Mar 2020 20:25:08 +0100 Subject: [PATCH 16/24] no need to be static after all --- apps/permission/backends.py | 1 - apps/permission/permissions.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/permission/backends.py b/apps/permission/backends.py index 62b0c09f..e61b0719 100644 --- a/apps/permission/backends.py +++ b/apps/permission/backends.py @@ -89,7 +89,6 @@ class PermissionBackend(ModelBackend): query = query | perm.query return query - @staticmethod def has_perm(self, user_obj, perm, obj=None): if user_obj is None or isinstance(user_obj, AnonymousUser): return False diff --git a/apps/permission/permissions.py b/apps/permission/permissions.py index 9fb36f35..7959065f 100644 --- a/apps/permission/permissions.py +++ b/apps/permission/permissions.py @@ -42,7 +42,7 @@ class StrongDjangoObjectPermissions(DjangoObjectPermissions): perms = self.get_required_object_permissions(request.method, model_cls) # if not user.has_perms(perms, obj): - if not all(PermissionBackend.has_perm(user, perm, obj) for perm in perms): + if not all(PermissionBackend().has_perm(user, perm, obj) for perm in perms): # If the user does not have permissions we need to determine if # they have read permissions to see 403, or not, and simply see # a 404 response. From ba04a6555f429a307f6c908e4a641416110f344b Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 24 Mar 2020 22:12:44 +0100 Subject: [PATCH 17/24] dynamically delete buttons --- apps/note/api/views.py | 3 ++- apps/note/tables.py | 5 ++++ templates/note/transactiontemplate_list.html | 28 +++++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/apps/note/api/views.py b/apps/note/api/views.py index 977441f7..d35c3797 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -5,6 +5,7 @@ from django.db.models import Q 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 .serializers import NotePolymorphicSerializer, AliasSerializer, TemplateCategorySerializer, \ TransactionTemplateSerializer, TransactionPolymorphicSerializer @@ -81,7 +82,7 @@ class TemplateCategoryViewSet(ReadProtectedModelViewSet): search_fields = ['$name', ] -class TransactionTemplateViewSet(ReadProtectedModelViewSet): +class TransactionTemplateViewSet(viewsets.ModelViewSet): """ REST API View set. The djangorestframework plugin will get all `TransactionTemplate` objects, serialize it to JSON with the given serializer, diff --git a/apps/note/tables.py b/apps/note/tables.py index 2986c748..ad57c265 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -90,5 +90,10 @@ class ButtonTable(tables.Table): model = TransactionTemplate + + delete = tables.TemplateColumn(template_code=""" +
-
- {% render_table table %} -
+
+
+
{% trans "buttons listing "%}
+
+
+ {% render_table table %} +
+
{% endblock %} @@ -40,7 +45,6 @@ function getInfo() { $('table tr').show(); } } - var timer; var timer_on; /* Fontion appelée quand le texte change (délenche le timer) */ @@ -54,5 +58,21 @@ function search_field_moved(secondfield) { timer_on = true; } } +// on click of button "delete" , call the API + function delete_button(button_id){ + console.log(button_id); + $.ajax({ + url:"/api/note/transaction/template/"+button_id, + method:"DELETE", + headers: { + "X-CSRFTOKEN": CSRF_TOKEN + }, + success: function(){ + addMsg('{% trans "button successfully deleted "%}','success'); + $("#buttons_table").load('{% url "note:template_list" %} #buttons_tables'); + }, + error: addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' ) + }); +} {% endblock %} From 41568916b832d4f5ee8660cfe747788f6a51b24a Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 24 Mar 2020 22:13:15 +0100 Subject: [PATCH 18/24] error fixes --- apps/note/views.py | 2 +- apps/permission/permissions.py | 1 + templates/note/transactiontemplate_list.html | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/note/views.py b/apps/note/views.py index a8118cb2..8a7d24fd 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -109,7 +109,7 @@ class TransactionTemplateCreateView(LoginRequiredMixin, CreateView): """ model = TransactionTemplate form_class = TransactionTemplateForm - success_url = reverse_lazy('template_list') + success_url = reverse_lazy('note:template_list') class TransactionTemplateListView(LoginRequiredMixin, SingleTableView): """ diff --git a/apps/permission/permissions.py b/apps/permission/permissions.py index 7959065f..9f6d8cd2 100644 --- a/apps/permission/permissions.py +++ b/apps/permission/permissions.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later from rest_framework.permissions import DjangoObjectPermissions +from .backends import PermissionBackend SAFE_METHODS = ('HEAD', 'OPTIONS', ) diff --git a/templates/note/transactiontemplate_list.html b/templates/note/transactiontemplate_list.html index ca88010f..ea227ea8 100644 --- a/templates/note/transactiontemplate_list.html +++ b/templates/note/transactiontemplate_list.html @@ -60,7 +60,6 @@ function search_field_moved(secondfield) { } // on click of button "delete" , call the API function delete_button(button_id){ - console.log(button_id); $.ajax({ url:"/api/note/transaction/template/"+button_id, method:"DELETE", From 9f53bda1cd13072c206766fb0f10191d6815af5a Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 24 Mar 2020 23:02:12 +0100 Subject: [PATCH 19/24] clean code --- apps/note/tables.py | 28 ++++++++++++-------- templates/note/transactiontemplate_list.html | 18 ++++++------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index ad57c265..bfb60303 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -56,7 +56,11 @@ class HistoryTable(tables.Table): def render_valid(self, value): return "✔" if value else "✖" - +# function delete_button(id) provided in template file +delete_template = """ + """ class AliasTable(tables.Table): @@ -73,9 +73,16 @@ class AliasTable(tables.Table): show_header = False name = tables.Column(attrs={'td': {'class': 'text-center'}}) - delete = tables.TemplateColumn(template_code=delete_template, - extra_context={"delete_trans":_('delete')}, - attrs={'td':{'class': 'col-sm-1'}}) + # delete = tables.TemplateColumn(template_code=delete_template, + # attrs={'td':{'class': 'col-sm-1'}}) + + delete = tables.LinkColumn('member:user_alias_delete', + args=[A('pk')], + attrs={ + 'td': {'class': 'col-sm-2'}, + 'a': {'class': 'btn btn-danger'}}, + text='delete', accessor='pk') + class ButtonTable(tables.Table): class Meta: attrs = { From b3c1032f4f49b32b7e349277abe38d3b2185c614 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 24 Mar 2020 23:27:08 +0100 Subject: [PATCH 21/24] wrap in function for correct behavior --- templates/note/transactiontemplate_list.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/note/transactiontemplate_list.html b/templates/note/transactiontemplate_list.html index 50421f68..ba0254bc 100644 --- a/templates/note/transactiontemplate_list.html +++ b/templates/note/transactiontemplate_list.html @@ -61,7 +61,7 @@ function search_field_moved(secondfield) { // on click of button "delete" , call the API function delete_button(button_id){ $.ajax({ - url:"/api/note/transaction/template/"+button_id, + url:"/api/note/transaction/template/"+button_id+"/", method:"DELETE", headers: {"X-CSRFTOKEN": CSRF_TOKEN} }) @@ -69,7 +69,9 @@ function search_field_moved(secondfield) { addMsg('{% trans "button successfully deleted "%}','success'); $("#buttons_table").load("{% url 'note:template_list' %} #buttons_table"); }) - .fail(addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' )); + .fail(function(){ + addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' ) + }); } {% endblock %} From 20ea017e960a9060f87b4d0fa5c24e3930b08ec7 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 24 Mar 2020 23:32:48 +0100 Subject: [PATCH 22/24] row color to show if display --- apps/note/tables.py | 4 ++-- apps/note/views.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index 256ebad3..b2326fe3 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -87,10 +87,10 @@ class ButtonTable(tables.Table): class Meta: attrs = { 'class': - 'table table-bordered condensed table-striped table-hover' + 'table table-bordered condensed table-hover' } row_attrs = { - 'class': 'table-row', + 'class': lambda record: 'table-row ' + 'table-success' if record.display else 'table-danger', 'id': lambda record: "row-"+str(record.pk), 'data-href': lambda record: record.pk } diff --git a/apps/note/views.py b/apps/note/views.py index 8a7d24fd..6ddc8975 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -132,7 +132,7 @@ class TransactionTemplateUpdateView(LoginRequiredMixin, UpdateView): """ model = TransactionTemplate form_class = TransactionTemplateForm - + success_url = reverse_lazy('note:template_list') class ConsoView(LoginRequiredMixin, SingleTableView): """ From 0411646ae69f8e0011e51baf954bfaebf25ac352 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Wed, 25 Mar 2020 00:03:48 +0100 Subject: [PATCH 23/24] make the CI pass and nicer front --- apps/note/tables.py | 29 ++++++++++---------- apps/note/views.py | 10 ++----- templates/note/transactiontemplate_list.html | 14 ++++++---- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index b2326fe3..6e662107 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -56,11 +56,12 @@ class HistoryTable(tables.Table): def render_valid(self, value): return "✔" if value else "✖" + # function delete_button(id) provided in template file -delete_template = """ +DELETE_TEMPLATE = """ """ - + class AliasTable(tables.Table): class Meta: attrs = { @@ -75,7 +76,7 @@ class AliasTable(tables.Table): name = tables.Column(attrs={'td': {'class': 'text-center'}}) # delete = tables.TemplateColumn(template_code=delete_template, # attrs={'td':{'class': 'col-sm-1'}}) - + delete = tables.LinkColumn('member:user_alias_delete', args=[A('pk')], attrs={ @@ -97,16 +98,16 @@ class ButtonTable(tables.Table): model = TransactionTemplate - edit = tables.LinkColumn('note:template_update', - args=[A('pk')], - attrs={ - 'td': {'class': 'col-sm-1'}, - 'a': {'class': 'btn btn-primary'}}, - text=_('edit'), accessor='pk') - - delete = tables.TemplateColumn(template_code=delete_template, - extra_context={"delete_trans":_('delete')}, - attrs={'td':{'class':'col-sm-1'}}) - + edit = tables.LinkColumn('note:template_update', + args=[A('pk')], + attrs={'td': {'class': 'col-sm-1'}, + 'a': {'class': 'btn btn-primary'}}, + text=_('edit'), + accessor='pk') + + delete = tables.TemplateColumn(template_code=DELETE_TEMPLATE, + extra_context={"delete_trans": _('delete')}, + attrs={'td': {'class': 'col-sm-1'}}) + def render_amount(self, value): return pretty_money(value) diff --git a/apps/note/views.py b/apps/note/views.py index 6ddc8975..7d8d80aa 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -111,6 +111,7 @@ class TransactionTemplateCreateView(LoginRequiredMixin, CreateView): form_class = TransactionTemplateForm success_url = reverse_lazy('note:template_list') + class TransactionTemplateListView(LoginRequiredMixin, SingleTableView): """ List TransactionsTemplates @@ -118,14 +119,6 @@ class TransactionTemplateListView(LoginRequiredMixin, SingleTableView): model = TransactionTemplate table_class = ButtonTable - def get_queryset(self): - name = self.request.GET.get('name','') - if (name != ''): - object_list = self.model.objects.filter(name__icontains = name) - else: - object_list = self.model.objects.all() - return object_list - class TransactionTemplateUpdateView(LoginRequiredMixin, UpdateView): """ @@ -134,6 +127,7 @@ class TransactionTemplateUpdateView(LoginRequiredMixin, UpdateView): form_class = TransactionTemplateForm success_url = reverse_lazy('note:template_list') + class ConsoView(LoginRequiredMixin, SingleTableView): """ The Magic View that make people pay their beer and burgers. diff --git a/templates/note/transactiontemplate_list.html b/templates/note/transactiontemplate_list.html index ba0254bc..043a06e9 100644 --- a/templates/note/transactiontemplate_list.html +++ b/templates/note/transactiontemplate_list.html @@ -14,12 +14,14 @@
-
-
-
{% trans "buttons listing "%}
-
-
- {% render_table table %} +
+
+
+
{% trans "buttons listing "%}
+
+
+ {% render_table table %} +
From f85f292d5b33b147613b11e0ef64c34b4ba6f61d Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Wed, 25 Mar 2020 00:12:56 +0100 Subject: [PATCH 24/24] linter compliance --- apps/note/api/views.py | 1 + apps/note/tables.py | 4 +++- apps/note/views.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/note/api/views.py b/apps/note/api/views.py index d35c3797..fc4a0e8f 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -94,6 +94,7 @@ class TransactionTemplateViewSet(viewsets.ModelViewSet): filterset_fields = ['name', 'amount', 'display', 'category', ] search_fields = ['$name', ] + class TransactionViewSet(ReadProtectedModelViewSet): """ REST API View set. diff --git a/apps/note/tables.py b/apps/note/tables.py index 6e662107..20054d2c 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -62,6 +62,7 @@ DELETE_TEMPLATE = """ """ + class AliasTable(tables.Table): class Meta: attrs = { @@ -84,6 +85,7 @@ class AliasTable(tables.Table): 'a': {'class': 'btn btn-danger'}}, text='delete', accessor='pk') + class ButtonTable(tables.Table): class Meta: attrs = { @@ -92,7 +94,7 @@ class ButtonTable(tables.Table): } row_attrs = { 'class': lambda record: 'table-row ' + 'table-success' if record.display else 'table-danger', - 'id': lambda record: "row-"+str(record.pk), + 'id': lambda record: "row-" + str(record.pk), 'data-href': lambda record: record.pk } diff --git a/apps/note/views.py b/apps/note/views.py index 7d8d80aa..ddf5ee6f 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -6,7 +6,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.contenttypes.models import ContentType from django.db.models import Q from django.utils.translation import gettext_lazy as _ -from django.views.generic import CreateView, ListView, UpdateView +from django.views.generic import CreateView, UpdateView from django_tables2 import SingleTableView from django.urls import reverse_lazy from permission.backends import PermissionBackend