Add POST/Redirect/GET for Domains dashboard
Currently, "Set Domain Context" and "Clear Domain Context" doesn't do PRG, so page reload after these actions produce browser popup about form re-submission. Proposed patch fixes it Change-Id: I80d11cbdd42224456ee3a354ebad556a318ba03a
This commit is contained in:
parent
9ba9a54d0f
commit
c80d7e32ef
@ -15,6 +15,7 @@
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django import shortcuts
|
||||
from django.template import defaultfilters as filters
|
||||
from django.urls import reverse
|
||||
from django.utils.http import urlencode
|
||||
@ -246,9 +247,11 @@ class SetDomainContext(tables.Action):
|
||||
messages.success(request,
|
||||
_('Domain Context updated to Domain %s.') %
|
||||
domain.name)
|
||||
return shortcuts.redirect(request.get_full_path())
|
||||
except Exception:
|
||||
messages.error(request,
|
||||
_('Unable to set Domain Context.'))
|
||||
return shortcuts.redirect(request.get_full_path())
|
||||
|
||||
|
||||
class UnsetDomainContext(tables.Action):
|
||||
@ -268,6 +271,7 @@ class UnsetDomainContext(tables.Action):
|
||||
request.session.pop("domain_context")
|
||||
request.session.pop("domain_context_name")
|
||||
messages.success(request, _('Domain Context cleared.'))
|
||||
return shortcuts.redirect(request.get_full_path())
|
||||
|
||||
|
||||
class DomainsTable(tables.DataTable):
|
||||
|
@ -153,15 +153,21 @@ class DomainsViewTests(test.BaseAdminViewTests):
|
||||
self.mock_domain_list.return_value = self.domains.list()
|
||||
|
||||
formData = {'action': 'domains__set_domain_context__%s' % domain.id}
|
||||
res = self.client.post(DOMAINS_INDEX_URL, formData)
|
||||
res = self.client.post(DOMAINS_INDEX_URL, formData, follow=True)
|
||||
|
||||
self.assertRedirects(res, DOMAINS_INDEX_URL, status_code=302,
|
||||
target_status_code=200,
|
||||
fetch_redirect_response=True)
|
||||
self.assertTemplateUsed(res, constants.DOMAINS_INDEX_VIEW_TEMPLATE)
|
||||
self.assertCountEqual(res.context['table'].data, [domain, ])
|
||||
self.assertContains(res, "<em>another_test_domain:</em>")
|
||||
|
||||
formData = {'action': 'domains__clear_domain_context__%s' % domain.id}
|
||||
res = self.client.post(DOMAINS_INDEX_URL, formData)
|
||||
res = self.client.post(DOMAINS_INDEX_URL, formData, follow=True)
|
||||
|
||||
self.assertRedirects(res, DOMAINS_INDEX_URL, status_code=302,
|
||||
target_status_code=200,
|
||||
fetch_redirect_response=True)
|
||||
self.assertTemplateUsed(res, constants.DOMAINS_INDEX_VIEW_TEMPLATE)
|
||||
self.assertCountEqual(res.context['table'].data, self.domains.list())
|
||||
self.assertNotContains(res, "<em>test_domain:</em>")
|
||||
|
Loading…
Reference in New Issue
Block a user