Various fixes to backend storing
This commit is contained in:
parent
b9e959f18d
commit
ede1fe5a5c
@ -233,7 +233,7 @@ class Translation(models.Model):
|
|||||||
m = 'Translated using Weblate'
|
m = 'Translated using Weblate'
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_unit(self, request, unit):
|
def update_unit(self, unit, request):
|
||||||
'''
|
'''
|
||||||
Updates backend file and unit.
|
Updates backend file and unit.
|
||||||
'''
|
'''
|
||||||
@ -242,14 +242,17 @@ class Translation(models.Model):
|
|||||||
pounits = store.findunits(src)
|
pounits = store.findunits(src)
|
||||||
for pounit in pounits:
|
for pounit in pounits:
|
||||||
if pounit.getcontext() == unit.context:
|
if pounit.getcontext() == unit.context:
|
||||||
if unit.target != join_plural(unit.target.strings):
|
if unit.target != join_plural(pounit.target.strings):
|
||||||
|
if unit.is_plural():
|
||||||
pounit.settarget(unit.get_target_plurals())
|
pounit.settarget(unit.get_target_plurals())
|
||||||
|
else:
|
||||||
|
pounit.settarget(unit.target)
|
||||||
need_save = True
|
need_save = True
|
||||||
# We should have only one match
|
# We should have only one match
|
||||||
break
|
break
|
||||||
if need_save:
|
if need_save:
|
||||||
store.save()
|
store.save()
|
||||||
self.git_commit()
|
self.git_commit(request)
|
||||||
|
|
||||||
class Unit(models.Model):
|
class Unit(models.Model):
|
||||||
translation = models.ForeignKey(Translation)
|
translation = models.ForeignKey(Translation)
|
||||||
@ -305,11 +308,11 @@ class Unit(models.Model):
|
|||||||
def save_backend(self, request, propagate = True):
|
def save_backend(self, request, propagate = True):
|
||||||
# Store to backend
|
# Store to backend
|
||||||
self.translation.update_unit(self, request)
|
self.translation.update_unit(self, request)
|
||||||
self.save(request)
|
self.save(backend = True)
|
||||||
# Propagate to other projects
|
# Propagate to other projects
|
||||||
if propagate:
|
if propagate:
|
||||||
allunits = Unit.objects.filter(
|
allunits = Unit.objects.filter(
|
||||||
checksum = unit.checksum,
|
checksum = self.checksum,
|
||||||
translation__subproject__project = self.translation.subproject.project,
|
translation__subproject__project = self.translation.subproject.project,
|
||||||
).exclude(id == self.id)
|
).exclude(id == self.id)
|
||||||
for unit in allunits:
|
for unit in allunits:
|
||||||
@ -317,6 +320,8 @@ class Unit(models.Model):
|
|||||||
unit.save_backend(request, False)
|
unit.save_backend(request, False)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not 'request' in kwargs:
|
if not 'backend' in kwargs:
|
||||||
logger.error('Unit.save called without request object: %s', '\n'.join(traceback.format_stack()))
|
logger.error('Unit.save called without backend sync: %s', ''.join(traceback.format_stack()))
|
||||||
|
else:
|
||||||
|
del kwargs['backend']
|
||||||
super(Unit, self).save(*args, **kwargs)
|
super(Unit, self).save(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user