damned-lies r1401 - in trunk: . templates/vertimus vertimus



Author: claudep
Date: Tue Jan 27 08:30:30 2009
New Revision: 1401
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1401&view=rev

Log:
2009-01-27  Claude Paroz  <claude 2xlibre net>

	* templates/vertimus/vertimus_detail.html: Show the various diff links for
	each po file.
	* vertimus/models.py: get_action_history also build a file history
	attached with each action with a po file. Return now a list of tuples.
	* vertimus/urls.py: Optionally accept the action id of the second diff
	parameter.
	* vertimus/views.py: Handle the optionally action_id2 parameter.
	Fixes bug #568772.

Modified:
   trunk/ChangeLog
   trunk/templates/vertimus/vertimus_detail.html
   trunk/vertimus/models.py
   trunk/vertimus/urls.py
   trunk/vertimus/views.py

Modified: trunk/templates/vertimus/vertimus_detail.html
==============================================================================
--- trunk/templates/vertimus/vertimus_detail.html	(original)
+++ trunk/templates/vertimus/vertimus_detail.html	Tue Jan 27 08:30:30 2009
@@ -64,7 +64,7 @@
 {% if action_history %}
 <h2>{% trans "Action History" %}</h2>
 <div>
-  {% for action in action_history %}
+  {% for action,files in action_history %}
   <div class="vertimus_action">
     <div class="vertimus_action_head">
       <img src="{{ MEDIA_URL }}img/nobody-16.png" alt="Person"/> <a href="{{ action.person.get_absolute_url }}">{{ action.person.name }}</a>
@@ -78,7 +78,11 @@
           {% if action.merged_file.url %}
             <a href="{{ action.merged_file.url }}"><img src="{{ MEDIA_URL }}img/download.png"/>&nbsp;{{ action.merged_file.filename }}</a><br />
           {% endif %}
-          <div class="right_actions"><a href="{% url vertimus-diff-view action.id %}">diff with previous</a></div>
+          <div class="right_actions">{% trans "diff with:" %}
+            {% for f in files %}
+                <a href="{% url vertimus-diff-view action.id,f.action %}" title="{{ f.title }}">[{{ forloop.revcounter }}]</a>
+            {% endfor %}
+          </div>
         {% endif %}
       </div>
       {% endif %}

Modified: trunk/vertimus/models.py
==============================================================================
--- trunk/vertimus/models.py	(original)
+++ trunk/vertimus/models.py	Tue Jan 27 08:30:30 2009
@@ -319,11 +319,20 @@
 
     @classmethod
     def get_action_history(cls, state_db):
+        """ Return action history as a list of tuples (action, file_history)
+            File_history is a list of previous po files, used in vertimus view to generate diff links """
+        history = []
         if state_db:
-            return [va_db.get_action() for va_db in ActionDb.objects.filter(
-                    state_db__id=state_db.id).order_by('id')]
-        else:
-            return []
+            file_history = [{'action':0, 'title': ugettext("File in repository")}]
+            for va_db in ActionDb.objects.filter(state_db__id=state_db.id).order_by('id'):
+                history.append((va_db.get_action(), list(file_history)))
+                if va_db.file and va_db.file.path.endswith('.po'):
+                    file_history.insert(0, {'action':va_db.id,
+                                            'title': ugettext("Uploaded file by %(name)s on %(date)s") % { 
+                                                                'name': va_db.person.name,
+                                                                'date': va_db.created },
+                                           })
+        return history
 
     def __unicode__(self):
         return "%s (%s)" % (self.name, self.id)

Modified: trunk/vertimus/urls.py
==============================================================================
--- trunk/vertimus/urls.py	(original)
+++ trunk/vertimus/urls.py	Tue Jan 27 08:30:30 2009
@@ -4,5 +4,5 @@
     url(r'^(?P<stats_id>\d+)/(?P<lang_id>\d+)$', 'vertimus_by_stats_id', name='vertimus-stats-id-view'),
     url(r'^(?P<branch_id>\d+)/(?P<domain_id>\d+)/(?P<language_id>\d+)', 'vertimus_by_ids', name='vertimus-ids-view'),
     url(r'^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w\-]+)/(?P<locale_name>[\w\- ]+)', 'vertimus_by_names', name='vertimus-names-view'),
-    url(r'^diff/(?P<action_id>\d+)$', 'vertimus_diff', name='vertimus-diff-view')
+    url(r'^diff/(?P<action_id>\d+)/(?P<action_id2>\d+)?$', 'vertimus_diff', name='vertimus-diff-view')
 )

Modified: trunk/vertimus/views.py
==============================================================================
--- trunk/vertimus/views.py	(original)
+++ trunk/vertimus/views.py	Tue Jan 27 08:30:30 2009
@@ -110,7 +110,7 @@
     return render_to_response('vertimus/vertimus_detail.html', context,
                               context_instance=RequestContext(request))
 
-def vertimus_diff(request, action_id):
+def vertimus_diff(request, action_id, action_id2=None):
     """ Show a diff between current action po file and previous file """
     import difflib
     action_db1 = get_object_or_404(ActionDb, pk=action_id)
@@ -121,13 +121,15 @@
     content1 = [l.decode('utf-8') for l in open(file_path1, 'U').readlines()]
     descr1 = _("Uploaded file by %(name)s on %(date)s") % { 'name': action_db1.person.name,
                                                             'date': action_db1.created }
-    action2 = action_db1.get_previous_action_with_po()
-    if action2:
-        file_path2 = action2.merged_file()['path']
-        descr2 = _("Uploaded file by %(name)s on %(date)s") % { 'name': action2.person.name,
-                                                                'date': action2.created }
-    else:
-        # The file should be the more recently committed file (merged)
+    if action_id2 is None:
+        # Search previous in action history
+        action2 = action_db1.get_previous_action_with_po()
+        if action2:
+            file_path2 = action2.merged_file()['path']
+            descr2 = _("Uploaded file by %(name)s on %(date)s") % { 'name': action2.person.name,
+                                                                    'date': action2.created }
+    if action_id2 == "0" or (not action_id2 and not action2):
+         # The file should be the more recently committed file (merged)
         try:
             stats = Statistics.objects.get(branch=state.branch, domain=state.domain, language=state.language)
             descr2 = _("Latest committed file for %(lang)s" % {'lang': state.language.get_name()})
@@ -135,6 +137,12 @@
             stats = get_object_or_404(Statistics, branch=state.branch, domain=state.domain, language=None)
             descr2 = _("Latest POT file")
         file_path2 = stats.po_path()
+    else:
+        # id2 specified in url
+        action2 = ActionDb.objects.get(id=action_id2)
+        file_path2 = action2.file.path
+        descr2 = _("Uploaded file by %(name)s on %(date)s") % { 'name': action2.person.name,
+                                                                'date': action2.created }
     content2 = [l.decode('utf-8') for l in open(file_path2, 'U').readlines()]
     d = difflib.HtmlDiff()
     diff_content = d.make_table(content2, content1,



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