X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fadmin.py;h=d2a9b53150dc505a41df1328c1da3d9c5ef42d1a;hb=688b9d9e8279538d4e169292346841734625a474;hp=a77be5bead5dad76fc8e84f4ec9b572f80686b53;hpb=5c9b77c25b94e6f22358d9063be427865a1e4945;p=plstackapi.git diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py index a77be5b..d2a9b53 100644 --- a/planetstack/core/admin.py +++ b/planetstack/core/admin.py @@ -17,6 +17,10 @@ from django.core.exceptions import PermissionDenied from django.core.urlresolvers import reverse, NoReverseMatch import django_evolution +import threading + +# thread locals necessary to work around a django-suit issue +_thread_locals = threading.local() def backend_icon(obj): # backend_status, enacted, updated): #return "%s %s %s" % (str(obj.updated), str(obj.enacted), str(obj.backend_status)) @@ -723,8 +727,10 @@ class SliceForm(forms.ModelForm): def clean(self): cleaned_data = super(SliceForm, self).clean() name = cleaned_data.get('name') - site_id = cleaned_data.get('site') - site = Slice.objects.get(id=site_id) + site = cleaned_data.get('site') + if (not isinstance(site,Site)): + # previous code indicates 'site' could be a site_id and not a site? + site = Slice.objects.get(id=site.id) if not name.startswith(site.login_base): raise forms.ValidationError('slice name must begin with %s' % site.login_base) return cleaned_data @@ -1036,7 +1042,7 @@ class UserAdmin(PermissionCheckingAdminMixin, UserAdmin): add_fieldsets = ( (None, { 'classes': ('wide',), - 'fields': ('email', 'firstname', 'lastname', 'is_readonly', 'phone', 'public_key','password1', 'password2')} + 'fields': ('email', 'firstname', 'lastname', 'is_readonly', 'phone', 'public_key','password1', 'password2')}, ), ) readonly_fields = ('backend_status_text', ) @@ -1046,12 +1052,24 @@ class UserAdmin(PermissionCheckingAdminMixin, UserAdmin): user_readonly_fields = fieldListLoginDetails + fieldListContactInfo - suit_form_tabs =(('general','Login Details'), - ('contact','Contact Information'), - ('sliceprivileges','Slice Privileges'), - ('siteprivileges','Site Privileges'), - ('deploymentprivileges','Deployment Privileges'), - ('dashboards','Dashboard Views')) + def get_form(self, request, obj=None): + # Save obj in thread-local storage, so suit_form_tabs can use it to + # determine whether we're in edit or add mode. + _thread_locals.request = request + _thread_locals.obj = obj + return super(UserAdmin, self).get_form(request, obj) + + @property + def suit_form_tabs(self): + if getattr(_thread_locals, "obj", None) is None: + return [] + else: + return (('general','Login Details'), + ('contact','Contact Information'), + ('sliceprivileges','Slice Privileges'), + ('siteprivileges','Site Privileges'), + ('deploymentprivileges','Deployment Privileges'), + ('dashboards','Dashboard Views')) def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == 'site':