General cleanup of tables

This commit is contained in:
Jeremy Stretch
2020-09-25 14:18:29 -04:00
parent 29741ecf7f
commit 3be9d13485
7 changed files with 27 additions and 106 deletions

View File

@@ -78,6 +78,12 @@ class ObjectChangeActionChoices(ChoiceSet):
(ACTION_DELETE, 'Deleted'),
)
CSS_CLASSES = {
ACTION_CREATE: 'success',
ACTION_UPDATE: 'primary',
ACTION_DELETE: 'danger',
}
#
# Log Levels for Reports and Scripts

View File

@@ -152,3 +152,6 @@ class ObjectChange(models.Model):
self.object_repr,
self.object_data,
)
def get_action_class(self):
return ObjectChangeActionChoices.CSS_CLASSES.get(self.action)

View File

@@ -1,6 +1,7 @@
import django_tables2 as tables
from django.conf import settings
from utilities.tables import BaseTable, BooleanColumn, ButtonsColumn, ColorColumn, ToggleColumn
from utilities.tables import BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ToggleColumn
from .models import ConfigContext, ObjectChange, Tag, TaggedItem
TAGGED_ITEM = """
@@ -20,20 +21,6 @@ CONFIGCONTEXT_ACTIONS = """
{% endif %}
"""
OBJECTCHANGE_TIME = """
<a href="{{ record.get_absolute_url }}">{{ value|date:"SHORT_DATETIME_FORMAT" }}</a>
"""
OBJECTCHANGE_ACTION = """
{% if record.action == 'create' %}
<span class="label label-success">Created</span>
{% elif record.action == 'update' %}
<span class="label label-primary">Updated</span>
{% elif record.action == 'delete' %}
<span class="label label-danger">Deleted</span>
{% endif %}
"""
OBJECTCHANGE_OBJECT = """
{% if record.action != 3 and record.changed_object.get_absolute_url %}
<a href="{{ record.changed_object.get_absolute_url }}">{{ record.object_repr }}</a>
@@ -91,12 +78,11 @@ class ConfigContextTable(BaseTable):
class ObjectChangeTable(BaseTable):
time = tables.TemplateColumn(
template_code=OBJECTCHANGE_TIME
)
action = tables.TemplateColumn(
template_code=OBJECTCHANGE_ACTION
time = tables.DateTimeColumn(
linkify=True,
format=settings.SHORT_DATETIME_FORMAT
)
action = ChoiceFieldColumn()
changed_object_type = tables.Column(
verbose_name='Type'
)