blob: ee9e42b9efcee1241b644053a83ffe4c0a55ae6d [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'
35
Scott Baker446eaca2014-05-23 13:16:57 -070036class CDNPrefixROInline(ReadOnlyTabularInline):
37 model = CDNPrefix
38 extra = 0
39 suit_classes = 'suit-tab suit-tab-prefixes'
40
41class ContentProviderInline(PlStackTabularInline):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040042 model = ContentProvider
43 extra = 0
44 suit_classes = 'suit-tab suit-tab-cps'
45
Scott Baker446eaca2014-05-23 13:16:57 -070046class ContentProviderROInline(ReadOnlyTabularInline):
47 model = ContentProvider
48 extra = 0
49 suit_classes = 'suit-tab suit-tab-cps'
50
51class OriginServerAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040052 list_display = ('url','protocol','redirects','contentProvider','authenticated','enabled' )
53
Scott Baker446eaca2014-05-23 13:16:57 -070054 user_readonly_fields = ('url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description','redirects','authenticated' )
55
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040056class ContentProviderForm(forms.ModelForm):
57 class Meta:
58 widgets = {
59 'serviceProvider' : LinkedSelect
60 }
61
Scott Baker446eaca2014-05-23 13:16:57 -070062class ContentProviderAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040063 form = ContentProviderForm
64 list_display = ('name','description','enabled' )
65 fieldsets = [ (None, {'fields': ['name','enabled','description','serviceProvider','users'], 'classes':['suit-tab suit-tab-general']})]
66
67 inlines = [CDNPrefixInline]
68
Scott Baker446eaca2014-05-23 13:16:57 -070069 user_readonly_fields = ('name','description','enabled','serviceProvider','users')
70 user_readonly_inlines = [CDNPrefixROInline]
71
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040072 suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes'))
73
Scott Baker446eaca2014-05-23 13:16:57 -070074class ServiceProviderAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040075 list_display = ('name', 'description', 'enabled')
76 fieldsets = [
77 (None, {'fields': ['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
80 user_readonly_fields = ('name', 'description', 'enabled')
81 user_readonly_inlines = [ContentProviderROInline]
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
94 list_display = ['prefix','contentProvider']
Scott Baker446eaca2014-05-23 13:16:57 -070095 user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040096
Scott Baker446eaca2014-05-23 13:16:57 -070097class SiteMapAdmin(ReadOnlyAwareAdmin):
Scott Baker53491082014-03-13 23:15:19 -070098 model = SiteMap
99 verbose_name = "Site Map"
100 verbose_name_plural = "Site Map"
101 list_display = ("name", "contentProvider", "serviceProvider")
Scott Baker446eaca2014-05-23 13:16:57 -0700102 user_readonly_fields = ("name", "contentProvider", "serviceProvider", "description", "map")
Scott Baker53491082014-03-13 23:15:19 -0700103
Scott Baker446eaca2014-05-23 13:16:57 -0700104class AccessMapAdmin(ReadOnlyAwareAdmin):
Scott Baker53491082014-03-13 23:15:19 -0700105 model = AccessMap
106 verbose_name = "Access Map"
107 verbose_name_plural = "Access Map"
108 list_display = ("name", "contentProvider")
Scott Baker446eaca2014-05-23 13:16:57 -0700109 user_readonly_fields = ("name", "contentProvider", "description", "map")
Scott Baker53491082014-03-13 23:15:19 -0700110
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400111admin.site.register(ServiceProvider, ServiceProviderAdmin)
112admin.site.register(ContentProvider, ContentProviderAdmin)
113admin.site.register(CDNPrefix, CDNPrefixAdmin)
114admin.site.register(OriginServer,OriginServerAdmin)
Scott Baker446eaca2014-05-23 13:16:57 -0700115admin.site.register(HpcService, HpcServiceAdmin)
Scott Baker53491082014-03-13 23:15:19 -0700116admin.site.register(SiteMap, SiteMapAdmin)
117admin.site.register(AccessMap, AccessMapAdmin)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400118