blob: 9e6c84e8c35a971190f2825c0379ea99aaf43a63 [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"
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"]
Scott Baker446eaca2014-05-23 13:16:57 -070024
25 suit_form_tabs =(('general', 'HPC Service Details'),
26 ('slices','Slices'),
27 ('serviceattrs','Additional Attributes'),
28 )
29
30class CDNPrefixInline(PlStackTabularInline):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040031 model = CDNPrefix
32 extra = 0
33 suit_classes = 'suit-tab suit-tab-prefixes'
Scott Baker2a21ba12014-06-03 12:25:40 -070034 fields = ('cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled')
35 readonly_fields = ('cdn_prefix_id',)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040036
Scott Baker446eaca2014-05-23 13:16:57 -070037class ContentProviderInline(PlStackTabularInline):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040038 model = ContentProvider
39 extra = 0
40 suit_classes = 'suit-tab suit-tab-cps'
Scott Baker2a21ba12014-06-03 12:25:40 -070041 fields = ('content_provider_id', 'name', 'enabled')
42 readonly_fields = ('content_provider_id',)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040043
Scott Baker446eaca2014-05-23 13:16:57 -070044class OriginServerAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040045 list_display = ('url','protocol','redirects','contentProvider','authenticated','enabled' )
46
Scott Baker2a21ba12014-06-03 12:25:40 -070047 fields = ('url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description' )
48 readonly_fields = ('origin_server_id',)
49 user_readonly_fields = ('url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description')
Scott Baker446eaca2014-05-23 13:16:57 -070050
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040051class ContentProviderForm(forms.ModelForm):
52 class Meta:
53 widgets = {
54 'serviceProvider' : LinkedSelect
55 }
56
Scott Baker446eaca2014-05-23 13:16:57 -070057class ContentProviderAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040058 form = ContentProviderForm
59 list_display = ('name','description','enabled' )
60 fieldsets = [ (None, {'fields': ['name','enabled','description','serviceProvider','users'], 'classes':['suit-tab suit-tab-general']})]
61
62 inlines = [CDNPrefixInline]
63
Scott Baker446eaca2014-05-23 13:16:57 -070064 user_readonly_fields = ('name','description','enabled','serviceProvider','users')
Scott Baker446eaca2014-05-23 13:16:57 -070065
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040066 suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes'))
67
Scott Baker446eaca2014-05-23 13:16:57 -070068class ServiceProviderAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040069 list_display = ('name', 'description', 'enabled')
70 fieldsets = [
71 (None, {'fields': ['name','description','enabled'], 'classes':['suit-tab suit-tab-general']})]
Scott Baker446eaca2014-05-23 13:16:57 -070072#, ('Content Providers', {'fields':['contentProviders'],'classes':['suit-tab suit-tab-cps']})]
73
74 user_readonly_fields = ('name', 'description', 'enabled')
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040075
76 suit_form_tabs = (('general','Details'),('cps','Content Providers'))
77 inlines = [ContentProviderInline]
78
79class CDNPrefixForm(forms.ModelForm):
80 class Meta:
81 widgets = {
82 'contentProvider' : LinkedSelect
83 }
84
Scott Baker446eaca2014-05-23 13:16:57 -070085class CDNPrefixAdmin(ReadOnlyAwareAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040086 form = CDNPrefixForm
87 list_display = ['prefix','contentProvider']
Scott Baker2a21ba12014-06-03 12:25:40 -070088 fields = ['prefix', 'contentProvider', 'cdn_prefix_id', 'description', 'defaultOriginServer', 'enabled']
Scott Baker446eaca2014-05-23 13:16:57 -070089 user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040090
Scott Baker446eaca2014-05-23 13:16:57 -070091class SiteMapAdmin(ReadOnlyAwareAdmin):
Scott Baker53491082014-03-13 23:15:19 -070092 model = SiteMap
93 verbose_name = "Site Map"
94 verbose_name_plural = "Site Map"
95 list_display = ("name", "contentProvider", "serviceProvider")
Scott Baker446eaca2014-05-23 13:16:57 -070096 user_readonly_fields = ("name", "contentProvider", "serviceProvider", "description", "map")
Scott Baker53491082014-03-13 23:15:19 -070097
Scott Baker446eaca2014-05-23 13:16:57 -070098class AccessMapAdmin(ReadOnlyAwareAdmin):
Scott Baker53491082014-03-13 23:15:19 -070099 model = AccessMap
100 verbose_name = "Access Map"
101 verbose_name_plural = "Access Map"
102 list_display = ("name", "contentProvider")
Scott Baker446eaca2014-05-23 13:16:57 -0700103 user_readonly_fields = ("name", "contentProvider", "description", "map")
Scott Baker53491082014-03-13 23:15:19 -0700104
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400105admin.site.register(ServiceProvider, ServiceProviderAdmin)
106admin.site.register(ContentProvider, ContentProviderAdmin)
107admin.site.register(CDNPrefix, CDNPrefixAdmin)
108admin.site.register(OriginServer,OriginServerAdmin)
Scott Baker446eaca2014-05-23 13:16:57 -0700109admin.site.register(HpcService, HpcServiceAdmin)
Scott Baker53491082014-03-13 23:15:19 -0700110admin.site.register(SiteMap, SiteMapAdmin)
111admin.site.register(AccessMap, AccessMapAdmin)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400112