Check whether database cache is up to date before saving

This commit is contained in:
Michal Čihař 2012-02-29 13:54:54 +01:00
parent f4ad31c211
commit 5db6b3e288
2 changed files with 8 additions and 0 deletions

View File

@ -207,6 +207,13 @@ class Translation(models.Model):
def get_store(self):
return factory.getobject(os.path.join(self.subproject.get_path(), self.filename))
def check_sync(self):
'''
Checks whether database is in sync with git and possibly does update.
'''
blob = self.get_git_blob()
self.update_from_blob(blob)
def update_from_blob(self, blob, force = False):
'''
Updates translation data from blob.

View File

@ -54,6 +54,7 @@ def translate(request, project, subproject, lang):
if request.method == 'POST':
form = TranslationForm(request.POST)
if form.is_valid():
obj.check_sync()
unit = Unit.objects.get(checksum = form.cleaned_data['checksum'], translation = obj)
unit.target = form.cleaned_data['target']
unit.fuzzy = form.cleaned_data['fuzzy']