blob: 1f4e75995379d1f840f5d04b4107f76535abe2af [file] [log] [blame]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001from django.contrib import admin
2
3from hpc.models import *
4from django import forms
5from django.utils.safestring import mark_safe
6from django.contrib.auth.admin import UserAdmin
7from django.contrib.admin.widgets import FilteredSelectMultiple
8from django.contrib.auth.forms import ReadOnlyPasswordHashField
9from django.contrib.auth.signals import user_logged_in
10from django.utils import timezone
11from django.contrib.contenttypes import generic
12from suit.widgets import LinkedSelect
Scott Bakerb27b62c2014-08-15 16:29:16 -070013from core.admin import SingletonAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, PlStackTabularInline
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040014
Scott Baker446eaca2014-05-23 13:16:57 -070015class HpcServiceAdmin(SingletonAdmin):
16 model = HpcService
17 verbose_name = "HPC Service"
18 verbose_name_plural = "HPC Service"
Scott Baker63d1a552014-08-21 15:19:07 -070019 list_display = ("backend_status_icon", "name","enabled")
20 list_display_links = ('backend_status_icon', 'name', )
Scott Baker40c00762014-08-21 16:55:59 -070021 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description'], 'classes':['suit-tab suit-tab-general']})]
22 readonly_fields = ('backend_status_text', )
Scott Baker446eaca2014-05-23 13:16:57 -070023 inlines = [SliceInline,ServiceAttrAsTabInline]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040024
Scott Baker446eaca2014-05-23 13:16:57 -070025 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
Scott Baker446eaca2014-05-23 13:16:57 -070026
27 suit_form_tabs =(('general', 'HPC Service Details'),
28 ('slices','Slices'),
29 ('serviceattrs','Additional Attributes'),
30 )
31
32class CDNPrefixInline(PlStackTabularInline):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040033 model = CDNPrefix
34 extra = 0
35 suit_classes = 'suit-tab suit-tab-prefixes'
Scott Baker40c00762014-08-21 16:55:59 -070036 fields = ('backend_status_icon', 'cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled')
37 readonly_fields = ('backend_status_icon', 'cdn_prefix_id',)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040038
Scott Baker446eaca2014-05-23 13:16:57 -070039class ContentProviderInline(PlStackTabularInline):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040040 model = ContentProvider
41 extra = 0
42 suit_classes = 'suit-tab suit-tab-cps'
Scott Baker40c00762014-08-21 16:55:59 -070043 fields = ('backend_status_icon', 'content_provider_id', 'name', 'enabled')
44 readonly_fields = ('backend_status_icon', 'content_provider_id',)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040045
Scott Baker446eaca2014-05-23 13:16:57 -070046class OriginServerAdmin(ReadOnlyAwareAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -070047 list_display = ('backend_status_icon', 'url','protocol','redirects','contentProvider','authenticated','enabled' )
48 list_display_links = ('backend_status_icon', 'url', )
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040049
Scott Baker40c00762014-08-21 16:55:59 -070050 fields = ('backend_status_text', 'url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description' )
51 readonly_fields = ('backend_status_text', 'origin_server_id',)
Scott Baker2a21ba12014-06-03 12:25:40 -070052 user_readonly_fields = ('url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description')
Scott Baker446eaca2014-05-23 13:16:57 -070053
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040054class ContentProviderForm(forms.ModelForm):
55 class Meta:
56 widgets = {
57 'serviceProvider' : LinkedSelect
58 }
59
Scott Baker446eaca2014-05-23 13:16:57 -070060class ContentProviderAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040061 form = ContentProviderForm
Scott Baker63d1a552014-08-21 15:19:07 -070062 list_display = ('backend_status_icon', 'name','description','enabled' )
63 list_display_links = ('backend_status_icon', 'name', )
Scott Baker40c00762014-08-21 16:55:59 -070064 fieldsets = [ (None, {'fields': ['backend_status_text', 'name','enabled','description','serviceProvider','users'], 'classes':['suit-tab suit-tab-general']})]
65 readonly_fields = ('backend_status_text', )
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040066
67 inlines = [CDNPrefixInline]
68
Scott Baker446eaca2014-05-23 13:16:57 -070069 user_readonly_fields = ('name','description','enabled','serviceProvider','users')
Scott Baker446eaca2014-05-23 13:16:57 -070070
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040071 suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes'))
72
Scott Baker446eaca2014-05-23 13:16:57 -070073class ServiceProviderAdmin(ReadOnlyAwareAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -070074 list_display = ('backend_status_icon', 'name', 'description', 'enabled')
75 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040076 fieldsets = [
Scott Baker40c00762014-08-21 16:55:59 -070077 (None, {'fields': ['backend_status_text', 'name','description','enabled'], 'classes':['suit-tab suit-tab-general']})]
Scott Baker446eaca2014-05-23 13:16:57 -070078#, ('Content Providers', {'fields':['contentProviders'],'classes':['suit-tab suit-tab-cps']})]
79
Scott Baker40c00762014-08-21 16:55:59 -070080 readonly_fields = ('backend_status_text', )
Scott Baker446eaca2014-05-23 13:16:57 -070081 user_readonly_fields = ('name', 'description', 'enabled')
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040082
83 suit_form_tabs = (('general','Details'),('cps','Content Providers'))
84 inlines = [ContentProviderInline]
85
86class CDNPrefixForm(forms.ModelForm):
87 class Meta:
88 widgets = {
89 'contentProvider' : LinkedSelect
90 }
91
Scott Baker446eaca2014-05-23 13:16:57 -070092class CDNPrefixAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040093 form = CDNPrefixForm
Scott Baker63d1a552014-08-21 15:19:07 -070094 list_display = ['backend_status_icon', 'prefix','contentProvider']
95 list_display_links = ('backend_status_icon', 'prefix', )
Scott Baker40c00762014-08-21 16:55:59 -070096 fields = ['backend_status_text', 'prefix', 'contentProvider', 'cdn_prefix_id', 'description', 'defaultOriginServer', 'enabled']
97 readonly_fields = ('backend_status_text', )
Scott Baker446eaca2014-05-23 13:16:57 -070098 user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040099
Scott Baker446eaca2014-05-23 13:16:57 -0700100class SiteMapAdmin(ReadOnlyAwareAdmin):
Scott Baker53491082014-03-13 23:15:19 -0700101 model = SiteMap
102 verbose_name = "Site Map"
103 verbose_name_plural = "Site Map"
Scott Baker63d1a552014-08-21 15:19:07 -0700104 list_display = ("backend_status_icon", "name", "contentProvider", "serviceProvider")
105 list_display_links = ('backend_status_icon', 'name', )
Scott Baker40c00762014-08-21 16:55:59 -0700106 user_readonly_fields = ('backend_status_text', "name", "contentProvider", "serviceProvider", "description", "map")
107 readonly_fields = ('backend_status_text', )
Scott Baker53491082014-03-13 23:15:19 -0700108
Scott Baker446eaca2014-05-23 13:16:57 -0700109class AccessMapAdmin(ReadOnlyAwareAdmin):
Scott Baker53491082014-03-13 23:15:19 -0700110 model = AccessMap
111 verbose_name = "Access Map"
112 verbose_name_plural = "Access Map"
Scott Baker63d1a552014-08-21 15:19:07 -0700113 list_display = ("backend_status_icon", "name", "contentProvider")
114 list_display_links = ('backend_status_icon', 'name', )
Scott Baker40c00762014-08-21 16:55:59 -0700115 user_readonly_fields = ('backend_status_text', "name", "contentProvider", "description", "map")
116 readonly_fields = ('backend_status_text', )
Scott Baker53491082014-03-13 23:15:19 -0700117
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400118admin.site.register(ServiceProvider, ServiceProviderAdmin)
119admin.site.register(ContentProvider, ContentProviderAdmin)
120admin.site.register(CDNPrefix, CDNPrefixAdmin)
121admin.site.register(OriginServer,OriginServerAdmin)
Scott Baker446eaca2014-05-23 13:16:57 -0700122admin.site.register(HpcService, HpcServiceAdmin)
Scott Baker53491082014-03-13 23:15:19 -0700123admin.site.register(SiteMap, SiteMapAdmin)
124admin.site.register(AccessMap, AccessMapAdmin)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400125