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 | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 13 | from core.admin import SingletonAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, PlStackTabularInline |
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"] |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 24 | |
| 25 | suit_form_tabs =(('general', 'HPC Service Details'), |
| 26 | ('slices','Slices'), |
| 27 | ('serviceattrs','Additional Attributes'), |
| 28 | ) |
| 29 | |
| 30 | class CDNPrefixInline(PlStackTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 31 | model = CDNPrefix |
| 32 | extra = 0 |
| 33 | suit_classes = 'suit-tab suit-tab-prefixes' |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 34 | fields = ('cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled') |
| 35 | readonly_fields = ('cdn_prefix_id',) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 36 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 37 | class ContentProviderInline(PlStackTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 38 | model = ContentProvider |
| 39 | extra = 0 |
| 40 | suit_classes = 'suit-tab suit-tab-cps' |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 41 | fields = ('content_provider_id', 'name', 'enabled') |
| 42 | readonly_fields = ('content_provider_id',) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 43 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 44 | class OriginServerAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 45 | list_display = ('url','protocol','redirects','contentProvider','authenticated','enabled' ) |
| 46 | |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 47 | 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 Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 50 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 51 | class ContentProviderForm(forms.ModelForm): |
| 52 | class Meta: |
| 53 | widgets = { |
| 54 | 'serviceProvider' : LinkedSelect |
| 55 | } |
| 56 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 57 | class ContentProviderAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 58 | 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 Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 64 | user_readonly_fields = ('name','description','enabled','serviceProvider','users') |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 65 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 66 | suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes')) |
| 67 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 68 | class ServiceProviderAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 69 | list_display = ('name', 'description', 'enabled') |
| 70 | fieldsets = [ |
| 71 | (None, {'fields': ['name','description','enabled'], 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 72 | #, ('Content Providers', {'fields':['contentProviders'],'classes':['suit-tab suit-tab-cps']})] |
| 73 | |
| 74 | user_readonly_fields = ('name', 'description', 'enabled') |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 75 | |
| 76 | suit_form_tabs = (('general','Details'),('cps','Content Providers')) |
| 77 | inlines = [ContentProviderInline] |
| 78 | |
| 79 | class CDNPrefixForm(forms.ModelForm): |
| 80 | class Meta: |
| 81 | widgets = { |
| 82 | 'contentProvider' : LinkedSelect |
| 83 | } |
| 84 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 85 | class CDNPrefixAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 86 | form = CDNPrefixForm |
| 87 | list_display = ['prefix','contentProvider'] |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 88 | fields = ['prefix', 'contentProvider', 'cdn_prefix_id', 'description', 'defaultOriginServer', 'enabled'] |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 89 | user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 90 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 91 | class SiteMapAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 92 | model = SiteMap |
| 93 | verbose_name = "Site Map" |
| 94 | verbose_name_plural = "Site Map" |
| 95 | list_display = ("name", "contentProvider", "serviceProvider") |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 96 | user_readonly_fields = ("name", "contentProvider", "serviceProvider", "description", "map") |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 97 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 98 | class AccessMapAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 99 | model = AccessMap |
| 100 | verbose_name = "Access Map" |
| 101 | verbose_name_plural = "Access Map" |
| 102 | list_display = ("name", "contentProvider") |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 103 | user_readonly_fields = ("name", "contentProvider", "description", "map") |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 104 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 105 | admin.site.register(ServiceProvider, ServiceProviderAdmin) |
| 106 | admin.site.register(ContentProvider, ContentProviderAdmin) |
| 107 | admin.site.register(CDNPrefix, CDNPrefixAdmin) |
| 108 | admin.site.register(OriginServer,OriginServerAdmin) |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 109 | admin.site.register(HpcService, HpcServiceAdmin) |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 110 | admin.site.register(SiteMap, SiteMapAdmin) |
| 111 | admin.site.register(AccessMap, AccessMapAdmin) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 112 | |