[damned-lies] Add some more xml/json interfaces
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Add some more xml/json interfaces
- Date: Wed, 29 Sep 2010 20:05:11 +0000 (UTC)
commit c2acaebe42ac84b690736399d407f31ff37006f4
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Sep 29 22:03:43 2010 +0200
Add some more xml/json interfaces
XML/JSON APIs are currently documented on:
http://live.gnome.org/DamnedLies
stats/views.py | 33 +++++++++++++++++----------------
teams/urls.py | 2 +-
teams/views.py | 4 ++--
urls.py | 2 +-
4 files changed, 21 insertions(+), 20 deletions(-)
---
diff --git a/stats/views.py b/stats/views.py
index 8421526..f2a38c9 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -34,8 +34,11 @@ from stats.forms import ModuleBranchForm
from stats import utils
from languages.models import Language
-def modules(request):
+def modules(request, format='html'):
all_modules = Module.objects.all()
+ if format in ('json', 'xml'):
+ data = serializers.serialize(format, all_modules)
+ return HttpResponse(data, mimetype=MIME_TYPES[format])
context = {
'pageSection': "module",
'modules': utils.sort_object_list(all_modules, 'get_description'),
@@ -226,28 +229,26 @@ def releases(request, format='html'):
old_releases = Release.objects.filter(weight__lt=0).order_by('status', '-weight', '-name')
if format in ('json', 'xml'):
from itertools import chain
- data = serializers.serialize(format, chain(active_releases, old_releases))
+ data = serializers.serialize(format, itertools.chain(active_releases, old_releases))
return HttpResponse(data, mimetype=MIME_TYPES[format])
- else:
- context = {
- 'pageSection' : "releases",
- 'active_releases': active_releases,
- 'old_releases' : old_releases,
- 'bug_url' : settings.ENTER_BUG_URL,
- }
- return render_to_response('release_list.html', context, context_instance=RequestContext(request))
+ context = {
+ 'pageSection' : "releases",
+ 'active_releases': active_releases,
+ 'old_releases' : old_releases,
+ 'bug_url' : settings.ENTER_BUG_URL,
+ }
+ return render_to_response('release_list.html', context, context_instance=RequestContext(request))
def release(request, release_name, format='html'):
release = get_object_or_404(Release, name=release_name)
if format == 'xml':
return render_to_response('release_detail.xml', { 'release' : release },
mimetype=MIME_TYPES[format])
- else:
- context = {
- 'pageSection': "releases",
- 'release': release
- }
- return render_to_response('release_detail.html', context, context_instance=RequestContext(request))
+ context = {
+ 'pageSection': "releases",
+ 'release': release
+ }
+ return render_to_response('release_detail.html', context, context_instance=RequestContext(request))
def compare_by_releases(request, dtype, rels_to_compare):
releases = []
diff --git a/teams/urls.py b/teams/urls.py
index d0f02c6..292c130 100644
--- a/teams/urls.py
+++ b/teams/urls.py
@@ -12,7 +12,7 @@ info_dict = {
urlpatterns = patterns('',
url(
- regex = r'^$',
+ regex = r'^(?P<format>(xml))?/?$',
view = 'teams.views.teams',
name = 'teams'),
url(
diff --git a/teams/views.py b/teams/views.py
index 8c173ff..0aaf7d5 100644
--- a/teams/views.py
+++ b/teams/views.py
@@ -30,9 +30,9 @@ from teams.models import Team, FakeTeam, Role
from teams.forms import EditMemberRoleForm, EditTeamDetailsForm
from languages.models import Language
-def teams(request):
+def teams(request, format='html'):
teams = Team.objects.all_with_coordinator()
- format = request.GET.get('format', 'html')
+ format = request.GET.get('format') or format
if format == 'xml':
return render_to_response(
'teams/team_list.xml',
diff --git a/urls.py b/urls.py
index e83db7c..a3f5d03 100644
--- a/urls.py
+++ b/urls.py
@@ -53,7 +53,7 @@ urlpatterns = patterns('',
urlpatterns += patterns('stats.views',
url(
- regex = r'^module/$',
+ regex = r'^module/(?P<format>(html|json|xml))?/?$',
view = 'modules',
name = 'modules'),
url(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]