|
@ -48,16 +48,21 @@ class Converter(models.AbstractModel): |
|
|
@api.model |
|
|
@api.model |
|
|
def convert(self, filename, content, format="pdf", recompute=False, store=True): |
|
|
def convert(self, filename, content, format="pdf", recompute=False, store=True): |
|
|
binary_content = base64.b64decode(content) |
|
|
binary_content = base64.b64decode(content) |
|
|
|
|
|
output = self.convert_raw(filename, content, format=format, recompute=recompute, store=store) |
|
|
|
|
|
return base64.b64encode(output) |
|
|
|
|
|
|
|
|
|
|
|
@api.model |
|
|
|
|
|
def convert_raw(self, filename, binary_content, format="pdf", recompute=False, store=True): |
|
|
checksum = hashlib.sha1(binary_content).hexdigest() |
|
|
checksum = hashlib.sha1(binary_content).hexdigest() |
|
|
stored = self._retrieve(checksum, format) |
|
|
stored = self._retrieve(checksum, format) |
|
|
if not recompute and stored.exists(): |
|
|
if not recompute and stored.exists(): |
|
|
return base64.b64encode(stored.content) |
|
|
|
|
|
|
|
|
return stored.content |
|
|
else: |
|
|
else: |
|
|
name = "%s.%s" % (filename, format) |
|
|
name = "%s.%s" % (filename, format) |
|
|
output = self._parse(filename, binary_content, format) |
|
|
output = self._parse(filename, binary_content, format) |
|
|
if store: |
|
|
if store: |
|
|
self._store(checksum, name, output, format, stored) |
|
|
self._store(checksum, name, output, format, stored) |
|
|
return base64.b64encode(output) |
|
|
|
|
|
|
|
|
return output |
|
|
|
|
|
|
|
|
#---------------------------------------------------------- |
|
|
#---------------------------------------------------------- |
|
|
# Helper |
|
|
# Helper |
|
|