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' |
| 35 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 36 | class CDNPrefixROInline(ReadOnlyTabularInline): |
| 37 | model = CDNPrefix |
| 38 | extra = 0 |
| 39 | suit_classes = 'suit-tab suit-tab-prefixes' |
| 40 | |
| 41 | class ContentProviderInline(PlStackTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 42 | model = ContentProvider |
| 43 | extra = 0 |
| 44 | suit_classes = 'suit-tab suit-tab-cps' |
| 45 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 46 | class ContentProviderROInline(ReadOnlyTabularInline): |
| 47 | model = ContentProvider |
| 48 | extra = 0 |
| 49 | suit_classes = 'suit-tab suit-tab-cps' |
| 50 | |
| 51 | class OriginServerAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 52 | list_display = ('url','protocol','redirects','contentProvider','authenticated','enabled' ) |
| 53 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 54 | user_readonly_fields = ('url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description','redirects','authenticated' ) |
| 55 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 56 | class ContentProviderForm(forms.ModelForm): |
| 57 | class Meta: |
| 58 | widgets = { |
| 59 | 'serviceProvider' : LinkedSelect |
| 60 | } |
| 61 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 62 | class ContentProviderAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 63 | 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 Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 69 | user_readonly_fields = ('name','description','enabled','serviceProvider','users') |
| 70 | user_readonly_inlines = [CDNPrefixROInline] |
| 71 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 72 | suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes')) |
| 73 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 74 | class ServiceProviderAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 75 | list_display = ('name', 'description', 'enabled') |
| 76 | fieldsets = [ |
| 77 | (None, {'fields': ['name','description','enabled'], 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 78 | #, ('Content Providers', {'fields':['contentProviders'],'classes':['suit-tab suit-tab-cps']})] |
| 79 | |
| 80 | user_readonly_fields = ('name', 'description', 'enabled') |
| 81 | user_readonly_inlines = [ContentProviderROInline] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 82 | |
| 83 | suit_form_tabs = (('general','Details'),('cps','Content Providers')) |
| 84 | inlines = [ContentProviderInline] |
| 85 | |
| 86 | class CDNPrefixForm(forms.ModelForm): |
| 87 | class Meta: |
| 88 | widgets = { |
| 89 | 'contentProvider' : LinkedSelect |
| 90 | } |
| 91 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 92 | class CDNPrefixAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 93 | form = CDNPrefixForm |
| 94 | list_display = ['prefix','contentProvider'] |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 95 | user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 96 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 97 | class SiteMapAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 98 | model = SiteMap |
| 99 | verbose_name = "Site Map" |
| 100 | verbose_name_plural = "Site Map" |
| 101 | list_display = ("name", "contentProvider", "serviceProvider") |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 102 | user_readonly_fields = ("name", "contentProvider", "serviceProvider", "description", "map") |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 103 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 104 | class AccessMapAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 105 | model = AccessMap |
| 106 | verbose_name = "Access Map" |
| 107 | verbose_name_plural = "Access Map" |
| 108 | list_display = ("name", "contentProvider") |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 109 | user_readonly_fields = ("name", "contentProvider", "description", "map") |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 110 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 111 | admin.site.register(ServiceProvider, ServiceProviderAdmin) |
| 112 | admin.site.register(ContentProvider, ContentProviderAdmin) |
| 113 | admin.site.register(CDNPrefix, CDNPrefixAdmin) |
| 114 | admin.site.register(OriginServer,OriginServerAdmin) |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 115 | admin.site.register(HpcService, HpcServiceAdmin) |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 116 | admin.site.register(SiteMap, SiteMapAdmin) |
| 117 | admin.site.register(AccessMap, AccessMapAdmin) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 118 | |