def get(self, request, report_id): """load a report""" data = { "report": get_object_or_404(models.Report, id=report_id), "group_form": forms.UserGroupForm(), } return TemplateResponse(request, "settings/reports/report.html", data)
def post(self, request, user): """update user group""" user = get_object_or_404(models.User, id=user) form = forms.UserGroupForm(request.POST, instance=user) if form.is_valid(): form.save() data = {"user": user, "group_form": form} return TemplateResponse(request, "settings/users/user.html", data)
def moderator_delete_user(request, user_id): """permanently delete a user""" user = get_object_or_404(models.User, id=user_id) # we can't delete users on other instances if not user.local: raise PermissionDenied() form = forms.DeleteUserForm(request.POST, instance=user) moderator = models.User.objects.get(id=request.user.id) # check the moderator's password if form.is_valid() and moderator.check_password( form.cleaned_data["password"]): user.deactivation_reason = "moderator_deletion" user.delete() return redirect("settings-user", user.id) form.errors["password"] = ["Invalid password"] data = {"user": user, "group_form": forms.UserGroupForm(), "form": form} return TemplateResponse(request, "user_admin/user.html", data)
def get(self, request, user): """user view""" user = get_object_or_404(models.User, id=user) data = {"user": user, "group_form": forms.UserGroupForm()} return TemplateResponse(request, "settings/users/user.html", data)