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

Move checksum calculation to Unit class

parent 00e58d18
......@@ -27,6 +27,7 @@ from translate.storage import factory
from trans.util import get_source, get_string
from translate.misc import quote
import re
import hashlib
import importlib
import __builtin__
......@@ -145,6 +146,17 @@ class FileUnit(object):
return self.mainunit.getid()
return context
def get_checksum(self):
'''
Returns checksum of source string, 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.
......
......@@ -48,11 +48,10 @@ class UnitManager(models.Manager):
'''
Process translation toolkit unit and stores/updates database entry.
'''
# Get basic unit data
src = unit.get_source()
ctx = unit.get_context()
# TODO: move to unit
checksum = msg_checksum(src, ctx)
checksum = unit.get_checksum()
# Try getting existing unit
dbunit = None
......
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