Browse Source

Add template tags

pull/3622/head
Edward Ribeiro 2 years ago
parent
commit
c3bcf0fa27
  1. 12
      sapl/base/forms.py
  2. 30
      sapl/base/templatetags/common_tags.py
  3. 23
      sapl/templates/base/auditlog_filter.html

12
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()

30
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:

23
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 {
<th>Data/Hora</th>
<th>Usuário</th>
<th>Operação</th>
<th>Objeto</th>
<th>Registro</th>
<th>Id</th>
<th>Campos</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
@ -40,27 +40,26 @@ deleted {
<tr class="background:{%if obj.operation == 'D' %}red{%else%}lightgray{%endif%}">
<td>{{ obj.timestamp|localtime|date:"d/m/Y, H:i:s" }}</td>
<td>{{ obj.username|default:"Não informado" }}</td>
<td>{{ obj.operation }}</td>
<td>{{ obj.operation|desc_operation }}</td>
<td>{{ obj.model_name }}</td>
<td>{{obj.data.pk}}</td>
<td>
<strong>Campos ({{obj.data.fields|length}})</strong><br/>
<strong>Atributos ({{obj.data.fields|length}})</strong><br/>
<hr/>
<ul>
{% for key, value in obj.data.fields.items %}
<ul>
<li>
{{key}}:
{% if key == "password" %}*********{%else%}{{value|default_if_none:""}}{%endif%}<br/>
</li>
</ul>
{% if forloop.counter == 10 %}
{% if forloop.counter == 11 %}
<div id="{{obj.id}}" style="display:none;">
{%endif%}
<li>
{{key}}: {{ value|default_if_none:""|obfuscate_value:key }}<br/>
</li>
{% if forloop.last and forloop.counter > 10 %}
</div>
<input class="btn btn-primary btn-sm" type="button" value="Expandir/Colapsar" onclick="toggleDetails({{obj.id}})"/>
{% endif %}
{% endfor %}
</ul>
</td>
</tr>
{% endfor %}

Loading…
Cancel
Save