2016-08-15 16:58:25 -04:00
|
|
|
from django import forms
|
2016-03-01 11:23:03 -05:00
|
|
|
from django.contrib import admin
|
|
|
|
|
2018-05-30 11:19:10 -04:00
|
|
|
from utilities.forms import LaxURLField
|
2020-06-29 03:50:05 -04:00
|
|
|
from .models import CustomField, CustomFieldChoice, CustomLink, Graph, ExportTemplate, JobResult, Webhook
|
2019-12-31 16:11:47 -05:00
|
|
|
from .reports import get_report
|
2016-08-15 16:58:25 -04:00
|
|
|
|
|
|
|
|
2017-09-19 11:31:29 -04:00
|
|
|
def order_content_types(field):
|
|
|
|
"""
|
|
|
|
Order the list of available ContentTypes by application
|
|
|
|
"""
|
|
|
|
queryset = field.queryset.order_by('app_label', 'model')
|
|
|
|
field.choices = [(ct.pk, '{} > {}'.format(ct.app_label, ct.name)) for ct in queryset]
|
|
|
|
|
|
|
|
|
2018-05-30 11:19:10 -04:00
|
|
|
#
|
|
|
|
# Webhooks
|
|
|
|
#
|
|
|
|
|
|
|
|
class WebhookForm(forms.ModelForm):
|
2018-07-16 13:54:50 -04:00
|
|
|
payload_url = LaxURLField(
|
|
|
|
label='URL'
|
|
|
|
)
|
2018-05-30 11:19:10 -04:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Webhook
|
2020-02-24 16:12:46 -05:00
|
|
|
exclude = ()
|
2018-05-30 11:19:10 -04:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2018-05-30 11:19:10 -04:00
|
|
|
|
2018-12-12 09:30:31 -05:00
|
|
|
if 'obj_type' in self.fields:
|
|
|
|
order_content_types(self.fields['obj_type'])
|
2018-05-30 11:19:10 -04:00
|
|
|
|
|
|
|
|
2020-04-07 10:17:34 -04:00
|
|
|
@admin.register(Webhook)
|
2018-05-30 11:19:10 -04:00
|
|
|
class WebhookAdmin(admin.ModelAdmin):
|
|
|
|
list_display = [
|
2020-02-24 16:12:46 -05:00
|
|
|
'name', 'models', 'payload_url', 'http_content_type', 'enabled', 'type_create', 'type_update', 'type_delete',
|
|
|
|
'ssl_verification',
|
2018-05-30 11:19:10 -04:00
|
|
|
]
|
2019-11-01 12:22:39 -04:00
|
|
|
list_filter = [
|
|
|
|
'enabled', 'type_create', 'type_update', 'type_delete', 'obj_type',
|
|
|
|
]
|
2018-05-30 11:19:10 -04:00
|
|
|
form = WebhookForm
|
2020-02-24 16:12:46 -05:00
|
|
|
fieldsets = (
|
|
|
|
(None, {
|
2020-06-04 13:11:24 -04:00
|
|
|
'fields': ('name', 'obj_type', 'enabled')
|
2020-02-24 16:12:46 -05:00
|
|
|
}),
|
|
|
|
('Events', {
|
2020-06-04 13:11:24 -04:00
|
|
|
'fields': ('type_create', 'type_update', 'type_delete')
|
2020-02-24 16:12:46 -05:00
|
|
|
}),
|
|
|
|
('HTTP Request', {
|
2020-02-24 20:42:24 -05:00
|
|
|
'fields': (
|
2020-02-25 10:43:14 -05:00
|
|
|
'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret',
|
2020-06-04 13:11:24 -04:00
|
|
|
),
|
|
|
|
'classes': ('monospace',)
|
2020-02-24 16:12:46 -05:00
|
|
|
}),
|
|
|
|
('SSL', {
|
2020-06-04 13:11:24 -04:00
|
|
|
'fields': ('ssl_verification', 'ca_file_path')
|
2020-02-24 16:12:46 -05:00
|
|
|
})
|
|
|
|
)
|
2018-05-30 11:19:10 -04:00
|
|
|
|
|
|
|
def models(self, obj):
|
|
|
|
return ', '.join([ct.name for ct in obj.obj_type.all()])
|
|
|
|
|
|
|
|
|
2017-09-19 11:31:29 -04:00
|
|
|
#
|
|
|
|
# Custom fields
|
|
|
|
#
|
|
|
|
|
2016-08-15 16:58:25 -04:00
|
|
|
class CustomFieldForm(forms.ModelForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = CustomField
|
|
|
|
exclude = []
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2016-08-15 16:58:25 -04:00
|
|
|
|
2017-09-19 11:31:29 -04:00
|
|
|
order_content_types(self.fields['obj_type'])
|
2016-08-12 17:20:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
class CustomFieldChoiceAdmin(admin.TabularInline):
|
|
|
|
model = CustomFieldChoice
|
2016-08-18 14:23:28 -04:00
|
|
|
extra = 5
|
2016-08-12 17:20:01 -04:00
|
|
|
|
|
|
|
|
2020-04-07 10:17:34 -04:00
|
|
|
@admin.register(CustomField)
|
2016-08-12 17:20:01 -04:00
|
|
|
class CustomFieldAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [CustomFieldChoiceAdmin]
|
2019-11-01 12:22:39 -04:00
|
|
|
list_display = [
|
|
|
|
'name', 'models', 'type', 'required', 'filter_logic', 'default', 'weight', 'description',
|
|
|
|
]
|
|
|
|
list_filter = [
|
|
|
|
'type', 'required', 'obj_type',
|
|
|
|
]
|
2016-08-15 16:58:25 -04:00
|
|
|
form = CustomFieldForm
|
2016-08-15 15:24:23 -04:00
|
|
|
|
|
|
|
def models(self, obj):
|
|
|
|
return ', '.join([ct.name for ct in obj.obj_type.all()])
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2019-04-15 17:12:41 -04:00
|
|
|
#
|
|
|
|
# Custom links
|
|
|
|
#
|
|
|
|
|
2019-04-15 21:29:02 -04:00
|
|
|
class CustomLinkForm(forms.ModelForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = CustomLink
|
|
|
|
exclude = []
|
2019-10-09 09:40:24 -04:00
|
|
|
widgets = {
|
|
|
|
'text': forms.Textarea,
|
|
|
|
'url': forms.Textarea,
|
|
|
|
}
|
2019-04-19 14:56:40 -04:00
|
|
|
help_texts = {
|
2020-06-04 13:11:24 -04:00
|
|
|
'weight': 'A numeric weight to influence the ordering of this link among its peers. Lower weights appear '
|
|
|
|
'first in a list.',
|
2019-06-24 12:20:09 -04:00
|
|
|
'text': 'Jinja2 template code for the link text. Reference the object as <code>{{ obj }}</code>. Links '
|
|
|
|
'which render as empty text will not be displayed.',
|
2019-04-19 14:56:40 -04:00
|
|
|
'url': 'Jinja2 template code for the link URL. Reference the object as <code>{{ obj }}</code>.',
|
|
|
|
}
|
2019-04-15 21:29:02 -04:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Format ContentType choices
|
|
|
|
order_content_types(self.fields['content_type'])
|
|
|
|
self.fields['content_type'].choices.insert(0, ('', '---------'))
|
|
|
|
|
|
|
|
|
2020-04-07 10:17:34 -04:00
|
|
|
@admin.register(CustomLink)
|
2019-04-15 17:12:41 -04:00
|
|
|
class CustomLinkAdmin(admin.ModelAdmin):
|
2020-06-04 13:11:24 -04:00
|
|
|
fieldsets = (
|
|
|
|
('Custom Link', {
|
|
|
|
'fields': ('content_type', 'name', 'group_name', 'weight', 'button_class', 'new_window')
|
|
|
|
}),
|
|
|
|
('Templates', {
|
|
|
|
'fields': ('text', 'url'),
|
|
|
|
'classes': ('monospace',)
|
|
|
|
})
|
|
|
|
)
|
2019-11-01 12:22:39 -04:00
|
|
|
list_display = [
|
|
|
|
'name', 'content_type', 'group_name', 'weight',
|
|
|
|
]
|
|
|
|
list_filter = [
|
|
|
|
'content_type',
|
|
|
|
]
|
2019-04-15 21:29:02 -04:00
|
|
|
form = CustomLinkForm
|
2019-04-15 17:12:41 -04:00
|
|
|
|
|
|
|
|
2017-09-19 11:31:29 -04:00
|
|
|
#
|
|
|
|
# Graphs
|
|
|
|
#
|
|
|
|
|
2020-06-04 13:11:24 -04:00
|
|
|
class GraphForm(forms.ModelForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Graph
|
|
|
|
exclude = ()
|
|
|
|
widgets = {
|
|
|
|
'source': forms.Textarea,
|
|
|
|
'link': forms.Textarea,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-07 10:17:34 -04:00
|
|
|
@admin.register(Graph)
|
2016-03-01 11:23:03 -05:00
|
|
|
class GraphAdmin(admin.ModelAdmin):
|
2020-06-04 13:11:24 -04:00
|
|
|
fieldsets = (
|
|
|
|
('Graph', {
|
|
|
|
'fields': ('type', 'name', 'weight')
|
|
|
|
}),
|
|
|
|
('Templates', {
|
|
|
|
'fields': ('template_language', 'source', 'link'),
|
|
|
|
'classes': ('monospace',)
|
|
|
|
})
|
|
|
|
)
|
|
|
|
form = GraphForm
|
2019-11-01 12:22:39 -04:00
|
|
|
list_display = [
|
2020-01-10 11:28:50 -05:00
|
|
|
'name', 'type', 'weight', 'template_language', 'source',
|
2019-11-01 12:22:39 -04:00
|
|
|
]
|
|
|
|
list_filter = [
|
2020-01-10 11:28:50 -05:00
|
|
|
'type', 'template_language',
|
2019-11-01 12:22:39 -04:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2017-09-19 11:31:29 -04:00
|
|
|
#
|
|
|
|
# Export templates
|
|
|
|
#
|
|
|
|
|
|
|
|
class ExportTemplateForm(forms.ModelForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ExportTemplate
|
|
|
|
exclude = []
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-27 10:52:24 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
2017-09-19 11:31:29 -04:00
|
|
|
|
|
|
|
# Format ContentType choices
|
|
|
|
order_content_types(self.fields['content_type'])
|
|
|
|
self.fields['content_type'].choices.insert(0, ('', '---------'))
|
|
|
|
|
|
|
|
|
2020-04-07 10:17:34 -04:00
|
|
|
@admin.register(ExportTemplate)
|
2016-03-01 11:23:03 -05:00
|
|
|
class ExportTemplateAdmin(admin.ModelAdmin):
|
2020-06-04 13:11:24 -04:00
|
|
|
fieldsets = (
|
|
|
|
('Export Template', {
|
|
|
|
'fields': ('content_type', 'name', 'description', 'mime_type', 'file_extension')
|
|
|
|
}),
|
|
|
|
('Content', {
|
|
|
|
'fields': ('template_language', 'template_code'),
|
|
|
|
'classes': ('monospace',)
|
|
|
|
})
|
|
|
|
)
|
2019-11-01 12:22:39 -04:00
|
|
|
list_display = [
|
|
|
|
'name', 'content_type', 'description', 'mime_type', 'file_extension',
|
|
|
|
]
|
|
|
|
list_filter = [
|
|
|
|
'content_type',
|
|
|
|
]
|
2017-09-19 11:31:29 -04:00
|
|
|
form = ExportTemplateForm
|
|
|
|
|
2016-04-08 14:57:54 -04:00
|
|
|
|
2019-12-31 16:11:47 -05:00
|
|
|
#
|
|
|
|
# Reports
|
|
|
|
#
|
|
|
|
|
2020-06-29 03:50:05 -04:00
|
|
|
@admin.register(JobResult)
|
|
|
|
class JobResultAdmin(admin.ModelAdmin):
|
2019-12-31 16:11:47 -05:00
|
|
|
list_display = [
|
2020-06-29 03:50:05 -04:00
|
|
|
'obj_type', 'name', 'created', 'completed', 'user', 'status',
|
2019-12-31 16:11:47 -05:00
|
|
|
]
|
|
|
|
fields = [
|
2020-06-29 03:50:05 -04:00
|
|
|
'obj_type', 'name', 'created', 'completed', 'user', 'status', 'data', 'job_id'
|
2019-12-31 16:11:47 -05:00
|
|
|
]
|
|
|
|
list_filter = [
|
2020-06-29 03:50:05 -04:00
|
|
|
'status',
|
2019-12-31 16:11:47 -05:00
|
|
|
]
|
|
|
|
readonly_fields = fields
|
|
|
|
|
|
|
|
def has_add_permission(self, request):
|
|
|
|
return False
|