def remove_user_from_organization(self, request, queryset): form = None if request.user.is_superuser: if 'cancel' in request.POST: self.message_user(request, _('Cancelled removing users from the organization.')) return elif 'remove_user_profile_from_organization' in request.POST: objs_up = UserProfile.objects.filter(user__is_active=True) form = self.UserProfileinOrganizationForm(objs_up, request.POST) if form.is_valid(): userprofiles = form.cleaned_data['users'] for userprofile in userprofiles: for obj in queryset: userprofile.user.groups.remove(obj) self.message_user(request, _('Successfully removed users from organization.')) return HttpResponseRedirect(request.get_full_path()) if not form: userprofiles = UserProfile.objects.filter(user__is_active=True) form = self.UserProfileinOrganizationForm(choices=userprofiles, initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)}) dictionary = {'title': _('Remove Users from Organization'), 'selected_organizations': queryset, 'form': form, 'path': request.get_full_path() } dictionary.update(create_breadcrumb_template_params(self.model, _('Remove user'))) return render_to_response('accounts/remove_user_profile_from_organization.html', dictionary, context_instance=RequestContext(request))
def remove_user_from_editor_group_managers(self, request, queryset): form = None if request.user.is_superuser: if "cancel" in request.POST: self.message_user(request, _("Cancelled removing users from " "editor group managers.")) return elif "remove_user_profile_from_editor_group_managers" in request.POST: objs_up = UserProfile.objects.filter(user__is_active=True) form = self.UserProfileinEditorGroupManagersForm(objs_up, request.POST) if form.is_valid(): userprofiles = form.cleaned_data["users"] for userprofile in userprofiles: for obj in queryset: userprofile.user.groups.remove(obj) self.message_user(request, _("Successfully removed users " "from editor group managers.")) return HttpResponseRedirect(request.get_full_path()) if not form: userprofiles = UserProfile.objects.filter(user__is_active=True) form = self.UserProfileinEditorGroupManagersForm( choices=userprofiles, initial={"_selected_action": request.POST.getlist(admin.ACTION_CHECKBOX_NAME)} ) dictionary = { "title": _("Remove Users from Editor Group Managers"), "selected_editorgroupmanagers": queryset, "form": form, "path": request.get_full_path(), } dictionary.update(create_breadcrumb_template_params(self.model, _("Remove user"))) return render_to_response( "accounts/remove_user_profile_from_editor_group_managers.html", dictionary, context_instance=RequestContext(request), ) else: self.message_user( request, _("You need to be a superuser to " "remove a user from these editor group managers.") ) return HttpResponseRedirect(request.get_full_path())
def add_user_to_organization_managers(self, request, queryset): form = None if request.user.is_superuser: if "cancel" in request.POST: self.message_user(request, _("Cancelled adding users to the organization managers.")) return elif "add_user_profile_to_organization_managers" in request.POST: objs_up = UserProfile.objects.filter(user__is_active=True) form = self.UserProfileinOrganizationManagersForm(objs_up, request.POST) if form.is_valid(): userprofiles = form.cleaned_data["users"] for userprofile in userprofiles: user = userprofile.user for obj in queryset: user.groups.add(obj) user.groups.add(obj.managed_organization) self.message_user(request, _("Successfully added users to organization managers.")) return HttpResponseRedirect(request.get_full_path()) if not form: userprofiles = UserProfile.objects.filter(user__is_active=True) form = self.UserProfileinOrganizationManagersForm( choices=userprofiles, initial={"_selected_action": request.POST.getlist(admin.ACTION_CHECKBOX_NAME)} ) dictionary = { "title": _("Add Users to Organization Manager Group"), "selected_organizationmanagers": queryset, "form": form, "path": request.get_full_path(), } dictionary.update(create_breadcrumb_template_params(self.model, _("Add user"))) return render_to_response( "accounts/add_user_profile_to_organization_managers.html", dictionary, context_instance=RequestContext(request), ) else: self.message_user(request, _("You need to be a superuser to add " "a user to these organization managers.")) return HttpResponseRedirect(request.get_full_path())
def add_user_to_organization_managers(self, request, queryset): form = None if request.user.is_superuser: if 'cancel' in request.POST: self.message_user(request, _('Cancelled adding users to the organization managers.')) return elif 'add_user_profile_to_organization_managers' in request.POST: objs_up = UserProfile.objects.filter(user__is_active=True) form = self.UserProfileinOrganizationManagersForm(objs_up, request.POST) if form.is_valid(): userprofiles = form.cleaned_data['users'] for userprofile in userprofiles: user = userprofile.user for obj in queryset: user.groups.add(obj) user.groups.add(obj.managed_organization) self.message_user(request, _('Successfully added users to organization managers.')) return HttpResponseRedirect(request.get_full_path()) if not form: userprofiles = UserProfile.objects.filter(user__is_active=True) form = self.UserProfileinOrganizationManagersForm(choices=userprofiles, initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)}) dictionary = {'title': _('Add Users to Organization Manager Group'), 'selected_organizationmanagers': queryset, 'form': form, 'path': request.get_full_path() } dictionary.update(create_breadcrumb_template_params(self.model, _('Add user'))) return render_to_response('accounts/add_user_profile_to_organization_managers.html', dictionary, context_instance=RequestContext(request)) else: self.message_user(request, _('You need to be a superuser to add ' \ 'a user to these organization managers.')) return HttpResponseRedirect(request.get_full_path())