[damned-lies/wip/afranke/api] Add XML/JSON API for a given module
- From: Alexandre Franke <afranke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies/wip/afranke/api] Add XML/JSON API for a given module
- Date: Thu, 4 Aug 2016 17:47:36 +0000 (UTC)
commit 97e07367c626744ec51c7e127096e9f378490002
Author: Alexandre Franke <alexandre franke gmail com>
Date: Thu Aug 4 19:47:01 2016 +0200
Add XML/JSON API for a given module
damnedlies/urls.py | 2 +-
stats/views.py | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/damnedlies/urls.py b/damnedlies/urls.py
index ba7ad51..3f65350 100644
--- a/damnedlies/urls.py
+++ b/damnedlies/urls.py
@@ -65,7 +65,7 @@ urlpatterns += [
url(r'^module/po/(?P<module_name>[\w\-\+]+)/(?P<domain>[\w~\-]+)/(?P<branch_name>[\w\-\.]+)/(?P<filename>.*)$',
stats_views.dynamic_po,
name='dynamic_po'),
- url(r'^module/(?P<module_name>[\w\-\+]+)/$',
+ url(r'^module/(?P<module_name>[\w\-\+]+)/(?P<format>(html|json|xml))?/?$',
stats_views.module,
name='module'),
url(r'^module/(?P<module_name>[\w\-\+]+)/edit/branches/$',
diff --git a/stats/views.py b/stats/views.py
index b62cdff..380d001 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -48,7 +48,7 @@ def modules(request, format='html'):
return render(request, 'module_list.html', context)
-def module(request, module_name):
+def module(request, module_name, format='html'):
mod = get_object_or_404(Module, name=module_name)
branches = sorted(mod.branch_set.all())
if request.user.is_authenticated():
@@ -59,6 +59,9 @@ def module(request, module_name):
branch.get_ui_stats(mandatory_langs=langs)
branch.get_doc_stats(mandatory_langs=langs)
+ if format in ('json', 'xml'):
+ data = serializers.serialize(format, branches)
+ return HttpResponse(data, content_type=MIME_TYPES[format])
context = {
'pageSection': "module",
'module': mod,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]