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 | 67db95f | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 13 | from core.admin import SingletonAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline |
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" |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 19 | list_display = ("backend_status_icon", "name","enabled") |
| 20 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 21 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description'], 'classes':['suit-tab suit-tab-general']})] |
| 22 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 23 | inlines = [SliceInline,ServiceAttrAsTabInline] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 24 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 25 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 26 | |
| 27 | suit_form_tabs =(('general', 'HPC Service Details'), |
| 28 | ('slices','Slices'), |
| 29 | ('serviceattrs','Additional Attributes'), |
| 30 | ) |
| 31 | |
Scott Baker | 67db95f | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 32 | class CDNPrefixInline(XOSTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 33 | model = CDNPrefix |
| 34 | extra = 0 |
| 35 | suit_classes = 'suit-tab suit-tab-prefixes' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 36 | fields = ('backend_status_icon', 'cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled') |
| 37 | readonly_fields = ('backend_status_icon', 'cdn_prefix_id',) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 38 | |
Scott Baker | 67db95f | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 39 | class ContentProviderInline(XOSTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 40 | model = ContentProvider |
| 41 | extra = 0 |
| 42 | suit_classes = 'suit-tab suit-tab-cps' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 43 | fields = ('backend_status_icon', 'content_provider_id', 'name', 'enabled') |
| 44 | readonly_fields = ('backend_status_icon', 'content_provider_id',) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 45 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 46 | class OriginServerAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 47 | list_display = ('backend_status_icon', 'url','protocol','redirects','contentProvider','authenticated','enabled' ) |
| 48 | list_display_links = ('backend_status_icon', 'url', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 49 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 50 | fields = ('backend_status_text', 'url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description' ) |
| 51 | readonly_fields = ('backend_status_text', 'origin_server_id',) |
Scott Baker | 2a21ba1 | 2014-06-03 12:25:40 -0700 | [diff] [blame] | 52 | 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] | 53 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 54 | class ContentProviderForm(forms.ModelForm): |
| 55 | class Meta: |
| 56 | widgets = { |
| 57 | 'serviceProvider' : LinkedSelect |
| 58 | } |
| 59 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 60 | class ContentProviderAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 61 | form = ContentProviderForm |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 62 | list_display = ('backend_status_icon', 'name','description','enabled' ) |
| 63 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 64 | fieldsets = [ (None, {'fields': ['backend_status_text', 'name','enabled','description','serviceProvider','users'], 'classes':['suit-tab suit-tab-general']})] |
| 65 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 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') |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 70 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 71 | suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes')) |
| 72 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 73 | class ServiceProviderAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 74 | list_display = ('backend_status_icon', 'name', 'description', 'enabled') |
| 75 | list_display_links = ('backend_status_icon', 'name', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 76 | fieldsets = [ |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 77 | (None, {'fields': ['backend_status_text', '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 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 80 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 81 | user_readonly_fields = ('name', 'description', 'enabled') |
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 |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 94 | list_display = ['backend_status_icon', 'prefix','contentProvider'] |
| 95 | list_display_links = ('backend_status_icon', 'prefix', ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 96 | fields = ['backend_status_text', 'prefix', 'contentProvider', 'cdn_prefix_id', 'description', 'defaultOriginServer', 'enabled'] |
| 97 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 98 | user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 99 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 100 | class SiteMapAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 101 | model = SiteMap |
| 102 | verbose_name = "Site Map" |
| 103 | verbose_name_plural = "Site Map" |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 104 | list_display = ("backend_status_icon", "name", "contentProvider", "serviceProvider") |
| 105 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 106 | user_readonly_fields = ('backend_status_text', "name", "contentProvider", "serviceProvider", "description", "map") |
| 107 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 108 | |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 109 | class AccessMapAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 110 | model = AccessMap |
| 111 | verbose_name = "Access Map" |
| 112 | verbose_name_plural = "Access Map" |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 113 | list_display = ("backend_status_icon", "name", "contentProvider") |
| 114 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 115 | user_readonly_fields = ('backend_status_text', "name", "contentProvider", "description", "map") |
| 116 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 117 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 118 | admin.site.register(ServiceProvider, ServiceProviderAdmin) |
| 119 | admin.site.register(ContentProvider, ContentProviderAdmin) |
| 120 | admin.site.register(CDNPrefix, CDNPrefixAdmin) |
| 121 | admin.site.register(OriginServer,OriginServerAdmin) |
Scott Baker | 446eaca | 2014-05-23 13:16:57 -0700 | [diff] [blame] | 122 | admin.site.register(HpcService, HpcServiceAdmin) |
Scott Baker | 5349108 | 2014-03-13 23:15:19 -0700 | [diff] [blame] | 123 | admin.site.register(SiteMap, SiteMapAdmin) |
| 124 | admin.site.register(AccessMap, AccessMapAdmin) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 125 | |