From cc5185b3ed718f8dd91c52978d206b98eb537ad3 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 14 Mar 2020 02:08:23 +0100 Subject: [PATCH] (Un)validate transactions --- apps/note/tables.py | 21 +++++++++++++++++++-- static/js/base.js | 7 +------ templates/note/conso_form.html | 30 +++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index 496ae335..9309e14c 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later +import html + import django_tables2 as tables from django.db.models import F from django_tables2.utils import A @@ -19,23 +21,38 @@ class HistoryTable(tables.Table): model = Transaction exclude = ("id", "polymorphic_ctype", ) template_name = 'django_tables2/bootstrap4.html' - sequence = ('...', 'total', 'valid') + sequence = ('...', 'total', 'valid', ) + orderable = False 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'}}) + def order_total(self, queryset, is_descending): # needed for rendering queryset = queryset.annotate(total=F('amount') * F('quantity')) \ .order_by(('-' if is_descending else '') + 'total') - return (queryset, True) + return queryset, True + def render_amount(self, value): return pretty_money(value) + def render_total(self, value): return pretty_money(value) + # Django-tables escape strings. That's a wrong thing. + def render_reason(self, value): + return html.unescape(value) + + + def render_valid(self, value): + return "✔" if value else "✖" + + class AliasTable(tables.Table): class Meta: attrs = { diff --git a/static/js/base.js b/static/js/base.js index 87ab0eb3..cca6e41c 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -139,7 +139,7 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes let pattern = field.val(); // If the pattern is not modified, we don't query the API - if (pattern === old_pattern) + if (pattern === old_pattern || pattern === "") return; old_pattern = pattern; @@ -150,11 +150,6 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes let aliases_matched_obj = $("#" + alias_matched_id); let aliases_matched_html = ""; - if (pattern === "") { - aliases_matched_obj.html(""); - return; - } - // Get matched notes with the given pattern getMatchedNotes(pattern, function(aliases) { // The response arrived too late, we stop the request diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 100f46c2..a007cecf 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -133,9 +133,9 @@ {% block extracss %} {% endblock %} @@ -143,6 +143,7 @@ {% block extrajavascript %} {% endblock %}