Commit 842137a5 authored by Michal Čihař's avatar Michal Čihař

Move checks definition to separate file and actually do checks

parent 21079844
from django.utils.translation import ugettext_lazy as _
CHECKS = []
def check_same(sources, targets):
if sources[0] == targets[0]:
return True
return False
CHECKS.append(('same', _('Not translated'), check_same))
...@@ -19,6 +19,7 @@ from translate.storage import poheader ...@@ -19,6 +19,7 @@ from translate.storage import poheader
from datetime import datetime from datetime import datetime
import trans import trans
import trans.checks
from trans.managers import TranslationManager, UnitManager from trans.managers import TranslationManager, UnitManager
from util import is_plural, split_plural, join_plural from util import is_plural, split_plural, join_plural
...@@ -530,6 +531,7 @@ class Unit(models.Model): ...@@ -530,6 +531,7 @@ class Unit(models.Model):
logger.error('Unit.save called without backend sync: %s', ''.join(traceback.format_stack())) logger.error('Unit.save called without backend sync: %s', ''.join(traceback.format_stack()))
else: else:
del kwargs['backend'] del kwargs['backend']
self.check()
super(Unit, self).save(*args, **kwargs) super(Unit, self).save(*args, **kwargs)
def get_location_links(self): def get_location_links(self):
...@@ -565,6 +567,29 @@ class Unit(models.Model): ...@@ -565,6 +567,29 @@ class Unit(models.Model):
ignore = False ignore = False
) )
def check(self):
src = self.get_source_plurals()
tgt = self.get_target_plurals()
failing = []
for check in trans.checks.CHECKS:
if check[2](src, tgt):
failing.append(check[0])
for check in self.checks():
if check.check in failing:
failing.remove(check.check)
continue
check.delete()
for check in failing:
Check.objects.create(
checksum = self.checksum,
project = self.translation.subproject.project,
language = self.translation.language,
ignore = False,
check = check
)
class Suggestion(models.Model): class Suggestion(models.Model):
checksum = models.CharField(max_length = 40, default = '', blank = True, db_index = True) checksum = models.CharField(max_length = 40, default = '', blank = True, db_index = True)
target = models.TextField() target = models.TextField()
...@@ -583,9 +608,7 @@ class Suggestion(models.Model): ...@@ -583,9 +608,7 @@ class Suggestion(models.Model):
unit.fuzzy = False unit.fuzzy = False
unit.save_backend(request, False) unit.save_backend(request, False)
CHECK_CHOICES = ( CHECK_CHOICES = [(x[0], x[1]) for x in trans.checks.CHECKS]
('same', ugettext_lazy('Not translated')),
)
class Check(models.Model): class Check(models.Model):
checksum = models.CharField(max_length = 40, default = '', blank = True, db_index = True) checksum = models.CharField(max_length = 40, default = '', blank = True, db_index = True)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment