blob: 2a6d5183618f4e78960de87b843ed00621199b47 [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 Baker446eaca2014-05-23 13:16:57 -070013from core.admin import SingletonAdmin,SliceInline,ServiceAttrAsTabInline, SliceROInline,ServiceAttrAsTabROInline, ReadOnlyAwareAdmin, PlStackTabularInline, ReadOnlyTabularInline
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"
19 list_display = ("name","enabled")
20 fieldsets = [(None, {'fields': ['name','enabled','versionNumber', 'description'], 'classes':['suit-tab suit-tab-general']})]
21 inlines = [SliceInline,ServiceAttrAsTabInline]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040022
Scott Baker446eaca2014-05-23 13:16:57 -070023 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
24 user_readonly_inlines = [SliceROInline, ServiceAttrAsTabROInline]
25
26 suit_form_tabs =(('general', 'HPC Service Details'),
27 ('slices','Slices'),
28 ('serviceattrs','Additional Attributes'),
29 )
30
31class CDNPrefixInline(PlStackTabularInline):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040032 model = CDNPrefix
33 extra = 0
34 suit_classes = 'suit-tab suit-tab-prefixes'
Scott Baker2a21ba12014-06-03 12:25:40 -070035 fields = ('cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled')
36 readonly_fields = ('cdn_prefix_id',)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040037
Scott Baker446eaca2014-05-23 13:16:57 -070038class CDNPrefixROInline(ReadOnlyTabularInline):
39 model = CDNPrefix
40 extra = 0
41 suit_classes = 'suit-tab suit-tab-prefixes'
Scott Baker2a21ba12014-06-03 12:25:40 -070042 fields = ('cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled')
43 readonly_fields = ('cdn_prefix_id',)
Scott Baker446eaca2014-05-23 13:16:57 -070044
45class ContentProviderInline(PlStackTabularInline):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040046 model = ContentProvider
47 extra = 0
48 suit_classes = 'suit-tab suit-tab-cps'
Scott Baker2a21ba12014-06-03 12:25:40 -070049 fields = ('content_provider_id', 'name', 'enabled')
50 readonly_fields = ('content_provider_id',)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040051
Scott Baker446eaca2014-05-23 13:16:57 -070052class ContentProviderROInline(ReadOnlyTabularInline):
53 model = ContentProvider
54 extra = 0
55 suit_classes = 'suit-tab suit-tab-cps'
56
57class OriginServerAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040058 list_display = ('url','protocol','redirects','contentProvider','authenticated','enabled' )
59
Scott Baker2a21ba12014-06-03 12:25:40 -070060 fields = ('url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description' )
61 readonly_fields = ('origin_server_id',)
62 user_readonly_fields = ('url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description')
Scott Baker446eaca2014-05-23 13:16:57 -070063
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040064class ContentProviderForm(forms.ModelForm):
65 class Meta:
66 widgets = {
67 'serviceProvider' : LinkedSelect
68 }
69
Scott Baker446eaca2014-05-23 13:16:57 -070070class ContentProviderAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040071 form = ContentProviderForm
72 list_display = ('name','description','enabled' )
73 fieldsets = [ (None, {'fields': ['name','enabled','description','serviceProvider','users'], 'classes':['suit-tab suit-tab-general']})]
74
75 inlines = [CDNPrefixInline]
76
Scott Baker446eaca2014-05-23 13:16:57 -070077 user_readonly_fields = ('name','description','enabled','serviceProvider','users')
78 user_readonly_inlines = [CDNPrefixROInline]
79
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040080 suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes'))
81
Scott Baker446eaca2014-05-23 13:16:57 -070082class ServiceProviderAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040083 list_display = ('name', 'description', 'enabled')
84 fieldsets = [
85 (None, {'fields': ['name','description','enabled'], 'classes':['suit-tab suit-tab-general']})]
Scott Baker446eaca2014-05-23 13:16:57 -070086#, ('Content Providers', {'fields':['contentProviders'],'classes':['suit-tab suit-tab-cps']})]
87
88 user_readonly_fields = ('name', 'description', 'enabled')
89 user_readonly_inlines = [ContentProviderROInline]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040090
91 suit_form_tabs = (('general','Details'),('cps','Content Providers'))
92 inlines = [ContentProviderInline]
93
94class CDNPrefixForm(forms.ModelForm):
95 class Meta:
96 widgets = {
97 'contentProvider' : LinkedSelect
98 }
99
Scott Baker446eaca2014-05-23 13:16:57 -0700100class CDNPrefixAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400101 form = CDNPrefixForm
102 list_display = ['prefix','contentProvider']
Scott Baker2a21ba12014-06-03 12:25:40 -0700103 fields = ['prefix', 'contentProvider', 'cdn_prefix_id', 'description', 'defaultOriginServer', 'enabled']
Scott Baker446eaca2014-05-23 13:16:57 -0700104 user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400105
Scott Baker446eaca2014-05-23 13:16:57 -0700106class SiteMapAdmin(ReadOnlyAwareAdmin):
Scott Baker53491082014-03-13 23:15:19 -0700107 model = SiteMap
108 verbose_name = "Site Map"
109 verbose_name_plural = "Site Map"
110 list_display = ("name", "contentProvider", "serviceProvider")
Scott Baker446eaca2014-05-23 13:16:57 -0700111 user_readonly_fields = ("name", "contentProvider", "serviceProvider", "description", "map")
Scott Baker53491082014-03-13 23:15:19 -0700112
Scott Baker446eaca2014-05-23 13:16:57 -0700113class AccessMapAdmin(ReadOnlyAwareAdmin):
Scott Baker53491082014-03-13 23:15:19 -0700114 model = AccessMap
115 verbose_name = "Access Map"
116 verbose_name_plural = "Access Map"
117 list_display = ("name", "contentProvider")
Scott Baker446eaca2014-05-23 13:16:57 -0700118 user_readonly_fields = ("name", "contentProvider", "description", "map")
Scott Baker53491082014-03-13 23:15:19 -0700119
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400120admin.site.register(ServiceProvider, ServiceProviderAdmin)
121admin.site.register(ContentProvider, ContentProviderAdmin)
122admin.site.register(CDNPrefix, CDNPrefixAdmin)
123admin.site.register(OriginServer,OriginServerAdmin)
Scott Baker446eaca2014-05-23 13:16:57 -0700124admin.site.register(HpcService, HpcServiceAdmin)
Scott Baker53491082014-03-13 23:15:19 -0700125admin.site.register(SiteMap, SiteMapAdmin)
126admin.site.register(AccessMap, AccessMapAdmin)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400127