misc: support variables in URL in root and category redirects (#8301)
This commit is contained in:
parent
fbef6d3c56
commit
7e12818eb8
|
@ -108,6 +108,14 @@ def test_home_redirect(pub):
|
|||
assert home.status_int == 302
|
||||
assert home.location == 'http://www.example.com/'
|
||||
|
||||
def test_home_redirect_var(pub):
|
||||
pub.cfg['misc']['homepage-redirect-url'] = 'http://www.example.com/[site_lang]/'
|
||||
pub.write_cfg()
|
||||
create_formdef()
|
||||
home = get_app(pub).get('/')
|
||||
assert home.status_int == 302
|
||||
assert home.location == 'http://www.example.com/en/'
|
||||
|
||||
def test_category_page(pub):
|
||||
formdef = create_formdef()
|
||||
formdef.category_id = '1'
|
||||
|
@ -127,6 +135,17 @@ def test_category_page_redirect(pub):
|
|||
assert resp.status_int == 302
|
||||
assert resp.location == 'http://www.example.com/'
|
||||
|
||||
def test_category_page_redirect_var(pub):
|
||||
formdef = create_formdef()
|
||||
formdef.category_id = '1'
|
||||
formdef.store()
|
||||
cat = Category.get(1)
|
||||
cat.redirect_url = 'http://www.example.com/[site_lang]/[category_slug]/'
|
||||
cat.store()
|
||||
resp = get_app(pub).get('/foobar/')
|
||||
assert resp.status_int == 302
|
||||
assert resp.location == 'http://www.example.com/en/foobar/'
|
||||
|
||||
def test_form_access(pub):
|
||||
formdef = create_formdef()
|
||||
get_app(pub).get('/test/', status=200)
|
||||
|
|
|
@ -86,6 +86,7 @@ class Category(XmlStorableObject):
|
|||
d = {
|
||||
'category_name': self.name,
|
||||
'category_id': self.url_name,
|
||||
'category_slug': self.url_name,
|
||||
}
|
||||
if not minimal:
|
||||
d.update({
|
||||
|
|
|
@ -1042,7 +1042,8 @@ class RootDirectory(AccessControlled, Directory):
|
|||
redirect_url = self.category.redirect_url
|
||||
|
||||
if redirect_url:
|
||||
return redirect(redirect_url)
|
||||
return redirect(misc.get_variadic_url(redirect_url,
|
||||
get_publisher().substitutions.get_context_variables()))
|
||||
|
||||
template.html_top(default_org = _('Forms'))
|
||||
r = TemplateIO(html=True)
|
||||
|
|
Loading…
Reference in New Issue