damned-lies r1357 - in trunk: . media/css templates/vertimus vertimus
- From: claudep svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1357 - in trunk: . media/css templates/vertimus vertimus
- Date: Sat, 17 Jan 2009 22:51:28 +0000 (UTC)
Author: claudep
Date: Sat Jan 17 22:51:28 2009
New Revision: 1357
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1357&view=rev
Log:
2009-01-17 Claude Paroz <claude 2xlibre net>
* media/css/difflib.css: Specific CSS for diff template.
* templates/vertimus/vertimus_detail.html: Add link to diff template just
under po files.
* templates/vertimus/vertimus_diff.html: Show side-by-side diff between
two po files.
* vertimus/models.py: 3 utility methods added for diff functionality.
* vertimus/urls.py: Add URL for diff view.
* vertimus/views.py: Add vertimus_diff view.
Preliminary work for #566060.
Added:
trunk/media/css/difflib.css
trunk/templates/vertimus/vertimus_diff.html
Modified:
trunk/ChangeLog
trunk/templates/vertimus/vertimus_detail.html
trunk/vertimus/models.py
trunk/vertimus/urls.py
trunk/vertimus/views.py
Added: trunk/media/css/difflib.css
==============================================================================
--- (empty file)
+++ trunk/media/css/difflib.css Sat Jan 17 22:51:28 2009
@@ -0,0 +1,7 @@
+table.diff {font-family:Courier; border:medium;}
+.diff_header {background-color:#e0e0e0}
+td.diff_header {text-align:right}
+.diff_next {background-color:#c0c0c0}
+.diff_add {background-color:#aaffaa}
+.diff_chg {background-color:#ffff77}
+.diff_sub {background-color:#ffaaaa}
Modified: trunk/templates/vertimus/vertimus_detail.html
==============================================================================
--- trunk/templates/vertimus/vertimus_detail.html (original)
+++ trunk/templates/vertimus/vertimus_detail.html Sat Jan 17 22:51:28 2009
@@ -73,7 +73,11 @@
<div class="vertimus_action_content">
{% if action.file %}
<div class="uploaded_file">
- <a href="{{ action.file.url }}"><img src="{{ MEDIA_URL }}img/download.png"/> {{ action.get_filename }}</a></div>
+ <a href="{{ action.file.url }}"><img src="{{ MEDIA_URL }}img/download.png"/> {{ action.get_filename }}</a><br />
+ {% if action.has_po_file %}
+ <div class="right_actions"><a href="{% url vertimus-diff-view action.id %}">diff with previous</a></div>
+ {% endif %}
+ </div>
{% endif %}
<p>{% if action.comment %}
{{ action.comment|linebreaksbr }}
Added: trunk/templates/vertimus/vertimus_diff.html
==============================================================================
--- (empty file)
+++ trunk/templates/vertimus/vertimus_diff.html Sat Jan 17 22:51:28 2009
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block title %}
+{% trans "Diff between po files" %}
+{% endblock %}
+
+{% block extrahead %}
+ <link rel="stylesheet" href="{{ MEDIA_URL }}css/difflib.css" />
+{% endblock %}
+
+{% block content %}
+<div class="mainpage">
+
+<h1>{{ state.branch.module.get_description }} - {{ state.branch.name }} - {{ state.domain.get_description }} - {{ state.language.get_name }}</h1>
+<p><a href="{% url vertimus-names-view state.branch.module.name state.branch.name state.domain.name state.language.locale %}">{% trans "<- Back to actions" %}</a></p>
+
+{{ diff_content|safe }}
+
+{% endblock %}
Modified: trunk/vertimus/models.py
==============================================================================
--- trunk/vertimus/models.py (original)
+++ trunk/vertimus/models.py Sat Jan 17 22:51:28 2009
@@ -293,6 +293,15 @@
action._action_db = self
return action
+ def get_previous_action_with_po(self):
+ """ Returns the previous action with an uploaded file related to the same state """
+ try:
+ act = ActionDb.objects.filter(file__endswith=".po", state_db=self.state_db,
+ created__lt=self.created).latest('created')
+ return act.get_action()
+ except ActionDb.DoesNotExist:
+ return None
+
@classmethod
def get_action_history(cls, state_db):
if state_db:
@@ -322,6 +331,10 @@
return [eval('Action' + action_name)() for action_name in ACTION_NAMES]
@property
+ def id(self):
+ return self._action_db.id
+
+ @property
def person(self):
return self._action_db.person
@@ -354,6 +367,12 @@
else:
return None
+ def has_po_file(self):
+ try:
+ return self._action_db.file.name[-3:] == ".po"
+ except:
+ return False
+
def send_mail_new_state(self, old_state, new_state, recipient_list):
# Remove None and empty string items from the list
recipient_list = filter(lambda x: x and x is not None, recipient_list)
Modified: trunk/vertimus/urls.py
==============================================================================
--- trunk/vertimus/urls.py (original)
+++ trunk/vertimus/urls.py Sat Jan 17 22:51:28 2009
@@ -3,5 +3,6 @@
urlpatterns = patterns('vertimus.views',
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'^(?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')
)
Modified: trunk/vertimus/views.py
==============================================================================
--- trunk/vertimus/views.py (original)
+++ trunk/vertimus/views.py Sat Jan 17 22:51:28 2009
@@ -19,6 +19,7 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from datetime import datetime
+from django.utils.translation import ugettext as _
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, Http404
from django.template import RequestContext
@@ -107,4 +108,38 @@
'action_form': action_form
}
return render_to_response('vertimus/vertimus_detail.html', context,
- context_instance=RequestContext(request))
+ context_instance=RequestContext(request))
+
+def vertimus_diff(request, action_id):
+ """ Show a diff between current action po file and previous file """
+ import difflib
+ action_db1 = get_object_or_404(ActionDb, pk=action_id)
+ state = action_db1.state_db
+ content1 = [l.decode('utf-8') for l in open(action_db1.file.path, 'U').readlines()]
+ descr1 = _("Uploaded file by %(name)s on %(date)s") % { 'name': action_db1.person.name,
+ 'date': action_db1.created }
+ action_db2 = action_db1.get_previous_action_with_po()
+ if action_db2:
+ file_path2 = action_db2.file.path
+ descr2 = _("Uploaded file by %(name)s on %(date)s") % { 'name': action_db2.person.name,
+ 'date': action_db2.created }
+ else:
+ # 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()})
+ except Statistics.DoesNotExist:
+ stats = get_object_or_404(Statistics, branch=state.branch, domain=state.domain, language=None)
+ descr2 = _("Latest POT file")
+ file_path2 = stats.po_path()
+ content2 = [l.decode('utf-8') for l in open(file_path2, 'U').readlines()]
+ d = difflib.HtmlDiff()
+ diff_content = d.make_table(content2, content1,
+ descr2, descr1, context=True)
+
+ context = {
+ 'diff_content': diff_content,
+ 'state': state,
+ }
+ return render_to_response('vertimus/vertimus_diff.html', context,
+ context_instance=RequestContext(request))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]