Refactored the converter backend system
This commit is contained in:
@@ -12,16 +12,13 @@ from python_magic import magic
|
||||
from taggit.managers import TaggableManager
|
||||
from dynamic_search.api import register
|
||||
from converter.api import get_page_count
|
||||
from converter import TRANFORMATION_CHOICES
|
||||
from converter.api import backend
|
||||
|
||||
from documents.conf.settings import CHECKSUM_FUNCTION
|
||||
from documents.conf.settings import UUID_FUNCTION
|
||||
from documents.conf.settings import STORAGE_BACKEND
|
||||
from documents.conf.settings import AVAILABLE_TRANSFORMATIONS
|
||||
from documents.managers import RecentDocumentManager
|
||||
|
||||
available_transformations = ([(name, data['label']) for name, data in AVAILABLE_TRANSFORMATIONS.items()])
|
||||
|
||||
|
||||
def get_filename_from_uuid(instance, filename):
|
||||
"""
|
||||
@@ -263,20 +260,7 @@ class DocumentPage(models.Model):
|
||||
return ('document_page_view', [self.pk])
|
||||
|
||||
def get_transformation_string(self):
|
||||
transformation_list = []
|
||||
warnings = []
|
||||
for page_transformation in self.documentpagetransformation_set.all():
|
||||
try:
|
||||
if page_transformation.transformation in TRANFORMATION_CHOICES:
|
||||
transformation_list.append(
|
||||
TRANFORMATION_CHOICES[page_transformation.transformation] % eval(
|
||||
page_transformation.arguments
|
||||
)
|
||||
)
|
||||
except Exception, e:
|
||||
warnings.append(e)
|
||||
|
||||
return u' '.join(transformation_list), warnings
|
||||
return backend.get_transformation_string(self.documentpagetransformation_set.values('transformation', 'arguments'))
|
||||
|
||||
|
||||
class DocumentPageTransformation(models.Model):
|
||||
@@ -286,7 +270,7 @@ class DocumentPageTransformation(models.Model):
|
||||
"""
|
||||
document_page = models.ForeignKey(DocumentPage, verbose_name=_(u'document page'))
|
||||
order = models.PositiveIntegerField(default=0, blank=True, null=True, verbose_name=_(u'order'), db_index=True)
|
||||
transformation = models.CharField(choices=available_transformations, max_length=128, verbose_name=_(u'transformation'))
|
||||
transformation = models.CharField(choices=backend.get_available_transformations_labels(), max_length=128, verbose_name=_(u'transformation'))
|
||||
arguments = models.TextField(blank=True, null=True, verbose_name=_(u'arguments'), help_text=_(u'Use dictionaries to indentify arguments, example: {\'degrees\':90}'))
|
||||
|
||||
def __unicode__(self):
|
||||
|
||||
Reference in New Issue
Block a user