Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
| 3 | from hpc.models import * |
| 4 | from django import forms |
| 5 | from django.utils.safestring import mark_safe |
| 6 | from django.contrib.auth.admin import UserAdmin |
| 7 | from django.contrib.admin.widgets import FilteredSelectMultiple |
| 8 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
| 9 | from django.contrib.auth.signals import user_logged_in |
| 10 | from django.utils import timezone |
| 11 | from django.contrib.contenttypes import generic |
| 12 | from suit.widgets import LinkedSelect |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 13 | from core.admin import SingletonAdmin,SliceInline,ServiceAttrAsTabInline, SliceROInline,ServiceAttrAsTabROInline, ReadOnlyAwareAdmin, PlStackTabularInline, ReadOnlyTabularInline |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 14 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 15 | class 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 Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 22 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 23 | 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 | |
| 31 | class CDNPrefixInline(PlStackTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 32 | model = CDNPrefix |
| 33 | extra = 0 |
| 34 | suit_classes = 'suit-tab suit-tab-prefixes' |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 35 | fields = ('cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled') |
| 36 | readonly_fields = ('cdn_prefix_id',) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 37 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 38 | class CDNPrefixROInline(ReadOnlyTabularInline): |
| 39 | model = CDNPrefix |
| 40 | extra = 0 |
| 41 | suit_classes = 'suit-tab suit-tab-prefixes' |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 42 | fields = ('cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled') |
| 43 | readonly_fields = ('cdn_prefix_id',) |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 44 | |
| 45 | class ContentProviderInline(PlStackTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 46 | model = ContentProvider |
| 47 | extra = 0 |
| 48 | suit_classes = 'suit-tab suit-tab-cps' |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 49 | fields = ('content_provider_id', 'name', 'enabled') |
| 50 | readonly_fields = ('content_provider_id',) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 51 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 52 | class ContentProviderROInline(ReadOnlyTabularInline): |
| 53 | model = ContentProvider |
| 54 | extra = 0 |
| 55 | suit_classes = 'suit-tab suit-tab-cps' |
| 56 | |
| 57 | class OriginServerAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 58 | list_display = ('url','protocol','redirects','contentProvider','authenticated','enabled' ) |
| 59 | |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 60 | 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 Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 63 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 64 | class ContentProviderForm(forms.ModelForm): |
| 65 | class Meta: |
| 66 | widgets = { |
| 67 | 'serviceProvider' : LinkedSelect |
| 68 | } |
| 69 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 70 | class ContentProviderAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 71 | 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 Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 77 | user_readonly_fields = ('name','description','enabled','serviceProvider','users') |
| 78 | user_readonly_inlines = [CDNPrefixROInline] |
| 79 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 80 | suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes')) |
| 81 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 82 | class ServiceProviderAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 83 | list_display = ('name', 'description', 'enabled') |
| 84 | fieldsets = [ |
| 85 | (None, {'fields': ['name','description','enabled'], 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 86 | #, ('Content Providers', {'fields':['contentProviders'],'classes':['suit-tab suit-tab-cps']})] |
| 87 | |
| 88 | user_readonly_fields = ('name', 'description', 'enabled') |
| 89 | user_readonly_inlines = [ContentProviderROInline] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 90 | |
| 91 | suit_form_tabs = (('general','Details'),('cps','Content Providers')) |
| 92 | inlines = [ContentProviderInline] |
| 93 | |
| 94 | class CDNPrefixForm(forms.ModelForm): |
| 95 | class Meta: |
| 96 | widgets = { |
| 97 | 'contentProvider' : LinkedSelect |
| 98 | } |
| 99 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 100 | class CDNPrefixAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 101 | form = CDNPrefixForm |
| 102 | list_display = ['prefix','contentProvider'] |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 103 | fields = ['prefix', 'contentProvider', 'cdn_prefix_id', 'description', 'defaultOriginServer', 'enabled'] |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 104 | user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 105 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 106 | class SiteMapAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 107 | model = SiteMap |
| 108 | verbose_name = "Site Map" |
| 109 | verbose_name_plural = "Site Map" |
| 110 | list_display = ("name", "contentProvider", "serviceProvider") |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 111 | user_readonly_fields = ("name", "contentProvider", "serviceProvider", "description", "map") |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 112 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 113 | class AccessMapAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 114 | model = AccessMap |
| 115 | verbose_name = "Access Map" |
| 116 | verbose_name_plural = "Access Map" |
| 117 | list_display = ("name", "contentProvider") |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 118 | user_readonly_fields = ("name", "contentProvider", "description", "map") |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 119 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 120 | admin.site.register(ServiceProvider, ServiceProviderAdmin) |
| 121 | admin.site.register(ContentProvider, ContentProviderAdmin) |
| 122 | admin.site.register(CDNPrefix, CDNPrefixAdmin) |
| 123 | admin.site.register(OriginServer,OriginServerAdmin) |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 124 | admin.site.register(HpcService, HpcServiceAdmin) |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 125 | admin.site.register(SiteMap, SiteMapAdmin) |
| 126 | admin.site.register(AccessMap, AccessMapAdmin) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 127 | |