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
|
|
|
|
|
2016-08-15 16:58:25 -04:00
|
|
|
from .models import CustomField, CustomFieldChoice, Graph, ExportTemplate, TopologyMap, UserAction
|
|
|
|
|
|
|
|
|
|
|
|
class CustomFieldForm(forms.ModelForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = CustomField
|
|
|
|
exclude = []
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(CustomFieldForm, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
# Organize the available ContentTypes
|
|
|
|
queryset = self.fields['obj_type'].queryset.order_by('app_label', 'model')
|
|
|
|
self.fields['obj_type'].choices = [(ct.pk, '{} > {}'.format(ct.app_label, ct.name)) for ct in queryset]
|
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
|
|
|
|
|
|
|
|
|
|
|
@admin.register(CustomField)
|
|
|
|
class CustomFieldAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [CustomFieldChoiceAdmin]
|
2016-08-23 16:45:26 -04:00
|
|
|
list_display = ['name', 'models', 'type', 'required', 'default', 'weight', 'description']
|
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
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Graph)
|
|
|
|
class GraphAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ['name', 'type', 'weight', 'source']
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(ExportTemplate)
|
|
|
|
class ExportTemplateAdmin(admin.ModelAdmin):
|
2016-09-27 16:31:18 -04:00
|
|
|
list_display = ['name', 'content_type', 'description', 'mime_type', 'file_extension']
|
2016-04-08 14:57:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(TopologyMap)
|
|
|
|
class TopologyMapAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ['name', 'slug', 'site']
|
|
|
|
prepopulated_fields = {
|
|
|
|
'slug': ['name'],
|
|
|
|
}
|
2016-08-06 15:35:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(UserAction)
|
|
|
|
class UserActionAdmin(admin.ModelAdmin):
|
|
|
|
actions = None
|
|
|
|
list_display = ['user', 'action', 'content_type', 'object_id', 'message']
|