Beispiel #1
0
 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 an dropdown organization field
     #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)
Beispiel #2
0
    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