blob: 13c636b74a2676344f297883ffad55965bb52edc [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001from plstackapi.core.models import Site
Tony Mackf1c12242013-04-09 16:08:43 -04002from plstackapi.core.models import *
Tony Mack7130ac32013-03-22 21:58:00 -04003from django.contrib import admin
Siobhan Tully4bc09f22013-04-10 21:15:21 -04004from django import forms
Tony Mack7130ac32013-03-22 21:58:00 -04005
6from django.contrib.auth.admin import UserAdmin
Siobhan Tully4bc09f22013-04-10 21:15:21 -04007from django.contrib.admin.widgets import FilteredSelectMultiple
Tony Mack7130ac32013-03-22 21:58:00 -04008
Siobhan Tully4bc09f22013-04-10 21:15:21 -04009
10class ReadonlyTabularInline(admin.TabularInline):
11 can_delete = False
12 extra = 0
13 editable_fields = []
14
15 def get_readonly_fields(self, request, obj=None):
16 fields = []
17 for field in self.model._meta.get_all_field_names():
18 if (not field == 'id'):
19 if (field not in self.editable_fields):
20 fields.append(field)
21 return fields
22
23 def has_add_permission(self, request):
24 return False
25
26class SliverInline(admin.TabularInline):
27 model = Sliver
28 extra = 0
29
30class SiteInline(admin.TabularInline):
31 model = Site
32 extra = 0
33
34class NodeInline(admin.TabularInline):
35 model = Node
36 extra = 0
37
38class PlanetStackBaseAdmin(admin.ModelAdmin):
39 save_on_top = False
40
41class DeploymentNetworkAdminForm(forms.ModelForm):
42 sites = forms.ModelMultipleChoiceField(
43 queryset=Site.objects.all(),
44 required=False,
45 widget=FilteredSelectMultiple(
46 verbose_name=('Sites'), is_stacked=False
47 )
48 )
49 class Meta:
50 model = DeploymentNetwork
51
52 def __init__(self, *args, **kwargs):
53 super(DeploymentNetworkAdminForm, self).__init__(*args, **kwargs)
54
55 if self.instance and self.instance.pk:
56 self.fields['sites'].initial = self.instance.sites.all()
57
58 def save(self, commit=True):
59 deploymentNetwork = super(DeploymentNetworkAdminForm, self).save(commit=False)
60
61 if commit:
62 deploymentNetwork.save()
63
64 if deploymentNetwork.pk:
65 deploymentNetwork.sites = self.cleaned_data['sites']
66 self.save_m2m()
67
68 return deploymentNetwork
69
70class DeploymentNetworkAdmin(PlanetStackBaseAdmin):
71 form = DeploymentNetworkAdminForm
72 inlines = [NodeInline,]
73
74class SiteAdmin(admin.ModelAdmin):
75 fieldsets = [
76 (None, {'fields': ['name', 'site_url', 'enabled', 'is_public', 'login_base']}),
77 ('Location', {'fields': ['latitude', 'longitude']}),
78 ('Deployment Networks', {'fields': ['deployments']})
79 ]
80 list_display = ('name', 'login_base','site_url', 'enabled')
81 filter_horizontal = ('deployments',)
82 inlines = [NodeInline,]
83 search_fields = ['name']
84
Tony Mack8484bdb2013-04-14 20:26:03 -040085class UserForm(forms.ModelForm):
86 class Meta:
87 password = forms.CharField(widget=forms.PasswordInput)
88 model = User
89 widgets = {
90 'password': forms.PasswordInput(),
91 }
92class UserAdmin(admin.ModelAdmin):
93 form = UserForm
94 fieldsets = [
95 ('User', {'fields': ['firstname', 'lastname', 'email', 'password', 'phone', 'user_url', 'is_admin', 'site']})
96 ]
97 list_display = ['firstname', 'lastname', 'email', 'password', 'phone', 'user_url', 'is_admin', 'site']
98 search_fields = ['email']
99
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400100class SliceAdmin(PlanetStackBaseAdmin):
101 fields = ['name', 'site', 'instantiation', 'description', 'slice_url']
102 list_display = ('name', 'site','slice_url', 'instantiation')
103 inlines = [SliverInline]
104
105class SubnetAdmin(admin.ModelAdmin):
106 fields = ['cidr', 'ip_version', 'start', 'end', 'slice']
107
108class ImageAdmin(admin.ModelAdmin):
109 fields = ['image_id', 'name', 'disk_format', 'container_format']
110
111class NodeAdmin(admin.ModelAdmin):
112 list_display = ('name', 'site', 'deploymentNetwork')
113 list_filter = ('deploymentNetwork',)
114
Tony Mackfd24d0d2013-04-14 00:59:17 -0400115
Tony Mackfd24d0d2013-04-14 00:59:17 -0400116class RoleAdmin(admin.ModelAdmin):
Tony Mackbc9cecf2013-04-14 13:56:38 -0400117 fieldsets = [
118 ('Role', {'fields': ['role_type']})
119 ]
Tony Mackfd24d0d2013-04-14 00:59:17 -0400120 list_display = ('role_type',)
121
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400122admin.site.register(Site, SiteAdmin)
123admin.site.register(SitePrivilege)
124admin.site.register(Slice, SliceAdmin)
125admin.site.register(SliceMembership)
126admin.site.register(Subnet, SubnetAdmin)
127admin.site.register(Image, ImageAdmin)
128admin.site.register(Node, NodeAdmin)
Tony Mack7130ac32013-03-22 21:58:00 -0400129admin.site.register(Sliver)
Tony Mack5cc16ba2013-04-09 10:30:45 -0400130admin.site.register(Flavor)
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400131admin.site.register(Key)
Tony Mackfd24d0d2013-04-14 00:59:17 -0400132admin.site.register(Role, RoleAdmin)
Tony Mack8484bdb2013-04-14 20:26:03 -0400133admin.site.register(User, UserAdmin)
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400134admin.site.register(DeploymentNetwork, DeploymentNetworkAdmin)
Tony Mack7130ac32013-03-22 21:58:00 -0400135