Migrated same solution to ocr queue transformation too
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
from ast import literal_eval
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from documents.models import Document
|
||||
from converter.api import get_available_transformations_choices
|
||||
@@ -59,6 +62,27 @@ class QueueDocument(models.Model):
|
||||
return ugettext(u'Missing document.')
|
||||
|
||||
|
||||
class ArgumentsValidator(object):
|
||||
message = _(u'Enter a valid value.')
|
||||
code = 'invalid'
|
||||
|
||||
def __init__(self, message=None, code=None):
|
||||
if message is not None:
|
||||
self.message = message
|
||||
if code is not None:
|
||||
self.code = code
|
||||
|
||||
def __call__(self, value):
|
||||
"""
|
||||
Validates that the input evaluates correctly.
|
||||
"""
|
||||
value = value.strip()
|
||||
try:
|
||||
literal_eval(value)
|
||||
except (ValueError, SyntaxError):
|
||||
raise ValidationError(self.message, code=self.code)
|
||||
|
||||
|
||||
class QueueTransformation(models.Model):
|
||||
"""
|
||||
Model that stores the transformation and transformation arguments
|
||||
@@ -69,7 +93,7 @@ class QueueTransformation(models.Model):
|
||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||
order = models.PositiveIntegerField(default=0, blank=True, null=True, verbose_name=_(u'order'), db_index=True)
|
||||
transformation = models.CharField(choices=get_available_transformations_choices(), 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: %s') % u'{\'degrees\':90}')
|
||||
arguments = models.TextField(blank=True, null=True, verbose_name=_(u'arguments'), help_text=_(u'Use dictionaries to indentify arguments, example: %s') % u'{\'degrees\':90}', validators=[ArgumentsValidator()])
|
||||
|
||||
objects = QueueTransformationManager()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user