[damned-lies] DRY on MIME_TYPES list



commit 908e70a30c3481f801b45adff1ba8b13d878a9ed
Author: Stéphane Raimbault <stephane raimbault gmail com>
Date:   Fri Jul 31 01:59:13 2009 +0200

    DRY on MIME_TYPES list
    
    Shared between stats and teams apps through common.utils

 common/utils.py               |    5 +++++
 stats/views.py                |    7 +++----
 teams/views.py                |   10 ++++------
 templates/teams/team_list.xml |    2 +-
 4 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/common/utils.py b/common/utils.py
index 5af08ca..17220d5 100644
--- a/common/utils.py
+++ b/common/utils.py
@@ -21,6 +21,11 @@
 
 from django.utils.translation import ugettext as _
 
+MIME_TYPES = {
+    'json': 'application/json',
+    'xml':  'text/xml'
+}
+
 def trans_sort_object_list(lst, tr_field):
     """Sort an object list with translated_name"""
     for l in lst:
diff --git a/stats/views.py b/stats/views.py
index e5d727f..1305633 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -28,14 +28,12 @@ from django.http import HttpResponse, Http404
 from django.template import RequestContext
 from django.utils.translation import ugettext as _
 
+from common.utils import MIME_TYPES
 from stats.models import Statistics, Module, Branch, Category, Release
 from stats.forms import ModuleBranchForm
 from stats import utils
 from languages.models import Language
 
-MIME_TYPES = {'json': 'application/json',
-              'xml':  'text/xml'
-             }
 def modules(request):
     all_modules = Module.objects.all()
     context = {
@@ -225,7 +223,8 @@ def releases(request, format='html'):
 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])
+        return render_to_response('release_detail.xml', { 'release' : release },
+                                  mimetype=MIME_TYPES[format])
     else:
         context = {
             'pageSection': "releases",
diff --git a/teams/views.py b/teams/views.py
index 99b561a..fcde33c 100644
--- a/teams/views.py
+++ b/teams/views.py
@@ -27,9 +27,6 @@ from teams.models import Team, FakeTeam, Role
 from teams.forms import EditMemberRoleForm
 from languages.models import Language
 
-MIME_TYPES = {'json': 'application/json',
-              'xml':  'text/xml'
-             }
 def teams(request):
     teams = Team.objects.all_with_coordinator()
     format = request.GET.get('format', 'html')
@@ -38,14 +35,15 @@ def teams(request):
             'teams/team_list.xml',
             { 'teams' : teams },
             context_instance=RequestContext(request),
-            mimetype=MIME_TYPES[format]
-        )
+            mimetype=utils.MIME_TYPES[format]
+            )
     else:
         context = {
             'pageSection': 'teams',
             'teams': utils.trans_sort_object_list(teams, 'description')
         }
-        return render_to_response('teams/team_list.html', context, context_instance=RequestContext(request))
+        return render_to_response('teams/team_list.html', context,
+                                  context_instance=RequestContext(request))
 
 def team(request, team_slug):
     try:
diff --git a/templates/teams/team_list.xml b/templates/teams/team_list.xml
index e85ae62..2c92394 100644
--- a/templates/teams/team_list.xml
+++ b/templates/teams/team_list.xml
@@ -1,6 +1,6 @@
 <teams>
   {% for team in teams %}
-  <team id="{{ team.name}}">
+  <team id="{{ team.name }}">
     {% with team.get_coordinator as coordinator %}
     <description>{{ team.description }}</description>
     {% if coordinator and coordinator.svn_account %}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]