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 (
|
2021-08-26 12:55:37 -04:00
|
|
|
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ContentTypeColumn, ContentTypesColumn,
|
2021-09-17 12:04:22 -04:00
|
|
|
MarkdownColumn, ToggleColumn,
|
2021-03-17 16:29:43 -04:00
|
|
|
)
|
2021-06-22 16:28:06 -04:00
|
|
|
from .models import *
|
2018-05-22 12:22:46 -04:00
|
|
|
|
2021-09-17 15:37:19 -04:00
|
|
|
__all__ = (
|
|
|
|
'ConfigContextTable',
|
|
|
|
'CustomFieldTable',
|
|
|
|
'CustomLinkTable',
|
|
|
|
'ExportTemplateTable',
|
|
|
|
'JournalEntryTable',
|
|
|
|
'ObjectChangeTable',
|
|
|
|
'ObjectJournalTable',
|
|
|
|
'TaggedItemTable',
|
|
|
|
'TagTable',
|
|
|
|
'WebhookTable',
|
|
|
|
)
|
|
|
|
|
2018-06-27 16:02:34 -04:00
|
|
|
CONFIGCONTEXT_ACTIONS = """
|
|
|
|
{% if perms.extras.change_configcontext %}
|
2021-05-26 09:07:45 -07:00
|
|
|
<a href="{% url 'extras:configcontext_edit' pk=record.pk %}" class="btn btn-sm 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 %}
|
2021-05-26 09:07:45 -07:00
|
|
|
<a href="{% url 'extras:configcontext_delete' pk=record.pk %}" class="btn btn-sm 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
|
|
|
|
2021-06-22 16:28:06 -04:00
|
|
|
#
|
|
|
|
# Custom fields
|
|
|
|
#
|
|
|
|
|
|
|
|
class CustomFieldTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-08-26 12:55:37 -04:00
|
|
|
content_types = ContentTypesColumn()
|
2021-06-24 08:51:29 -04:00
|
|
|
required = BooleanColumn()
|
2021-06-22 16:28:06 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = CustomField
|
|
|
|
fields = (
|
2021-11-02 16:21:34 -04:00
|
|
|
'pk', 'id', 'name', 'content_types', 'label', 'type', 'required', 'weight', 'default',
|
|
|
|
'description', 'filter_logic', 'choices',
|
2021-06-22 16:28:06 -04:00
|
|
|
)
|
2021-08-26 12:55:37 -04:00
|
|
|
default_columns = ('pk', 'name', 'content_types', 'label', 'type', 'required', 'description')
|
2021-06-22 16:28:06 -04:00
|
|
|
|
|
|
|
|
2021-06-23 17:09:15 -04:00
|
|
|
#
|
|
|
|
# Custom links
|
|
|
|
#
|
|
|
|
|
|
|
|
class CustomLinkTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-06-24 08:51:29 -04:00
|
|
|
content_type = ContentTypeColumn()
|
2021-06-23 20:39:35 -04:00
|
|
|
new_window = BooleanColumn()
|
2021-06-23 17:09:15 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = CustomLink
|
|
|
|
fields = (
|
2021-11-02 16:21:34 -04:00
|
|
|
'pk', 'id', 'name', 'content_type', 'link_text', 'link_url', 'weight', 'group_name',
|
|
|
|
'button_class', 'new_window',
|
2021-06-23 17:09:15 -04:00
|
|
|
)
|
|
|
|
default_columns = ('pk', 'name', 'content_type', 'group_name', 'button_class', 'new_window')
|
|
|
|
|
|
|
|
|
2021-06-23 20:39:35 -04:00
|
|
|
#
|
|
|
|
# Export templates
|
|
|
|
#
|
|
|
|
|
|
|
|
class ExportTemplateTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-06-24 08:51:29 -04:00
|
|
|
content_type = ContentTypeColumn()
|
2021-06-23 20:39:35 -04:00
|
|
|
as_attachment = BooleanColumn()
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = ExportTemplate
|
|
|
|
fields = (
|
2021-11-02 16:21:34 -04:00
|
|
|
'pk', 'id', 'name', 'content_type', 'description', 'mime_type', 'file_extension', 'as_attachment',
|
2021-06-23 20:39:35 -04:00
|
|
|
)
|
|
|
|
default_columns = (
|
|
|
|
'pk', 'name', 'content_type', 'description', 'mime_type', 'file_extension', 'as_attachment',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-06-23 21:24:23 -04:00
|
|
|
#
|
|
|
|
# Webhooks
|
|
|
|
#
|
|
|
|
|
|
|
|
class WebhookTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2021-08-26 12:55:37 -04:00
|
|
|
content_types = ContentTypesColumn()
|
2021-06-24 08:51:29 -04:00
|
|
|
enabled = BooleanColumn()
|
2021-08-26 14:48:24 -04:00
|
|
|
type_create = BooleanColumn(
|
|
|
|
verbose_name='Create'
|
|
|
|
)
|
|
|
|
type_update = BooleanColumn(
|
|
|
|
verbose_name='Update'
|
|
|
|
)
|
|
|
|
type_delete = BooleanColumn(
|
|
|
|
verbose_name='Delete'
|
|
|
|
)
|
|
|
|
ssl_validation = BooleanColumn(
|
|
|
|
verbose_name='SSL Validation'
|
|
|
|
)
|
2021-06-23 21:24:23 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = Webhook
|
|
|
|
fields = (
|
2021-11-02 16:21:34 -04:00
|
|
|
'pk', 'id', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method',
|
2021-08-26 12:55:37 -04:00
|
|
|
'payload_url', 'secret', 'ssl_validation', 'ca_file_path',
|
2021-06-23 21:24:23 -04:00
|
|
|
)
|
|
|
|
default_columns = (
|
2021-08-26 12:55:37 -04:00
|
|
|
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method',
|
|
|
|
'payload_url',
|
2021-06-23 21:24:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-06-22 16:28:06 -04:00
|
|
|
#
|
|
|
|
# Tags
|
|
|
|
#
|
|
|
|
|
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
|
2021-11-02 16:21:34 -04:00
|
|
|
fields = ('pk', 'id', 'name', 'items', 'slug', 'color', 'description', 'actions')
|
|
|
|
default_columns = ('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-11-02 16:21:34 -04:00
|
|
|
id = tables.Column(
|
|
|
|
verbose_name='ID',
|
|
|
|
linkify=lambda record: record.content_object.get_absolute_url(),
|
|
|
|
accessor='content_object__id'
|
|
|
|
)
|
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-11-02 16:21:34 -04:00
|
|
|
fields = ('id', '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()
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
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 = (
|
2021-11-02 16:21:34 -04:00
|
|
|
'pk', 'id', 'name', 'weight', 'is_active', 'description', 'regions', 'sites', 'roles',
|
|
|
|
'platforms', 'cluster_groups', 'clusters', 'tenant_groups', 'tenants',
|
2020-04-29 11:03:49 -04:00
|
|
|
)
|
|
|
|
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
|
2021-11-02 16:21:34 -04:00
|
|
|
fields = ('id', '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(
|
2021-04-13 10:53:55 -04:00
|
|
|
linkify=True,
|
2021-03-16 15:57:23 -04:00
|
|
|
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(
|
2021-04-13 10:53:55 -04:00
|
|
|
template_code='{% load helpers %}{{ value|render_markdown|truncatewords_html:50 }}'
|
2021-03-29 09:43:21 -04:00
|
|
|
)
|
2021-03-16 15:57:23 -04:00
|
|
|
actions = ButtonsColumn(
|
2021-04-13 10:53:55 -04:00
|
|
|
model=JournalEntry
|
2021-03-16 15:57:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = JournalEntry
|
2021-11-02 16:21:34 -04:00
|
|
|
fields = ('id', '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-09-17 12:04:22 -04:00
|
|
|
comments = MarkdownColumn()
|
2021-03-16 15:00:08 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = JournalEntry
|
2021-03-29 09:43:21 -04:00
|
|
|
fields = (
|
2021-11-02 16:21:34 -04:00
|
|
|
'pk', 'id', 'created', 'created_by', 'assigned_object_type', 'assigned_object', 'kind',
|
|
|
|
'comments', 'actions'
|
|
|
|
)
|
|
|
|
default_columns = (
|
|
|
|
'pk', 'created', 'created_by', 'assigned_object_type', 'assigned_object', 'kind',
|
|
|
|
'comments', 'actions'
|
2021-03-29 09:43:21 -04:00
|
|
|
)
|