[damned-lies] Add a Web API to retrieve last uploaded po file for a module/branch/domain/language



commit 097c0cfe0a7663df22a1afc3d4d12f18d8f8bc41
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Apr 17 21:32:29 2010 +0200

    Add a Web API to retrieve last uploaded po file for a module/branch/domain/language
    
    Fixes bug #615620

 vertimus/urls.py  |    4 ++++
 vertimus/views.py |   16 +++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/vertimus/urls.py b/vertimus/urls.py
index a461d61..2293d03 100644
--- a/vertimus/urls.py
+++ b/vertimus/urls.py
@@ -14,6 +14,10 @@ urlpatterns = patterns('vertimus.views',
         view = 'vertimus_diff',
         name = 'vertimus_diff'),
     url(
+        regex = r'^uploads/(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)/(?P<locale_name>[\w\- ]+)/latest/$',
+        view = 'latest_uploaded_po',
+        name = 'latest_uploaded_po'),
+    url(
         regex = '^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)/(?P<locale_name>[\w\- ]+)/level(?P<level>\d+)/$',
         view = 'vertimus_by_names',
         name = 'vertimus_archives_by_names'),
diff --git a/vertimus/views.py b/vertimus/views.py
index 7cbc0ac..476dd2a 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -21,7 +21,7 @@
 from django.conf import settings
 from django.utils.translation import ugettext as _
 from django.shortcuts import render_to_response, get_object_or_404
-from django.http import HttpResponseRedirect
+from django.http import HttpResponseRedirect, Http404
 from django.template import RequestContext
 from django.core import urlresolvers
 
@@ -199,3 +199,17 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
     }
     return render_to_response('vertimus/vertimus_diff.html', context,
                               context_instance=RequestContext(request))
+
+def latest_uploaded_po(request, module_name, branch_name, domain_name, locale_name):
+    """ Redirect to the latest uploaded po for a module/branch/language """
+    branch = get_object_or_404(Branch, module__name=module_name, name=branch_name)
+    domain = get_object_or_404(Domain, module__name=module_name, name=domain_name)
+    lang   = get_object_or_404(Language, locale=locale_name)
+    latest_upload = ActionDb.objects.filter(state_db__branch=branch,
+                                            state_db__domain=domain,
+                                            state_db__language=lang,
+                                            file__endswith=".po").order_by('-created')[:1]
+    if not latest_upload:
+        raise Http404
+    merged_file = latest_upload[0].get_action().merged_file()
+    return HttpResponseRedirect(merged_file['url'])



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