2018-05-22 12:22:46 -04:00
|
|
|
import django_tables2 as tables
|
2020-09-25 14:18:29 -04:00
|
|
|
from django.conf import settings
|
2018-05-22 12:22:46 -04:00
|
|
|
|
2021-03-17 16:29:43 -04:00
|
|
|
from utilities.tables import (
|
|
|
|
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ContentTypeColumn, ToggleColumn,
|
|
|
|
)
|
2021-03-16 15:00:08 -04:00
|
|
|
from .models import ConfigContext, JournalEntry, ObjectChange, Tag, TaggedItem
|
2018-05-22 12:22:46 -04:00
|
|
|
|
2018-06-27 16:02:34 -04:00
|
|
|
CONFIGCONTEXT_ACTIONS = """
|
|
|
|
{% if perms.extras.change_configcontext %}
|
2020-11-06 14:49:14 -05:00
|
|
|
<a href="{% url 'extras:configcontext_edit' pk=record.pk %}" class="btn btn-xs btn-warning"><i class="mdi mdi-pencil" aria-hidden="true"></i></a>
|
2018-06-27 16:02:34 -04:00
|
|
|
{% endif %}
|
|
|
|
{% if perms.extras.delete_configcontext %}
|
2020-11-06 14:49:14 -05:00
|
|
|
<a href="{% url 'extras:configcontext_delete' pk=record.pk %}" class="btn btn-xs btn-danger"><i class="mdi mdi-trash-can-outline" aria-hidden="true"></i></a>
|
2018-06-27 16:02:34 -04:00
|
|
|
{% endif %}
|
|
|
|
"""
|
|
|
|
|
2018-06-20 13:52:54 -04:00
|
|
|
OBJECTCHANGE_OBJECT = """
|
2020-10-07 13:13:03 -04:00
|
|
|
{% if record.changed_object.get_absolute_url %}
|
2018-06-20 13:52:54 -04:00
|
|
|
<a href="{{ record.changed_object.get_absolute_url }}">{{ record.object_repr }}</a>
|
|
|
|
{% else %}
|
|
|
|
{{ record.object_repr }}
|
|
|
|
{% endif %}
|
|
|
|
"""
|
|
|
|
|
2018-07-12 13:54:22 -04:00
|
|
|
OBJECTCHANGE_REQUEST_ID = """
|
|
|
|
<a href="{% url 'extras:objectchange_list' %}?request_id={{ value }}">{{ value }}</a>
|
|
|
|
"""
|
|
|
|
|
2018-05-22 12:22:46 -04:00
|
|
|
|
|
|
|
class TagTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
2021-03-26 15:25:18 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2019-02-20 03:52:47 -05:00
|
|
|
color = ColorColumn()
|
2021-02-26 17:23:23 -05:00
|
|
|
actions = ButtonsColumn(Tag)
|
2018-05-22 12:22:46 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = Tag
|
2020-03-13 17:00:00 -04:00
|
|
|
fields = ('pk', 'name', 'items', 'slug', 'color', 'description', 'actions')
|
2018-06-27 16:02:34 -04:00
|
|
|
|
|
|
|
|
2018-11-15 16:47:41 -05:00
|
|
|
class TaggedItemTable(BaseTable):
|
2021-03-29 16:53:41 -04:00
|
|
|
content_type = ContentTypeColumn(
|
|
|
|
verbose_name='Type'
|
|
|
|
)
|
|
|
|
content_object = tables.Column(
|
|
|
|
linkify=True,
|
2018-11-15 16:47:41 -05:00
|
|
|
orderable=False,
|
|
|
|
verbose_name='Object'
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = TaggedItem
|
2021-03-29 16:53:41 -04:00
|
|
|
fields = ('content_type', 'content_object')
|
2018-11-15 16:47:41 -05:00
|
|
|
|
|
|
|
|
2018-06-27 16:02:34 -04:00
|
|
|
class ConfigContextTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = tables.LinkColumn()
|
2018-06-29 12:05:56 -04:00
|
|
|
is_active = BooleanColumn(
|
2018-06-28 14:19:26 -04:00
|
|
|
verbose_name='Active'
|
|
|
|
)
|
2018-06-27 16:02:34 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = ConfigContext
|
2020-04-29 11:03:49 -04:00
|
|
|
fields = (
|
|
|
|
'pk', 'name', 'weight', 'is_active', 'description', 'regions', 'sites', 'roles', 'platforms',
|
|
|
|
'cluster_groups', 'clusters', 'tenant_groups', 'tenants',
|
|
|
|
)
|
|
|
|
default_columns = ('pk', 'name', 'weight', 'is_active', 'description')
|
2018-06-20 13:52:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ObjectChangeTable(BaseTable):
|
2020-09-25 14:18:29 -04:00
|
|
|
time = tables.DateTimeColumn(
|
|
|
|
linkify=True,
|
|
|
|
format=settings.SHORT_DATETIME_FORMAT
|
2018-06-20 13:52:54 -04:00
|
|
|
)
|
2020-09-25 14:18:29 -04:00
|
|
|
action = ChoiceFieldColumn()
|
2021-03-17 16:29:43 -04:00
|
|
|
changed_object_type = ContentTypeColumn(
|
2018-06-22 15:05:40 -04:00
|
|
|
verbose_name='Type'
|
|
|
|
)
|
2018-06-20 13:52:54 -04:00
|
|
|
object_repr = tables.TemplateColumn(
|
|
|
|
template_code=OBJECTCHANGE_OBJECT,
|
|
|
|
verbose_name='Object'
|
|
|
|
)
|
2018-07-12 13:54:22 -04:00
|
|
|
request_id = tables.TemplateColumn(
|
|
|
|
template_code=OBJECTCHANGE_REQUEST_ID,
|
2018-06-20 13:52:54 -04:00
|
|
|
verbose_name='Request ID'
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = ObjectChange
|
2018-06-22 15:05:40 -04:00
|
|
|
fields = ('time', 'user_name', 'action', 'changed_object_type', 'object_repr', 'request_id')
|
2021-03-16 15:00:08 -04:00
|
|
|
|
|
|
|
|
2021-03-29 09:43:21 -04:00
|
|
|
class ObjectJournalTable(BaseTable):
|
|
|
|
"""
|
|
|
|
Used for displaying a set of JournalEntries within the context of a single object.
|
|
|
|
"""
|
2021-03-16 15:57:23 -04:00
|
|
|
created = tables.DateTimeColumn(
|
|
|
|
format=settings.SHORT_DATETIME_FORMAT
|
|
|
|
)
|
2021-03-17 12:51:39 -04:00
|
|
|
kind = ChoiceFieldColumn()
|
2021-03-29 09:43:21 -04:00
|
|
|
comments = tables.TemplateColumn(
|
|
|
|
template_code='{% load helpers %}{{ value|render_markdown }}'
|
|
|
|
)
|
2021-03-16 15:57:23 -04:00
|
|
|
actions = ButtonsColumn(
|
|
|
|
model=JournalEntry,
|
|
|
|
buttons=('edit', 'delete')
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = JournalEntry
|
2021-03-29 09:43:21 -04:00
|
|
|
fields = ('created', 'created_by', 'kind', 'comments', 'actions')
|
2021-03-16 15:57:23 -04:00
|
|
|
|
|
|
|
|
2021-03-29 09:43:21 -04:00
|
|
|
class JournalEntryTable(ObjectJournalTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
assigned_object_type = ContentTypeColumn(
|
|
|
|
verbose_name='Object type'
|
2021-03-16 15:00:08 -04:00
|
|
|
)
|
2021-03-29 09:43:21 -04:00
|
|
|
assigned_object = tables.Column(
|
|
|
|
linkify=True,
|
|
|
|
orderable=False,
|
|
|
|
verbose_name='Object'
|
2021-03-16 15:00:08 -04:00
|
|
|
)
|
2021-03-29 09:54:06 -04:00
|
|
|
comments = tables.TemplateColumn(
|
|
|
|
template_code='{% load helpers %}{{ value|render_markdown|truncatewords_html:50 }}'
|
|
|
|
)
|
2021-03-16 15:00:08 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = JournalEntry
|
2021-03-29 09:43:21 -04:00
|
|
|
fields = (
|
|
|
|
'pk', 'created', 'created_by', 'assigned_object_type', 'assigned_object', 'kind', 'comments', 'actions'
|
|
|
|
)
|