def su_view(request, next_page=None, redirect_field_name=REDIRECT_FIELD_NAME): form = SuForm(request.POST) if not form.is_valid(): return TemplateResponse( request, 'simple-centered-form.html', { 'form': form, 'action': reverse('su'), 'title': _("Login as another user"), }, ) user = form.cleaned_data['user'] if is_under_su(request): raise SuspiciousOperation su_to_user(request, user, form.cleaned_data['backend']) if redirect_field_name in request.GET: next_page = request.GET[redirect_field_name] elif redirect_field_name in request.POST: next_page = request.POST[redirect_field_name] request.session[REDIRECTION_AFTER_SU_KEY] = 'PRE_SU' return safe_redirect(request, next_page)
def su_view(request, next_page=None, redirect_field_name=REDIRECT_FIELD_NAME): form = SuForm(request.POST) if not form.is_valid(): return TemplateResponse(request, 'simple-centered-form.html', {'form': form, 'action': reverse('su'), 'title': _("Login as another user")}) user = form.cleaned_data['user'] if user.is_superuser or is_under_su(request): raise SuspiciousOperation su_to_user(request, user, form.cleaned_data['backend']) if redirect_field_name in request.REQUEST: next_page = request.REQUEST[redirect_field_name] return safe_redirect(request, next_page)