def save_model(self, request, obj, form, change): new_watumiaji = form.save(commit=False) new_watumiaji.save() #Super users dont belong to any group so have to display a dropdown field for organization #that they can use to allocate the user if request.user.is_superuser: org_id = request.POST['organization'] slot = utility.auto_alloc_slot(obj) org = Organization.objects.get(pk = int(org_id)) grp_name = slugify(org.org_name).replace('-','') group = Vikundi.objects.get(group_name = grp_name, org = org) #TODO: Remove user from other organizations, if any so that they are not members #of more than one organization if not new_watumiaji.is_member(group): new_watumiaji.join_group(group, slot, None, False) #if adding a new user then they'll be added to default #group for that organization if not change: if not request.user.is_superuser: slot = utility.auto_alloc_slot(obj) org = Organization.objects.get(org_admin = request.user) grp_name = slugify(org.org_name).replace('-','') group = Vikundi.objects.get(group_name = grp_name, org = org) obj.join_group(group, slot, None, False)
def save_model(self, request, obj, form, change): new_watumiaji = form.save(commit=False) new_watumiaji.save() #Super users dont belong to any group so have to display a dropdown field for organization #that they can use to allocate the user if request.user.is_superuser: org_id = request.POST['organization'] slot = utility.auto_alloc_slot(obj) org = Organization.objects.get(pk=int(org_id)) grp_name = slugify(org.org_name).replace('-', '') group = Vikundi.objects.get(group_name=grp_name, org=org) #TODO: Remove user from other organizations, if any so that they are not members #of more than one organization if not new_watumiaji.is_member(group): new_watumiaji.join_group(group, slot, None, False) #if adding a new user then they'll be added to default #group for that organization if not change: if not request.user.is_superuser: slot = utility.auto_alloc_slot(obj) org = Organization.objects.get(org_admin=request.user) grp_name = slugify(org.org_name).replace('-', '') group = Vikundi.objects.get(group_name=grp_name, org=org) obj.join_group(group, slot, None, False)
def create_vikundi_object_handler(sender, **kwargs): logger.debug ('Creating vikundi %s' % kwargs) auth_user = kwargs['auth_user'] group_name = kwargs['group_name'] org = kwargs['org'] slot = utility.auto_alloc_slot(get_or_create_user_profile(auth_user), auth_user.is_superuser) user = auth_user.get_profile() Vikundi.create(user, group_name, slot, org = org)
def create_vikundi_object_handler(sender, **kwargs): logger.debug('Creating vikundi %s' % kwargs) auth_user = kwargs['auth_user'] group_name = kwargs['group_name'] org = kwargs['org'] slot = utility.auto_alloc_slot(get_or_create_user_profile(auth_user), auth_user.is_superuser) user = auth_user.get_profile() Vikundi.create(user, group_name, slot, org=org)
def save(self, force_insert=False, force_update=False, commit=True): ug_form = super(UserGroupsForm,self).save(commit=False) #for new users auto alloc slot. self.initial == {} for new records if self.initial == {}: ug_form.slot = utility.auto_alloc_slot(ug_form.user) #if quiet state changed use methods in model ug_db = UserGroups.objects.filter(pk = ug_form.pk) if len(ug_db) > 0: #if it's an edit then ug_db is not empty if ug_db[0].is_quiet != ug_form.is_quiet: if ug_form.is_quiet == 'yes': ug_form.group.set_quiet(ug_form.user) else: ug_form.group.unquiet(ug_form.user) #For some reason this value is not set ug_form.group_id = ug_form.group.pk ug_form.save() return ug_form
def save(self, force_insert=False, force_update=False, commit=True): ug_form = super(UserGroupsForm, self).save(commit=False) #for new users auto alloc slot. self.initial == {} for new records if self.initial == {}: ug_form.slot = utility.auto_alloc_slot(ug_form.user) #if quiet state changed use methods in model ug_db = UserGroups.objects.filter(pk=ug_form.pk) if len(ug_db) > 0: #if it's an edit then ug_db is not empty if ug_db[0].is_quiet != ug_form.is_quiet: if ug_form.is_quiet == 'yes': ug_form.group.set_quiet(ug_form.user) else: ug_form.group.unquiet(ug_form.user) #For some reason this value is not set ug_form.group_id = ug_form.group.pk ug_form.save() return ug_form