From 4a1eb36027b1a188df846b5ab370c2c0673794b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 28 Feb 2012 15:12:41 +0100 Subject: [PATCH] Keep ordering from po file --- trans/managers.py | 4 ++-- trans/models.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/trans/managers.py b/trans/managers.py index f1dedff19..ef7b3b41f 100644 --- a/trans/managers.py +++ b/trans/managers.py @@ -17,7 +17,7 @@ class TranslationManager(models.Manager): trans.update_from_blob(blob) class UnitManager(models.Manager): - def update_from_unit(self, translation, unit): + def update_from_unit(self, translation, unit, pos): ''' Process translation toolkit unit and stores/updates database entry. ''' @@ -38,7 +38,7 @@ class UnitManager(models.Manager): context = ctx) force = True - dbunit.update_from_unit(unit, force) + dbunit.update_from_unit(unit, pos, force) return dbunit def filter_type(self, rqtype): diff --git a/trans/models.py b/trans/models.py index 368f0baa1..db724fe56 100644 --- a/trans/models.py +++ b/trans/models.py @@ -211,10 +211,10 @@ class Translation(models.Model): # Load po file store = self.get_store() - for unit in store.units: + for pos, unit in enumerate(store.units): if unit.istranslatable(): continue - newunit = Unit.objects.update_from_unit(self, unit) + newunit = Unit.objects.update_from_unit(self, unit, pos) try: oldunits.remove(newunit.id) except: @@ -296,18 +296,23 @@ class Unit(models.Model): target = models.TextField(default = '', blank = True) fuzzy = models.BooleanField(default = False, db_index = True) translated = models.BooleanField(default = False, db_index = True) + position = models.IntegerField(db_index = True) objects = UnitManager() - def update_from_unit(self, unit, force): + class Meta: + ordering = ['position'] + + def update_from_unit(self, unit, pos, force): location = ', '.join(unit.getlocations()) flags = ', '.join(unit.typecomments) target = join_plural(unit.target.strings) fuzzy = unit.isfuzzy() translated = unit.istranslated() comment = unit.getnotes() - if not force and location == self.location and flags == self.flags and target == self.target and fuzzy == self.fuzzy and translated == self.translated and comment == self.comment: + if not force and location == self.location and flags == self.flags and target == self.target and fuzzy == self.fuzzy and translated == self.translated and comment == self.comment and pos == self.position: return + self.position = pos self.location = location self.flags = flags self.target = target