add quick-profile to user admin
diff --git a/xos/core/admin.py b/xos/core/admin.py
index f77345a..a3aea48 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -1253,6 +1253,9 @@
password = ReadOnlyPasswordHashField(label='Password',
help_text= '<a href=\"password/\">Change Password</a>.')
+ PROFILE_CHOICES = ((None, '------'), ('regular', 'Regular user'), ('cp', 'Content Provider'))
+ profile = forms.ChoiceField(choices=PROFILE_CHOICES, required=False, label="Quick Profile")
+
class Meta:
model = User
widgets = { 'public_key': UploadTextareaWidget, }
@@ -1263,6 +1266,12 @@
# field does not have access to the initial value
return self.initial["password"]
+ def save(self, *args, **kwargs):
+ if self.cleaned_data['profile']:
+ self.instance.apply_profile(self.cleaned_data['profile'])
+
+ return super(UserChangeForm, self).save(*args, **kwargs)
+
class UserDashboardViewInline(XOSTabularInline):
model = UserDashboardView
extra = 0
@@ -1296,7 +1305,7 @@
list_filter = ('site',)
inlines = [SlicePrivilegeInline,SitePrivilegeInline]
admin_inlines = [ControllerUserInline]
- fieldListLoginDetails = ['backend_status_text', 'email','site','password','is_active','is_readonly','is_admin','is_appuser', 'public_key']
+ fieldListLoginDetails = ['backend_status_text', 'email', 'site','password','is_active','is_readonly','is_admin','is_appuser', 'public_key', 'profile']
fieldListContactInfo = ['firstname','lastname','phone','timezone']
fieldsets = (
@@ -1350,9 +1359,13 @@
if 'is_admin' in login_details_fields:
login_details_fields.remove('is_admin')
if 'is_readonly' in login_details_fields:
- login_details_fields.remove('is_readonly')
+ login_details_fields.remove('is_readonly')
+ if 'is_appuser' in login_details_fields:
+ login_details_fields.remove('is_admin')
+ if 'profile' in login_details_fields:
+ login_details_fields.remove('profile')
#if len(request.user.siteprivileges.filter(role__role = 'pi')) > 0:
- # only admins and pis can change a user's site
+ # only admins and pis can change a user's site
# self.readonly_fields = ('backend_status_text', 'site')
self.fieldsets = (
('Login Details', {'fields': login_details_fields, 'classes':['suit-tab suit-tab-general']}),
diff --git a/xos/core/models/user.py b/xos/core/models/user.py
index 397c4f8..32e3e7d 100644
--- a/xos/core/models/user.py
+++ b/xos/core/models/user.py
@@ -198,7 +198,7 @@
dashboards = sorted(list(self.userdashboardviews.all()), key=attrgetter('order'))
dashboards = [x.dashboardView for x in dashboards]
- if not dashboards:
+ if (not dashboards) and (not self.is_appuser):
for dashboardName in DEFAULT_DASHBOARDS:
dbv = DashboardView.objects.filter(name=dashboardName)
if dbv:
@@ -353,6 +353,17 @@
raise PermissionDenied("You do not have permission to delete %s objects" % self.__class__.__name__)
self.delete(*args, **kwds)
+ def apply_profile(self, profile):
+ if profile=="regular":
+ self.is_appuser = False
+ self.is_admin = False
+
+ elif profile=="cp":
+ self.is_appuser = True
+ self.is_admin = False
+ for db in self.userdashboardviews.all():
+ db.delete()
+
class UserDashboardView(PlCoreBase):
user = models.ForeignKey(User, related_name='userdashboardviews')
dashboardView = models.ForeignKey(DashboardView, related_name='userdashboardviews')