improve json category REST API, sort and include description (#4958)
This commit is contained in:
parent
6e21e2bc40
commit
228f954af2
|
@ -78,7 +78,8 @@ La liste des catégories est disponible à l'URL <code>/categories</code>.
|
|||
{"data":
|
||||
[
|
||||
{"url": "https://www.example.net/inscriptions/",
|
||||
"title": "Inscriptions"},
|
||||
"title": "Inscriptions",
|
||||
"description": "<p>Pour vous et vos enfants...</p>" },
|
||||
{"url": "https://www.example.net/etat-civil/",
|
||||
"title": "État civil"}
|
||||
]
|
||||
|
|
|
@ -1005,9 +1005,15 @@ class RootDirectory(AccessControlled, Directory):
|
|||
user = get_user_from_api_query_string() or get_request().user
|
||||
list_categories = []
|
||||
charset = get_publisher().site_charset
|
||||
for category in self.get_categories(user):
|
||||
list_categories.append({'title': unicode(category.name, charset),
|
||||
'url': category.get_url()})
|
||||
categories = self.get_categories(user)
|
||||
Category.sort_by_position(categories)
|
||||
for category in categories:
|
||||
d = {}
|
||||
d['title'] = unicode(category.name, charset)
|
||||
d['url'] = category.get_url()
|
||||
if category.description:
|
||||
d['description'] = unicode(category.description, charset)
|
||||
list_categories.append(d)
|
||||
get_response().set_content_type('application/json')
|
||||
return json.dumps({'data': list_categories})
|
||||
|
||||
|
|
Loading…
Reference in New Issue