From 9cb57582458911b4efb3d1b668375b8193771a26 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 18 Jan 2017 02:35:14 -0400 Subject: [PATCH] Add 3 new "prepared" transformations: Rotate 90, 180 and 270 degrees. Sort transformation list. --- docs/releases/2.2.rst | 3 ++ mayan/apps/converter/classes.py | 60 ++++++++++++++++++++++++++------ mayan/apps/converter/managers.py | 9 ++++- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/docs/releases/2.2.rst b/docs/releases/2.2.rst index c5dcb89214..25a02c054e 100644 --- a/docs/releases/2.2.rst +++ b/docs/releases/2.2.rst @@ -50,6 +50,9 @@ Other changes - Make the lock_manager.backends.file_lock.FileLock the new default locking backend. - Add view to clone a document page transformation to other pages. - Document page transformation navigation bug fixed. +- Move test total to 359. +- Increase test coverage to 81%. +- 3 new "prepared" transformations added: Rotate 90 degrees, Rotate 180 degrees, and Rotate 270 degrees. Removals -------- diff --git a/mayan/apps/converter/classes.py b/mayan/apps/converter/classes.py index 794b4db4c1..5a888fa384 100644 --- a/mayan/apps/converter/classes.py +++ b/mayan/apps/converter/classes.py @@ -216,9 +216,8 @@ class ConverterBase(object): class BaseTransformation(object): - name = 'base_transformation' arguments = () - + name = 'base_transformation' _registry = {} @staticmethod @@ -247,9 +246,11 @@ class BaseTransformation(object): @classmethod def get_transformation_choices(cls): - return [ - (name, klass.get_label()) for name, klass in cls._registry.items() - ] + return sorted( + [ + (name, klass.get_label()) for name, klass in cls._registry.items() + ] + ) @classmethod def get(cls, name): @@ -257,7 +258,10 @@ class BaseTransformation(object): @classmethod def get_label(cls): - return string_concat(cls.label, ': ', ', '.join(cls.arguments)) + if cls.arguments: + return string_concat(cls.label, ': ', ', '.join(cls.arguments)) + else: + return cls.label def __init__(self, **kwargs): self.kwargs = {} @@ -278,9 +282,9 @@ class BaseTransformation(object): class TransformationResize(BaseTransformation): - name = 'resize' arguments = ('width', 'height') label = _('Resize') + name = 'resize' def execute_on(self, *args, **kwargs): super(TransformationResize, self).execute_on(*args, **kwargs) @@ -305,9 +309,9 @@ class TransformationResize(BaseTransformation): class TransformationRotate(BaseTransformation): - name = 'rotate' arguments = ('degrees',) label = _('Rotate') + name = 'rotate' def execute_on(self, *args, **kwargs): super(TransformationRotate, self).execute_on(*args, **kwargs) @@ -322,10 +326,43 @@ class TransformationRotate(BaseTransformation): ) +class TransformationRotate90(TransformationRotate): + arguments = () + degrees = 90 + label = _('Rotate 90 degrees') + name = 'rotate90' + + def __init__(self, **kwargs): + super(TransformationRotate90, self).__init__() + self.kwargs['degrees'] = 90 + + +class TransformationRotate180(TransformationRotate): + arguments = () + degrees = 180 + label = _('Rotate 180 degrees') + name = 'rotate180' + + def __init__(self, **kwargs): + super(TransformationRotate180, self).__init__() + self.kwargs['degrees'] = 180 + + +class TransformationRotate270(TransformationRotate): + arguments = () + degrees = 270 + label = _('Rotate 270 degrees') + name = 'rotate270' + + def __init__(self, **kwargs): + super(TransformationRotate270, self).__init__() + self.kwargs['degrees'] = 270 + + class TransformationZoom(BaseTransformation): - name = 'zoom' arguments = ('percent',) label = _('Zoom') + name = 'zoom' def execute_on(self, *args, **kwargs): super(TransformationZoom, self).execute_on(*args, **kwargs) @@ -343,9 +380,9 @@ class TransformationZoom(BaseTransformation): class TransformationCrop(BaseTransformation): - name = 'crop' arguments = ('left', 'top', 'right', 'bottom',) label = _('Crop') + name = 'crop' def execute_on(self, *args, **kwargs): super(TransformationCrop, self).execute_on(*args, **kwargs) @@ -357,5 +394,8 @@ class TransformationCrop(BaseTransformation): BaseTransformation.register(TransformationResize) BaseTransformation.register(TransformationRotate) +BaseTransformation.register(TransformationRotate90) +BaseTransformation.register(TransformationRotate180) +BaseTransformation.register(TransformationRotate270) BaseTransformation.register(TransformationZoom) BaseTransformation.register(TransformationCrop) diff --git a/mayan/apps/converter/managers.py b/mayan/apps/converter/managers.py index c01a0e8f3a..3350774c59 100644 --- a/mayan/apps/converter/managers.py +++ b/mayan/apps/converter/managers.py @@ -79,9 +79,16 @@ class TransformationManager(models.Manager): ) else: try: + # Some transformations don't require arguments + # return an empty dictionary as ** doesn't allow None + if transformation.arguments: + kwargs = yaml.safe_load(transformation.arguments) + else: + kwargs = {} + result.append( transformation_class( - **yaml.safe_load(transformation.arguments) + **kwargs ) ) except Exception as exception: