Commit 277c0316 authored by Michal Čihař's avatar Michal Čihař

Better way for getting context/id

parent f9a8b589
......@@ -27,7 +27,7 @@ from weblate.lang.models import Language
from whoosh import qparser
from util import msg_checksum, get_source, get_target
from util import msg_checksum, get_source, get_target, get_context
from weblate.trans.search import FULLTEXT_INDEX, SOURCE_SCHEMA, TARGET_SCHEMA
......@@ -117,10 +117,10 @@ class UnitManager(models.Manager):
'''
if template is None:
src = get_source(unit)
ctx = unit.getcontext()
ctx = get_context(unit)
else:
src = get_target(template)
ctx = template.getcontext()
ctx = get_context(template)
checksum = msg_checksum(src, ctx)
# Try getting existing unit
......
......@@ -96,6 +96,17 @@ def get_target(unit):
else:
return unit.target
def get_context(unit):
'''
Returns context of message. In some cases we have to use
ID here to make all backends consistent.
'''
if unit is None:
return ''
context = unit.getcontext()
if is_unit_key_value(unit) and context == '':
return unit.getid()
return context
def is_translated(unit):
'''
......
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