damned-lies r1368 - in trunk: . stats templates/vertimus vertimus
- From: claudep svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1368 - in trunk: . stats templates/vertimus vertimus
- Date: Tue, 20 Jan 2009 14:13:30 +0000 (UTC)
Author: claudep
Date: Tue Jan 20 14:13:30 2009
New Revision: 1368
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1368&view=rev
Log:
2009-01-20 Claude Paroz <claude 2xlibre net>
* stats/models.py: Emit pot_has_changed signal.
* stats/signals.py: Signal emitted by stats app (pot_has_changed).
* templates/vertimus/vertimus_detail.html: Add link to merged file below
original file.
* templates/vertimus/vertimus_diff.html: Add ending note about both files
being merged with latest pot file.
* vertimus/models.py: New functions related to merged files. Implement and
connect signals for merging/updating/deleting merged po files.
* vertimus/views.py: Do the diff with merged files.
Added:
trunk/stats/signals.py
Modified:
trunk/ChangeLog
trunk/stats/models.py
trunk/templates/vertimus/vertimus_detail.html
trunk/templates/vertimus/vertimus_diff.html
trunk/vertimus/models.py
trunk/vertimus/views.py
Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py (original)
+++ trunk/stats/models.py Tue Jan 20 14:13:30 2009
@@ -28,6 +28,7 @@
from django.utils import dateformat
from django.conf import settings
from stats import utils
+from stats import signals
import potdiff
from people.models import Person
@@ -307,6 +308,8 @@
diff = potdiff.diff(previous_pot, potfile)
if not len(diff):
pot_has_changed = False
+ else:
+ signals.pot_has_changed.send(sender=self, potfile=potfile, branch=self, domain=dom)
# 5. Generate pot stats and update DB
# ***********************************
Added: trunk/stats/signals.py
==============================================================================
--- (empty file)
+++ trunk/stats/signals.py Tue Jan 20 14:13:30 2009
@@ -0,0 +1,4 @@
+import django.dispatch
+
+pot_has_changed = django.dispatch.Signal(providing_args=["potfile", "branch", "domain"])
+
Modified: trunk/templates/vertimus/vertimus_detail.html
==============================================================================
--- trunk/templates/vertimus/vertimus_detail.html (original)
+++ trunk/templates/vertimus/vertimus_detail.html Tue Jan 20 14:13:30 2009
@@ -75,6 +75,9 @@
<div class="uploaded_file">
<a href="{{ action.file.url }}"><img src="{{ MEDIA_URL }}img/download.png"/> {{ action.get_filename }}</a><br />
{% if action.has_po_file %}
+ {% if action.merged_file.url %}
+ <a href="{{ action.merged_file.url }}"><img src="{{ MEDIA_URL }}img/download.png"/> {{ action.merged_file.filename }}</a><br />
+ {% endif %}
<div class="right_actions"><a href="{% url vertimus-diff-view action.id %}">diff with previous</a></div>
{% endif %}
</div>
Modified: trunk/templates/vertimus/vertimus_diff.html
==============================================================================
--- trunk/templates/vertimus/vertimus_diff.html (original)
+++ trunk/templates/vertimus/vertimus_diff.html Tue Jan 20 14:13:30 2009
@@ -17,4 +17,5 @@
{{ diff_content|safe }}
+<p><em>{% trans "Note: both files are merged with latest POT file." %}</em></p>
{% endblock %}
Modified: trunk/vertimus/models.py
==============================================================================
--- trunk/vertimus/models.py (original)
+++ trunk/vertimus/models.py Tue Jan 20 14:13:30 2009
@@ -27,8 +27,11 @@
from django.contrib.sites.models import Site
from django.conf import settings
from django.core.files.storage import default_storage
+from django.db.models.signals import post_save, pre_delete
-from stats.models import Branch, Domain
+from stats.models import Branch, Domain, Statistics
+from stats.signals import pot_has_changed
+from stats.utils import run_shell_command
from languages.models import Language
from people.models import Person
@@ -302,6 +305,16 @@
except ActionDb.DoesNotExist:
return None
+ def merge_file_with_pot(self, potfile):
+ """ Merge the uploaded translated file with current pot """
+ if self.file:
+ command = "msgmerge --previous -o %(outpo)s %(pofile)s %(potfile)s" % {
+ 'outpo': self.file.path[:-3] + ".merged.po",
+ 'pofile': self.file.path,
+ 'potfile': potfile
+ }
+ run_shell_command(command)
+
@classmethod
def get_action_history(cls, state_db):
if state_db:
@@ -367,6 +380,17 @@
else:
return None
+ def merged_file(self):
+ """ If available, returns the merged file as a dict: {'url':'path':'filename':} """
+ mfile_url = mfile_path = mfile_name = None
+ if self._action_db.file:
+ mfile_url = self._action_db.file.url[:-3] + ".merged.po"
+ mfile_path = self._action_db.file.path[:-3] + ".merged.po"
+ mfile_name = os.path.basename(mfile_path)
+ if not os.access(mfile_path, os.R_OK):
+ mfile_url = mfile_path = mfile_name = None
+ return {'url': mfile_url, 'path': mfile_path, 'filename': mfile_name}
+
def has_po_file(self):
try:
return self._action_db.file.name[-3:] == ".po"
@@ -638,3 +662,29 @@
return action._new_state()
except:
return StateNone()
+
+def update_uploaded_files(sender, **kwargs):
+ """ Callback to handle pot_file_changed signal """
+ actions = ActionDb.objects.filter(state_db__branch=kwargs['branch'],
+ state_db__domain=kwargs['domain'],
+ file__endswith=".po")
+ for action in actions:
+ action.merge_file_with_pot(potfile=kwargs['potfile'])
+pot_has_changed.connect(update_uploaded_files)
+
+def merge_uploaded_file(sender, instance, **kwargs):
+ """ post_save callback for ActionDb that automatically merge uploaded file with latest pot file """
+ if instance.file and instance.file.path.endswith('.po'):
+ stat = Statistics.objects.get(branch=instance.state_db.branch, domain=instance.state_db.domain, language=None)
+ potfile = stat.po_path()
+ instance.merge_file_with_pot(potfile)
+post_save.connect(merge_uploaded_file, sender=ActionDb)
+
+def delete_merged_file(sender, instance, **kwargs):
+ """ pre_delete callback for ActionDb that deletes the merged file from upload dir """
+ if instance.file and instance.file.path.endswith('.po'):
+ merged_file = instance.file.path[:-3] + ".merged.po"
+ if os.access(merged_file, os.W_OK):
+ os.remove(merged_file)
+pre_delete.connect(delete_merged_file, sender=ActionDb)
+
Modified: trunk/vertimus/views.py
==============================================================================
--- trunk/vertimus/views.py (original)
+++ trunk/vertimus/views.py Tue Jan 20 14:13:30 2009
@@ -115,12 +115,13 @@
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()]
+ file_path1 = action_db1.get_action().merged_file()['path']
+ 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 }
action_db2 = action_db1.get_previous_action_with_po()
if action_db2:
- file_path2 = action_db2.file.path
+ file_path2 = action_db2.get_action().merged_file()['path']
descr2 = _("Uploaded file by %(name)s on %(date)s") % { 'name': action_db2.person.name,
'date': action_db2.created }
else:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]