Commit e9ae0daa authored by Marcos Chavarría Teijeiro's avatar Marcos Chavarría Teijeiro Committed by Claude Paroz

Add list of teams JSON interface

Fixes bug #719663.
parent d3587371
......@@ -163,6 +163,52 @@ class TeamTest(TeamsAndRolesTests):
team = Team.objects.get(name='fr')
self.assertEquals(team.webpage_url, u"http://www.gnomefr.org/")
class JSONTeamsTest(TeamsAndRolesTests):
def setUp(self):
super(JSONTeamsTest, self).setUp()
t3 = Team.objects.create(name='gl', description='Galician')
coor1 = Person.objects.create(first_name='Marcos', last_name='Coordinator',
email='marc@imthebigboss.fr', username='marcos', svn_account='thesvnaccount')
coor2 = Person.objects.create(first_name='Pepe', last_name='Coordinator',
email='pepe@imthebigboss.es', username='pepe')
Role.objects.create(team=t3, person=coor1, role='coordinator')
Role.objects.create(team=t3, person=coor2, role='coordinator')
def test_json_teams(self):
"""Test JSON teams interface"""
c = Client()
response = c.get(reverse('teams', args=['json']))
self.assertEqual(response.status_code, 200)
expected_JSON = """[
{
"id":"fr",
"description":"French",
"coordinators": [
{
"name":"John Coordinator"
}]
},
{
"id":"gl",
"description":"Galician",
"coordinators": [
{
"name":"Marcos Coordinator",
"vcs":"thesvnaccount"
},
{
"name":"Pepe Coordinator"
}
]
},
{
"id":"pt",
"description":"Portuguese",
"coordinators": []
}
]"""
self.assertJSONEqual(response.content, expected_JSON)
class RoleTest(TeamsAndRolesTests):
......
......@@ -3,7 +3,7 @@ from django.conf.urls import patterns, url
urlpatterns = patterns('teams.views',
url(
regex = r'^(?P<format>(xml))?/?$',
regex = r'^(?P<format>(xml|json))?/?$',
view = 'teams',
name = 'teams'),
url(
......
......@@ -32,8 +32,8 @@ from languages.models import Language
def teams(request, format='html'):
teams = Team.objects.all_with_coordinator()
format = request.GET.get('format') or format
if format == 'xml':
return render(request, 'teams/team_list.xml', { 'teams' : teams },
if format in ('xml', 'json'):
return render(request, 'teams/team_list.%s' % format, {'teams': teams},
content_type=utils.MIME_TYPES[format]
)
else:
......
[{% for team in teams %}
{
"id":"{{ team.name }}",
"description":"{{ team.description }}",
"coordinators": [{% for coordinator in team.get_coordinators %}
{
"name":"{{ coordinator.name }}"{% if coordinator.svn_account %},
"vcs":"{{ coordinator.svn_account }}"{% endif %}
}{% if not forloop.last %},
{% endif %}{% endfor %}]
}{% if not forloop.last %},{% endif %}{% endfor %}
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment