From c3bcf0fa27672b29943b918a5e9261ee01e17788 Mon Sep 17 00:00:00 2001 From: Edward Oliveira Date: Sat, 19 Nov 2022 14:07:35 -0300 Subject: [PATCH] Add template tags --- sapl/base/forms.py | 12 +++++----- sapl/base/templatetags/common_tags.py | 30 ++++++++++++++++++++++++ sapl/templates/base/auditlog_filter.html | 23 +++++++++--------- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 2c7289f72..044e1dcad 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -751,15 +751,15 @@ def get_models(): class AuditLogFilterSet(django_filters.FilterSet): OPERATION_CHOICES = ( - ('C', 'Criar'), - ('D', 'Apagar'), - ('U', 'Atualizar'), + ('U', 'Atualizado'), + ('C', 'Criado'), + ('D', 'Excluído'), ) username = django_filters.ChoiceFilter(choices=get_username(), label=_('Usuário')) object_id = django_filters.NumberFilter(label=_('Id')) operation = django_filters.ChoiceFilter(choices=OPERATION_CHOICES, label=_('Operação')) - model_name = django_filters.ChoiceFilter(choices=get_models, label=_('Objeto')) + model_name = django_filters.ChoiceFilter(choices=get_models, label=_('Tipo de Registro')) timestamp = django_filters.DateRangeFilter(label=_('Período')) class Meta: @@ -769,10 +769,10 @@ class AuditLogFilterSet(django_filters.FilterSet): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - row0 = to_row([('username', 3), + row0 = to_row([('username', 2), ('operation', 2), ('model_name', 4), - ('object_id', 1), + ('object_id', 2), ('timestamp', 2)]) self.form.helper = SaplFormHelper() diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index f5b9c2c36..b1d804cc0 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/sapl/base/templatetags/common_tags.py @@ -29,6 +29,17 @@ def define(arg): return arg +@register.simple_tag +def describe_operation(value): + if value == "C": + return "Criar" + elif value == "D": + return "Apagar" + elif value == "U": + return "Atualizar" + return "" + + @register.simple_tag def field_verbose_name(instance, field_name): return instance._meta.get_field(field_name).verbose_name @@ -51,6 +62,25 @@ def model_verbose_name_plural(class_name): model = get_class(class_name) return model._meta.verbose_name_plural + +@register.filter +def obfuscate_value(value, key): + if key in ["hash", "google_recaptcha_secret_key", "password", "google_recaptcha_site_key", "hash_code"]: + return "***************" + return value + + +@register.filter +def desc_operation(value): + if value == "C": + return "Criado" + elif value == "D": + return "Excluido" + elif value == "U": + return "Atualizado" + return "" + + @register.filter def format_user(user): if user.first_name: diff --git a/sapl/templates/base/auditlog_filter.html b/sapl/templates/base/auditlog_filter.html index 9d2eeeba3..ef4b7ef77 100644 --- a/sapl/templates/base/auditlog_filter.html +++ b/sapl/templates/base/auditlog_filter.html @@ -1,5 +1,5 @@ {% extends "crud/list.html" %} -{% load i18n %} +{% load i18n common_tags %} {% load tz %} {% load crispy_forms_tags staticfiles %} @@ -30,9 +30,9 @@ deleted { Data/Hora Usuário Operação - Objeto + Registro Id - Campos +   @@ -40,27 +40,26 @@ deleted { {{ obj.timestamp|localtime|date:"d/m/Y, H:i:s" }} {{ obj.username|default:"Não informado" }} - {{ obj.operation }} + {{ obj.operation|desc_operation }} {{ obj.model_name }} {{obj.data.pk}} - Campos ({{obj.data.fields|length}})
+ Atributos ({{obj.data.fields|length}})

+ {% endfor %}