Auto add arguments to transformation labels.

This commit is contained in:
Roberto Rosario
2015-07-04 04:16:18 -04:00
parent 862de43219
commit fa4cb686fb
+10 -6
View File
@@ -10,9 +10,9 @@ try:
except ImportError: except ImportError:
from StringIO import StringIO from StringIO import StringIO
from PIL import Image
from django.utils.translation import ugettext_lazy as _ from PIL import Image
from django.utils.translation import string_concat, ugettext_lazy as _
from common.settings import setting_temporary_directory from common.settings import setting_temporary_directory
from common.utils import fs_cleanup from common.utils import fs_cleanup
@@ -201,12 +201,16 @@ class BaseTransformation(object):
@classmethod @classmethod
def get_transformation_choices(cls): def get_transformation_choices(cls):
return [(name, klass.label) for name, klass in cls._registry.items()] return [(name, klass.get_label()) for name, klass in cls._registry.items()]
@classmethod @classmethod
def get(cls, name): def get(cls, name):
return cls._registry[name] return cls._registry[name]
@classmethod
def get_label(cls):
return string_concat(cls.label, ': ', ', '.join(cls.arguments))
def __init__(self, **kwargs): def __init__(self, **kwargs):
for argument_name in self.arguments: for argument_name in self.arguments:
setattr(self, argument_name, kwargs.get(argument_name)) setattr(self, argument_name, kwargs.get(argument_name))
@@ -219,7 +223,7 @@ class BaseTransformation(object):
class TransformationResize(BaseTransformation): class TransformationResize(BaseTransformation):
name = 'resize' name = 'resize'
arguments = ('width', 'height') arguments = ('width', 'height')
label = _('Resize <width> <height>') label = _('Resize')
def execute_on(self, *args, **kwargs): def execute_on(self, *args, **kwargs):
super(TransformationResize, self).execute_on(*args, **kwargs) super(TransformationResize, self).execute_on(*args, **kwargs)
@@ -257,7 +261,7 @@ class TransformationResize(BaseTransformation):
class TransformationRotate(BaseTransformation): class TransformationRotate(BaseTransformation):
name = 'rotate' name = 'rotate'
arguments = ('degrees',) arguments = ('degrees',)
label = _('Rotate <degrees>') label = _('Rotate')
def execute_on(self, *args, **kwargs): def execute_on(self, *args, **kwargs):
super(TransformationRotate, self).execute_on(*args, **kwargs) super(TransformationRotate, self).execute_on(*args, **kwargs)
@@ -268,7 +272,7 @@ class TransformationRotate(BaseTransformation):
class TransformationZoom(BaseTransformation): class TransformationZoom(BaseTransformation):
name = 'zoom' name = 'zoom'
arguments = ('percent',) arguments = ('percent',)
label = _('Zoom <percent>') label = _('Zoom')
def execute_on(self, *args, **kwargs): def execute_on(self, *args, **kwargs):
super(TransformationZoom, self).execute_on(*args, **kwargs) super(TransformationZoom, self).execute_on(*args, **kwargs)