0001-misc-don-t-redirect-to-cat-form-if-a-formdef-exists-.patch
auquotidien/modules/root.py | ||
---|---|---|
852 | 852 |
try: |
853 | 853 |
category = Category.get_by_urlname(component) |
854 | 854 |
except KeyError: |
855 |
pass |
|
856 |
else: |
|
857 |
return FormsRootDirectory(category) |
|
855 |
category = None |
|
858 | 856 | |
859 | 857 |
# is this a formdef ? |
860 | 858 |
try: |
861 | 859 |
formdef = FormDef.get_by_urlname(component) |
862 | 860 |
except KeyError: |
863 |
pass |
|
861 |
if category: |
|
862 |
return FormsRootDirectory(category) |
|
864 | 863 |
else: |
865 |
# if there's no category, or the request is a POST, directly call |
|
864 |
# if the form has no category, or the request is a POST, or the |
|
865 |
# slug matches both a category and a formdef, directly call |
|
866 | 866 |
# into FormsRootDirectory. |
867 |
if formdef.category_id is None or get_request().get_method() == 'POST': |
|
867 |
if formdef.category_id is None or get_request().get_method() == 'POST' or ( |
|
868 |
formdef and category): |
|
868 | 869 |
get_response().filter['bigdiv'] = 'rub_service' |
869 | 870 |
return FormsRootDirectory()._q_lookup(component) |
870 | 871 |
tests/test_user_pages.py | ||
---|---|---|
180 | 180 |
resp = app.get('/agenda/filter') |
181 | 181 |
assert 'tags$element0' in resp.form.fields |
182 | 182 |
assert 'calendars$element0' in resp.form.fields |
183 | ||
184 |
def test_form_category_redirection(): |
|
185 |
Category.wipe() |
|
186 |
cat = Category(name='baz') |
|
187 |
cat.store() |
|
188 | ||
189 |
FormDef.wipe() |
|
190 |
formdef = FormDef() |
|
191 |
formdef.name = 'foobar' |
|
192 |
formdef.category_id = cat.id |
|
193 |
formdef.fields = [] |
|
194 |
formdef.store() |
|
195 | ||
196 |
# check we get a redirection to /category/formdef/ |
|
197 |
resp = get_app(pub).get('/foobar/') |
|
198 |
assert resp.location.endswith('/baz/foobar/') |
|
199 | ||
200 |
def test_form_and_category_same_slug(): |
|
201 |
Category.wipe() |
|
202 |
cat = Category(name='foobar') |
|
203 |
cat.store() |
|
204 | ||
205 |
FormDef.wipe() |
|
206 |
formdef = FormDef() |
|
207 |
formdef.name = 'foobar' |
|
208 |
formdef.category_id = cat.id |
|
209 |
formdef.fields = [] |
|
210 |
formdef.store() |
|
211 | ||
212 |
# check we get to the form, not the category |
|
213 |
resp = get_app(pub).get('/foobar/') |
|
214 |
assert resp.form |
|
183 |
- |