From add325c2cce1af21f2774083da8984e3741267b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 22 Mar 2016 11:03:46 +0100 Subject: [PATCH] api: include category_slug in formdefs API (#10366) --- help/fr/api-schema.page | 6 ++++-- tests/test_api.py | 6 ++++-- wcs/api.py | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/help/fr/api-schema.page b/help/fr/api-schema.page index 81a4e1b..f6b2bfe 100644 --- a/help/fr/api-schema.page +++ b/help/fr/api-schema.page @@ -45,7 +45,8 @@ l'URL /api/formdefs/. "redirection": false, "description": "", "keywords": [], - "category": "Inscriptions"}, + "category": "Inscriptions", + "category_slug": "inscriptions"}, {"url": "https://www.example.net/inscriptions/piscine", "title": "Piscine", "slug": "piscine", @@ -54,7 +55,8 @@ l'URL /api/formdefs/. "redirection": false, "description": "La piscine est ouverte du lundi au samedi.", "keywords": ["sport"], - "category": "Inscriptions"} + "category": "Inscriptions", + "category_slug": "inscriptions"} ] diff --git a/tests/test_api.py b/tests/test_api.py index f38be15..153318d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -506,7 +506,7 @@ def test_categories(pub): FormDef.wipe() Category.wipe() category = Category() - category.name = 'category' + category.name = 'Category' category.description = 'hello world' category.store() @@ -532,7 +532,7 @@ def test_categories(pub): resp = get_app(pub).get('/api/categories/') resp2 = get_app(pub).get('/categories', headers={'Accept': 'application/json'}) assert resp.json == resp2.json - assert resp.json['data'][0]['title'] == 'category' + assert resp.json['data'][0]['title'] == 'Category' assert resp.json['data'][0]['url'] == 'http://example.net/category/' assert resp.json['data'][0]['description'] == 'hello world' assert set(resp.json['data'][0]['keywords']) == set(['foobar', 'mobile', 'test']) @@ -556,6 +556,8 @@ def test_categories_formdefs(pub): assert resp.json[0]['url'] == 'http://example.net/test/' assert resp.json[0]['count'] == 0 assert resp.json[0]['redirection'] == False + assert resp.json[0]['category'] == 'Category' + assert resp.json[0]['category_slug'] == 'category' def test_categories_full(pub): test_categories(pub) diff --git a/wcs/api.py b/wcs/api.py index 2400967..5be02ef 100644 --- a/wcs/api.py +++ b/wcs/api.py @@ -342,6 +342,7 @@ class ApiFormdefsDirectory(Directory): if formdef.category: formdict['category'] = unicode(formdef.category.name, charset) + formdict['category_slug'] = unicode(formdef.category.url_name, charset) formdict['category_position'] = (formdef.category.position or 0) else: formdict['category_position'] = sys.maxint -- 2.8.0.rc3