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 %}
-
-
-
-ID | Nom |
- Destinataire |
- Montant |
- Catégorie |
-
-{% for object in object_list %}
-
- {{object.pk}} |
- {{ object.name }} |
- {{ object.destination }} |
- {{ object.amount | pretty_money }} |
- {{ object.template_type }} |
-
-{% endfor %}
-
-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 %}
+
-
+ {%endif%}
-
- {% render_table table %}
-
+
+
+
+ {% 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 = """
+