user post-creation redirect based on 'next' keyword (#28931)
This commit is contained in:
parent
bc26abc94c
commit
f48147b471
|
@ -7,7 +7,7 @@
|
|||
|
||||
{% block hidden_inputs %}
|
||||
{{ block.super }}
|
||||
{% if next_url %}<input type="hidden" name="next_url" value="{{ next_url }}">{% endif %}
|
||||
{% if next %}<input type="hidden" name="next" value="{{ next }}">{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
|
|
|
@ -129,15 +129,15 @@ class UserAddView(BaseAddView):
|
|||
return fields
|
||||
|
||||
def get_success_url(self):
|
||||
return self.request.POST.get('next_url') or \
|
||||
return self.request.POST.get('next') or \
|
||||
reverse('a2-manager-user-detail', kwargs={'pk': self.object.pk})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UserAddView, self).get_context_data(**kwargs)
|
||||
context['cancel_url'] = '../..'
|
||||
context['ou'] = self.ou
|
||||
if hasattr(self.request, 'GET') and 'next_url' in self.request.GET:
|
||||
context['next_url'] = self.request.GET['next_url']
|
||||
if hasattr(self.request, 'GET') and 'next' in self.request.GET:
|
||||
context['next'] = self.request.GET['next']
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
|
|
|
@ -741,9 +741,9 @@ def test_return_on_logout(superuser, app):
|
|||
assert response.request.query_string == 'next=/manage/'
|
||||
|
||||
|
||||
def test_manager_create_user_next_url(superuser_or_admin, app, ou1):
|
||||
def test_manager_create_user_next(superuser_or_admin, app, ou1):
|
||||
next_url = u'https://example.nowhere.null/'
|
||||
url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url)
|
||||
url = u'/manage/users/%s/add/?next=%s' % (ou1.pk, next_url)
|
||||
login(app, superuser_or_admin, '/manage/')
|
||||
response = app.get(url)
|
||||
form = response.form
|
||||
|
@ -755,9 +755,9 @@ def test_manager_create_user_next_url(superuser_or_admin, app, ou1):
|
|||
assert form.submit().location == next_url
|
||||
|
||||
|
||||
def test_manager_create_user_next_url_form_cancelation(superuser_or_admin, app, ou1):
|
||||
def test_manager_create_user_next_form_cancelation(superuser_or_admin, app, ou1):
|
||||
next_url = u'https://example.nowhere.null/'
|
||||
url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url)
|
||||
url = u'/manage/users/%s/add/?next=%s' % (ou1.pk, next_url)
|
||||
login(app, superuser_or_admin, '/manage/')
|
||||
response = app.get(url)
|
||||
form = response.form
|
||||
|
@ -769,9 +769,9 @@ def test_manager_create_user_next_url_form_cancelation(superuser_or_admin, app,
|
|||
assert form.submit('cancel').location == next_url
|
||||
|
||||
|
||||
def test_manager_create_user_next_url_form_error(superuser_or_admin, app, ou1):
|
||||
def test_manager_create_user_next_form_error(superuser_or_admin, app, ou1):
|
||||
next_url = u'https://example.nowhere.null/'
|
||||
url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url)
|
||||
url = u'/manage/users/%s/add/?next=%s' % (ou1.pk, next_url)
|
||||
login(app, superuser_or_admin, '/manage/')
|
||||
response = app.get(url)
|
||||
form = response.form
|
||||
|
@ -779,4 +779,4 @@ def test_manager_create_user_next_url_form_error(superuser_or_admin, app, ou1):
|
|||
form.set('last_name', 'Doe')
|
||||
form.set('email', 'jd') # erroneous
|
||||
form.set('password1', 'notvalid') # erroneous
|
||||
assert '<input type="hidden" name="next_url" value="%s">' % next_url in form.submit().body
|
||||
assert '<input type="hidden" name="next" value="%s">' % next_url in form.submit().body
|
||||
|
|
Loading…
Reference in New Issue