Commit e54fc89a authored by Michal Čihař's avatar Michal Čihař

Store contentsum with unit (issue #326)

parent a6297625
......@@ -216,6 +216,17 @@ class FileUnit(object):
md5.update(self.get_context().encode('utf-8'))
return md5.hexdigest()
def get_contentsum(self):
'''
Returns checksum of source string and conntext, used for quick lookup.
We use MD5 as it is faster than SHA1.
'''
md5 = hashlib.md5()
md5.update(self.get_source().encode('utf-8'))
md5.update(self.get_context().encode('utf-8'))
return md5.hexdigest()
def is_translated(self):
'''
Checks whether unit is translated.
......
......@@ -379,6 +379,7 @@ class Unit(models.Model):
fuzzy = unit.is_fuzzy()
translated = unit.is_translated()
previous_source = unit.get_previous_source()
contentsum = unit.get_contentsum()
# Monolingual files handling
if unit.template is not None:
......@@ -412,6 +413,7 @@ class Unit(models.Model):
translated == self.translated and
comment == self.comment and
pos == self.position and
contentsum == self.contentsum and
previous_source == self.previous_source):
return
......@@ -424,6 +426,7 @@ class Unit(models.Model):
self.fuzzy = fuzzy
self.translated = translated
self.comment = comment
self.contentsum = contentsum
self.previous_source = previous_source
self.save(
force_insert=created,
......
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