misc: display formdef when slug is shared by category and formdef (#39155)

This commit is contained in:
Frédéric Péters 2020-01-21 16:52:43 +01:00
parent 6d42dae95b
commit 7c109c3059
2 changed files with 37 additions and 0 deletions

View File

@ -280,6 +280,13 @@ class AlternateRootDirectory(OldRootDirectory):
return FormsRootDirectory(f.category)._q_traverse(path[1:])
return redirect('%s%s/%s' % (base_url, f.category.url_name, uri_rest))
try:
cat = Category.get_by_urlname(path[0])
except KeyError:
pass
else:
return FormsRootDirectory(cat)._q_traverse(path[1:])
raise e

View File

@ -153,3 +153,33 @@ def test_form_and_category_same_slug():
# check we get to the form, not the category
resp = get_app(pub).get('/foobar/')
assert resp.form
def test_form_and_category_same_slug2():
Category.wipe()
cat = Category(name='test')
cat.store()
FormDef.wipe()
formdef = FormDef()
formdef.name = 'foobar'
formdef.category_id = cat.id
formdef.fields = []
formdef.store()
formdef = FormDef()
formdef.name = 'test'
formdef.fields = []
formdef.store()
# check we get to the foobar form
resp = get_app(pub).get('/foobar/')
assert resp.location == 'http://example.net/test/foobar/'
resp = resp.follow()
assert resp.form
assert '<h3>foobar</h3>' in resp
# check we get to the test form
resp = get_app(pub).get('/test/')
assert resp.form
assert '<h3>test</h3>' in resp