misc: don't redirect to /cat/form/ if a formdef exists with the slug (#25450)
This commit is contained in:
parent
48fefff672
commit
c6d5ae604a
|
@ -852,19 +852,20 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
try:
|
||||
category = Category.get_by_urlname(component)
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
return FormsRootDirectory(category)
|
||||
category = None
|
||||
|
||||
# is this a formdef ?
|
||||
try:
|
||||
formdef = FormDef.get_by_urlname(component)
|
||||
except KeyError:
|
||||
pass
|
||||
if category:
|
||||
return FormsRootDirectory(category)
|
||||
else:
|
||||
# if there's no category, or the request is a POST, directly call
|
||||
# if the form has no category, or the request is a POST, or the
|
||||
# slug matches both a category and a formdef, directly call
|
||||
# into FormsRootDirectory.
|
||||
if formdef.category_id is None or get_request().get_method() == 'POST':
|
||||
if formdef.category_id is None or get_request().get_method() == 'POST' or (
|
||||
formdef and category):
|
||||
get_response().filter['bigdiv'] = 'rub_service'
|
||||
return FormsRootDirectory()._q_lookup(component)
|
||||
|
||||
|
|
|
@ -180,3 +180,35 @@ def test_agenda():
|
|||
resp = app.get('/agenda/filter')
|
||||
assert 'tags$element0' in resp.form.fields
|
||||
assert 'calendars$element0' in resp.form.fields
|
||||
|
||||
def test_form_category_redirection():
|
||||
Category.wipe()
|
||||
cat = Category(name='baz')
|
||||
cat.store()
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'foobar'
|
||||
formdef.category_id = cat.id
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
# check we get a redirection to /category/formdef/
|
||||
resp = get_app(pub).get('/foobar/')
|
||||
assert resp.location.endswith('/baz/foobar/')
|
||||
|
||||
def test_form_and_category_same_slug():
|
||||
Category.wipe()
|
||||
cat = Category(name='foobar')
|
||||
cat.store()
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'foobar'
|
||||
formdef.category_id = cat.id
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
# check we get to the form, not the category
|
||||
resp = get_app(pub).get('/foobar/')
|
||||
assert resp.form
|
||||
|
|
Reference in New Issue