Load the converter class on demand
Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -12,10 +12,11 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.converter import (
|
||||
BaseTransformation, TransformationResize, TransformationRotate,
|
||||
TransformationZoom, converter_class
|
||||
TransformationZoom
|
||||
)
|
||||
from mayan.apps.converter.literals import DEFAULT_ROTATION, DEFAULT_ZOOM_LEVEL
|
||||
from mayan.apps.converter.models import Transformation
|
||||
from mayan.apps.converter.utils import get_converter_class
|
||||
|
||||
from ..managers import DocumentPageManager
|
||||
from ..settings import (
|
||||
@@ -67,7 +68,7 @@ class DocumentPage(models.Model):
|
||||
|
||||
def detect_orientation(self):
|
||||
with self.document_version.open() as file_object:
|
||||
converter = converter_class(
|
||||
converter = get_converter_class()(
|
||||
file_object=file_object,
|
||||
mime_type=self.document_version.mimetype
|
||||
)
|
||||
@@ -198,7 +199,7 @@ class DocumentPage(models.Model):
|
||||
cache_file = self.cache_partition.get_file(filename=cache_filename)
|
||||
if not setting_disable_base_image_cache.value and cache_file:
|
||||
logger.debug('Page cache file "%s" found', cache_filename)
|
||||
converter = converter_class(
|
||||
converter = get_converter_class()(
|
||||
file_object=cache_file.open()
|
||||
)
|
||||
|
||||
@@ -206,7 +207,7 @@ class DocumentPage(models.Model):
|
||||
else:
|
||||
logger.debug('Page cache file "%s" not found', cache_filename)
|
||||
|
||||
converter = converter_class(
|
||||
converter = get_converter_class()(
|
||||
file_object=self.document_version.get_intermidiate_file()
|
||||
)
|
||||
converter.seek(page_number=self.page_number - 1)
|
||||
|
||||
@@ -11,9 +11,10 @@ from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.converter import TransformationRotate, converter_class
|
||||
from mayan.apps.converter import TransformationRotate
|
||||
from mayan.apps.converter.exceptions import InvalidOfficeFormat, PageCountError
|
||||
from mayan.apps.converter.models import Transformation
|
||||
from mayan.apps.converter.utils import get_converter_class
|
||||
from mayan.apps.mimetype.api import get_mimetype
|
||||
|
||||
from ..events import event_document_new_version, event_document_version_revert
|
||||
@@ -200,7 +201,7 @@ class DocumentVersion(models.Model):
|
||||
logger.debug('Intermidiate file not found.')
|
||||
|
||||
try:
|
||||
converter = converter_class(file_object=self.open())
|
||||
converter = get_converter_class()(file_object=self.open())
|
||||
pdf_file_object = converter.to_pdf()
|
||||
|
||||
with self.cache_partition.create_file(filename='intermediate_file') as file_object:
|
||||
@@ -419,7 +420,7 @@ class DocumentVersion(models.Model):
|
||||
def update_page_count(self, save=True):
|
||||
try:
|
||||
with self.open() as file_object:
|
||||
converter = converter_class(
|
||||
converter = get_converter_class()(
|
||||
file_object=file_object, mime_type=self.mimetype
|
||||
)
|
||||
detected_pages = converter.get_page_count()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from mayan.apps.converter import converter_class
|
||||
from mayan.apps.converter.utils import get_converter_class
|
||||
|
||||
|
||||
class OCRBackendBase(object):
|
||||
@@ -10,7 +10,7 @@ class OCRBackendBase(object):
|
||||
if not transformations:
|
||||
transformations = []
|
||||
|
||||
self.converter = converter_class(file_object=file_object)
|
||||
self.converter = get_converter_class()(file_object=file_object)
|
||||
|
||||
for transformation in transformations:
|
||||
self.converter.transform(transformation=transformation)
|
||||
|
||||
@@ -13,7 +13,8 @@ from django.urls import reverse
|
||||
from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||
from django.utils.six.moves.urllib.parse import quote_plus, unquote_plus
|
||||
|
||||
from mayan.apps.converter import TransformationResize, converter_class
|
||||
from mayan.apps.converter import TransformationResize
|
||||
from mayan.apps.converter.utils import get_converter_class
|
||||
|
||||
from .storages import storage_staging_file_image_cache
|
||||
|
||||
@@ -143,7 +144,7 @@ class StagingFile(object):
|
||||
|
||||
try:
|
||||
file_object = open(self.get_full_path(), mode='rb')
|
||||
converter = converter_class(file_object=file_object)
|
||||
converter = get_converter_class()(file_object=file_object)
|
||||
|
||||
page_image = converter.get_page()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user