Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | from plstackapi.core.models import Site |
Tony Mack | f1c1224 | 2013-04-09 16:08:43 -0400 | [diff] [blame] | 2 | from plstackapi.core.models import * |
Tony Mack | e59a7c8 | 2013-04-27 11:08:10 -0400 | [diff] [blame] | 3 | from plstackapi.openstack.driver import OpenStackDriver |
| 4 | from plstackapi.openstack.client import OpenStackClient |
| 5 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 6 | from django.contrib import admin |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 7 | from django.contrib.auth.models import Group |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 8 | from django import forms |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 9 | from django.utils.safestring import mark_safe |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 10 | from django.contrib.auth.admin import UserAdmin |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 11 | from django.contrib.admin.widgets import FilteredSelectMultiple |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 12 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
Tony Mack | 31c2b8f | 2013-04-26 20:01:42 -0400 | [diff] [blame] | 13 | from django.contrib.auth.signals import user_logged_in |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 14 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 15 | |
| 16 | class ReadonlyTabularInline(admin.TabularInline): |
| 17 | can_delete = False |
| 18 | extra = 0 |
| 19 | editable_fields = [] |
| 20 | |
| 21 | def get_readonly_fields(self, request, obj=None): |
| 22 | fields = [] |
| 23 | for field in self.model._meta.get_all_field_names(): |
| 24 | if (not field == 'id'): |
| 25 | if (field not in self.editable_fields): |
| 26 | fields.append(field) |
| 27 | return fields |
| 28 | |
| 29 | def has_add_permission(self, request): |
| 30 | return False |
| 31 | |
| 32 | class SliverInline(admin.TabularInline): |
| 33 | model = Sliver |
Tony Mack | ab05c3b | 2013-04-30 18:30:21 -0400 | [diff] [blame] | 34 | fields = ['ip', 'name', 'slice', 'image', 'key', 'node', 'deploymentNetwork'] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 35 | extra = 0 |
| 36 | |
| 37 | class SiteInline(admin.TabularInline): |
| 38 | model = Site |
| 39 | extra = 0 |
| 40 | |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 41 | class SliceInline(admin.TabularInline): |
| 42 | model = Slice |
| 43 | extra = 0 |
| 44 | |
| 45 | class UserInline(admin.TabularInline): |
| 46 | model = PLUser |
| 47 | extra = 0 |
| 48 | |
| 49 | class RoleInline(admin.TabularInline): |
| 50 | model = Role |
| 51 | extra = 0 |
| 52 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 53 | class NodeInline(admin.TabularInline): |
| 54 | model = Node |
| 55 | extra = 0 |
| 56 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 57 | class PlainTextWidget(forms.Widget): |
| 58 | def render(self, _name, value, attrs): |
| 59 | return mark_safe(value) if value is not None else '' |
| 60 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 61 | class PlanetStackBaseAdmin(admin.ModelAdmin): |
| 62 | save_on_top = False |
| 63 | |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 64 | class OSModelAdmin(PlanetStackBaseAdmin): |
| 65 | """Attach client connection to openstack on delete() and save()""" |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 66 | |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 67 | def save_model(self, request, obj, form, change): |
| 68 | client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {})) |
| 69 | obj.driver = OpenStackDriver(client=client) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 70 | obj.caller = request.user |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 71 | obj.save() |
| 72 | |
| 73 | def delete_model(self, request, obj): |
| 74 | client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {})) |
| 75 | obj.driver = OpenStackDriver(client=client) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 76 | obj.caller = request.user |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 77 | obj.delete() |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 78 | |
| 79 | class RoleAdmin(OSModelAdmin): |
| 80 | fieldsets = [ |
| 81 | ('Role', {'fields': ['role_type']}) |
| 82 | ] |
| 83 | list_display = ('role_type',) |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 84 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 85 | class DeploymentNetworkAdminForm(forms.ModelForm): |
| 86 | sites = forms.ModelMultipleChoiceField( |
| 87 | queryset=Site.objects.all(), |
| 88 | required=False, |
| 89 | widget=FilteredSelectMultiple( |
| 90 | verbose_name=('Sites'), is_stacked=False |
| 91 | ) |
| 92 | ) |
| 93 | class Meta: |
| 94 | model = DeploymentNetwork |
| 95 | |
| 96 | def __init__(self, *args, **kwargs): |
| 97 | super(DeploymentNetworkAdminForm, self).__init__(*args, **kwargs) |
| 98 | |
| 99 | if self.instance and self.instance.pk: |
| 100 | self.fields['sites'].initial = self.instance.sites.all() |
| 101 | |
| 102 | def save(self, commit=True): |
| 103 | deploymentNetwork = super(DeploymentNetworkAdminForm, self).save(commit=False) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 104 | if commit: |
| 105 | deploymentNetwork.save() |
| 106 | |
| 107 | if deploymentNetwork.pk: |
| 108 | deploymentNetwork.sites = self.cleaned_data['sites'] |
| 109 | self.save_m2m() |
| 110 | |
| 111 | return deploymentNetwork |
| 112 | |
| 113 | class DeploymentNetworkAdmin(PlanetStackBaseAdmin): |
| 114 | form = DeploymentNetworkAdminForm |
| 115 | inlines = [NodeInline,] |
| 116 | |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame^] | 117 | def get_formsets(self, request, obj=None): |
| 118 | for inline in self.get_inline_instances(request, obj): |
| 119 | # hide MyInline in the add view |
| 120 | if obj is None: |
| 121 | continue |
| 122 | # give inline object access to driver and caller |
| 123 | client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {})) |
| 124 | inline.model.driver = OpenStackDriver(client=client) |
| 125 | inline.model.caller = request.user |
| 126 | yield inline.get_formset(request, obj) |
| 127 | |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 128 | class SiteAdmin(OSModelAdmin): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 129 | fieldsets = [ |
| 130 | (None, {'fields': ['name', 'site_url', 'enabled', 'is_public', 'login_base']}), |
| 131 | ('Location', {'fields': ['latitude', 'longitude']}), |
| 132 | ('Deployment Networks', {'fields': ['deployments']}) |
| 133 | ] |
| 134 | list_display = ('name', 'login_base','site_url', 'enabled') |
| 135 | filter_horizontal = ('deployments',) |
| 136 | inlines = [NodeInline,] |
| 137 | search_fields = ['name'] |
| 138 | |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame^] | 139 | def get_formsets(self, request, obj=None): |
| 140 | for inline in self.get_inline_instances(request, obj): |
| 141 | # hide MyInline in the add view |
| 142 | if obj is None: |
| 143 | continue |
| 144 | # give inline object access to driver and caller |
| 145 | client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {})) |
| 146 | inline.model.driver = OpenStackDriver(client=client) |
| 147 | inline.model.caller = request.user |
| 148 | yield inline.get_formset(request, obj) |
| 149 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 150 | class SitePrivilegeAdmin(PlanetStackBaseAdmin): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 151 | fieldsets = [ |
| 152 | (None, {'fields': ['user', 'site', 'role']}) |
| 153 | ] |
| 154 | list_display = ('user', 'site', 'role') |
| 155 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 156 | def save_model(self, request, obj, form, change): |
| 157 | # update openstack connection to use this site/tenant |
| 158 | client = OpenStackClient(tenant=obj.site.login_base, **request.session.get('auth', {})) |
| 159 | obj.driver = OpenStackDriver(client=client) |
| 160 | obj.caller = request.user |
| 161 | obj.save() |
| 162 | |
| 163 | def delete_model(self, request, obj): |
| 164 | # update openstack connection to use this site/tenant |
| 165 | client = OpenStackClient(tenant=obj.site.login_base, **request.session.get('auth', {})) |
| 166 | obj.driver = OpenStackDriver(client=client) |
| 167 | obj.caller = request.user |
| 168 | obj.delete() |
| 169 | |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 170 | class KeyAdmin(OSModelAdmin): |
Tony Mack | 759b57a | 2013-04-14 21:03:31 -0400 | [diff] [blame] | 171 | fieldsets = [ |
| 172 | ('Key', {'fields': ['name', 'key', 'type', 'blacklisted', 'user']}) |
| 173 | ] |
| 174 | list_display = ['name', 'key', 'type', 'blacklisted', 'user'] |
Tony Mack | 8484bdb | 2013-04-14 20:26:03 -0400 | [diff] [blame] | 175 | |
Tony Mack | 956104d | 2013-04-27 12:36:19 -0400 | [diff] [blame] | 176 | def get_queryset(self, request): |
| 177 | # get keys user is allowed to see |
| 178 | qs = super(KeyAdmin, self).get_queryset(request) |
| 179 | if request.user.is_superuser: |
| 180 | return qs |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 181 | # users can only see their own keys |
Tony Mack | 956104d | 2013-04-27 12:36:19 -0400 | [diff] [blame] | 182 | return qs.filter(user=request.user) |
| 183 | |
Tony Mack | e59a7c8 | 2013-04-27 11:08:10 -0400 | [diff] [blame] | 184 | |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 185 | class SliceAdmin(OSModelAdmin): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 186 | fields = ['name', 'site', 'instantiation', 'description', 'slice_url'] |
| 187 | list_display = ('name', 'site','slice_url', 'instantiation') |
| 188 | inlines = [SliverInline] |
| 189 | |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 190 | def get_formsets(self, request, obj=None): |
| 191 | for inline in self.get_inline_instances(request, obj): |
| 192 | # hide MyInline in the add view |
| 193 | if obj is None: |
| 194 | continue |
| 195 | # give inline object access to driver and caller |
| 196 | client = OpenStackClient(tenant=obj.name, **request.session.get('auth', {})) |
| 197 | inline.model.driver = OpenStackDriver(client=client) |
| 198 | inline.model.caller = request.user |
| 199 | yield inline.get_formset(request, obj) |
| 200 | |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 201 | def get_queryset(self, request): |
| 202 | qs = super(SliceAdmin, self).get_queryset(request) |
| 203 | if request.user.is_superuser: |
| 204 | return qs |
| 205 | # users can only see slices at their site |
| 206 | return qs.filter(site=request.user.site) |
| 207 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 208 | class SliceMembershipAdmin(PlanetStackBaseAdmin): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 209 | fieldsets = [ |
| 210 | (None, {'fields': ['user', 'slice', 'role']}) |
| 211 | ] |
| 212 | list_display = ('user', 'slice', 'role') |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 213 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 214 | def save_model(self, request, obj, form, change): |
| 215 | # update openstack connection to use this slice/tenant |
| 216 | client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {})) |
| 217 | obj.driver = OpenStackDriver(client=client) |
| 218 | obj.caller = request.user |
| 219 | obj.save() |
| 220 | |
| 221 | def delete_model(self, request, obj): |
| 222 | # update openstack connection to use this slice/tenant |
| 223 | client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {})) |
| 224 | obj.driver = OpenStackDriver(client=client) |
| 225 | obj.caller = request.user |
| 226 | obj.delete() |
| 227 | |
| 228 | class SubnetAdmin(PlanetStackBaseAdmin): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 229 | fields = ['cidr', 'ip_version', 'start', 'end', 'slice'] |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 230 | list_display = ('slice','cidr', 'start', 'end', 'ip_version') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 231 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 232 | def save_model(self, request, obj, form, change): |
| 233 | # update openstack connection to use this subnet's slice/tenant |
| 234 | client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {})) |
| 235 | obj.driver = OpenStackDriver(client=client) |
| 236 | obj.caller = request.user |
| 237 | obj.save() |
| 238 | |
| 239 | def delete_model(self, request, obj): |
| 240 | # update openstack connection to use this subnet's slice/tenant |
| 241 | client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {})) |
| 242 | obj.driver = OpenStackDriver(client=client) |
| 243 | obj.caller = request.user |
| 244 | obj.delete() |
| 245 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 246 | class ImageAdmin(admin.ModelAdmin): |
| 247 | fields = ['image_id', 'name', 'disk_format', 'container_format'] |
| 248 | |
| 249 | class NodeAdmin(admin.ModelAdmin): |
| 250 | list_display = ('name', 'site', 'deploymentNetwork') |
| 251 | list_filter = ('deploymentNetwork',) |
| 252 | |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 253 | |
| 254 | class SliverForm(forms.ModelForm): |
| 255 | class Meta: |
| 256 | ip = forms.CharField(widget=PlainTextWidget) |
| 257 | model = Sliver |
| 258 | widgets = { |
| 259 | 'ip': PlainTextWidget(), |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 260 | } |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 261 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 262 | class SliverAdmin(PlanetStackBaseAdmin): |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 263 | form = SliverForm |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 264 | fieldsets = [ |
Tony Mack | ab05c3b | 2013-04-30 18:30:21 -0400 | [diff] [blame] | 265 | ('Sliver', {'fields': ['ip', 'name', 'slice', 'image', 'key', 'node', 'deploymentNetwork']}) |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 266 | ] |
Tony Mack | ab05c3b | 2013-04-30 18:30:21 -0400 | [diff] [blame] | 267 | list_display = ['ip', 'name', 'slice', 'image', 'key', 'node', 'deploymentNetwork'] |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 268 | |
| 269 | def save_model(self, request, obj, form, change): |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 270 | # update openstack connection to use this sliver's slice/tenant |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 271 | client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {})) |
| 272 | obj.driver = OpenStackDriver(client=client) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 273 | obj.caller = request.user |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 274 | obj.save() |
| 275 | |
| 276 | def delete_model(self, request, obj): |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 277 | # update openstack connection to use this sliver's slice/tenant |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 278 | client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {})) |
| 279 | obj.driver = OpenStackDriver(client=client) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 280 | obj.caller = request.user |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 281 | obj.delete() |
Tony Mack | fdd4d80 | 2013-04-27 13:02:33 -0400 | [diff] [blame] | 282 | |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 283 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 284 | class UserCreationForm(forms.ModelForm): |
| 285 | """A form for creating new users. Includes all the required |
| 286 | fields, plus a repeated password.""" |
| 287 | password1 = forms.CharField(label='Password', widget=forms.PasswordInput) |
| 288 | password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput) |
| 289 | |
| 290 | class Meta: |
| 291 | model = PLUser |
| 292 | fields = ('email', 'firstname', 'lastname', 'phone', 'site') |
| 293 | |
| 294 | def clean_password2(self): |
| 295 | # Check that the two password entries match |
| 296 | password1 = self.cleaned_data.get("password1") |
| 297 | password2 = self.cleaned_data.get("password2") |
| 298 | if password1 and password2 and password1 != password2: |
| 299 | raise forms.ValidationError("Passwords don't match") |
| 300 | return password2 |
| 301 | |
| 302 | def save(self, commit=True): |
| 303 | # Save the provided password in hashed format |
| 304 | user = super(UserCreationForm, self).save(commit=False) |
Tony Mack | f9f4afb | 2013-05-01 21:02:12 -0400 | [diff] [blame] | 305 | user.password = self.cleaned_data["password1"] |
| 306 | #user.set_password(self.cleaned_data["password1"]) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 307 | if commit: |
| 308 | user.save() |
| 309 | return user |
| 310 | |
| 311 | |
| 312 | class UserChangeForm(forms.ModelForm): |
| 313 | """A form for updating users. Includes all the fields on |
| 314 | the user, but replaces the password field with admin's |
| 315 | password hash display field. |
| 316 | """ |
| 317 | password = ReadOnlyPasswordHashField() |
| 318 | |
| 319 | class Meta: |
| 320 | model = PLUser |
| 321 | |
| 322 | def clean_password(self): |
| 323 | # Regardless of what the user provides, return the initial value. |
| 324 | # This is done here, rather than on the field, because the |
| 325 | # field does not have access to the initial value |
| 326 | return self.initial["password"] |
| 327 | |
| 328 | |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 329 | class PLUserAdmin(UserAdmin, OSModelAdmin): |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 330 | class Meta: |
| 331 | app_label = "core" |
| 332 | |
| 333 | # The forms to add and change user instances |
| 334 | form = UserChangeForm |
| 335 | add_form = UserCreationForm |
| 336 | |
| 337 | # The fields to be used in displaying the User model. |
| 338 | # These override the definitions on the base UserAdmin |
| 339 | # that reference specific fields on auth.User. |
| 340 | list_display = ('email', 'site', 'firstname', 'lastname', 'last_login') |
| 341 | list_filter = ('site',) |
| 342 | fieldsets = ( |
| 343 | (None, {'fields': ('email', 'password')}), |
| 344 | ('Personal info', {'fields': ('firstname','lastname','phone','site')}), |
| 345 | #('Important dates', {'fields': ('last_login',)}), |
| 346 | ) |
| 347 | add_fieldsets = ( |
| 348 | (None, { |
| 349 | 'classes': ('wide',), |
| 350 | 'fields': ('email', 'firstname', 'lastname', 'phone', 'site', 'password1', 'password2')} |
| 351 | ), |
| 352 | ) |
| 353 | search_fields = ('email',) |
| 354 | ordering = ('email',) |
| 355 | filter_horizontal = () |
| 356 | |
Tony Mack | 31c2b8f | 2013-04-26 20:01:42 -0400 | [diff] [blame] | 357 | # register a signal that caches the user's credentials when they log in |
| 358 | def cache_credentials(sender, user, request, **kwds): |
| 359 | auth = {'username': request.POST['username'], |
| 360 | 'password': request.POST['password']} |
| 361 | request.session['auth'] = auth |
| 362 | user_logged_in.connect(cache_credentials) |
| 363 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 364 | # Now register the new UserAdmin... |
| 365 | admin.site.register(PLUser, PLUserAdmin) |
| 366 | # ... and, since we're not using Django's builtin permissions, |
| 367 | # unregister the Group model from admin. |
| 368 | admin.site.unregister(Group) |
| 369 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 370 | admin.site.register(Site, SiteAdmin) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 371 | admin.site.register(SitePrivilege, SitePrivilegeAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 372 | admin.site.register(Slice, SliceAdmin) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 373 | admin.site.register(SliceMembership, SliceMembershipAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 374 | admin.site.register(Subnet, SubnetAdmin) |
| 375 | admin.site.register(Image, ImageAdmin) |
| 376 | admin.site.register(Node, NodeAdmin) |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 377 | admin.site.register(Sliver, SliverAdmin) |
Tony Mack | 759b57a | 2013-04-14 21:03:31 -0400 | [diff] [blame] | 378 | admin.site.register(Key, KeyAdmin) |
Tony Mack | fd24d0d | 2013-04-14 00:59:17 -0400 | [diff] [blame] | 379 | admin.site.register(Role, RoleAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 380 | admin.site.register(DeploymentNetwork, DeploymentNetworkAdmin) |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 381 | |