diff --git a/mayan/apps/converter/__init__.py b/mayan/apps/converter/__init__.py index b0211abbf8..8d963865bf 100644 --- a/mayan/apps/converter/__init__.py +++ b/mayan/apps/converter/__init__.py @@ -1,4 +1,4 @@ -from .classes import ( +from .classes import ( # NOQA TransformationResize, TransformationRotate, TransformationZoom # NOQA ) from .runtime import converter_class # NOQA diff --git a/mayan/apps/converter/apps.py b/mayan/apps/converter/apps.py index b63938aea7..0d221f83f9 100644 --- a/mayan/apps/converter/apps.py +++ b/mayan/apps/converter/apps.py @@ -18,6 +18,17 @@ class ConverterApp(MayanAppConfig): def ready(self): super(ConverterApp, self).ready() - menu_sidebar.bind_links(links=[link_transformation_create], sources=[Transformation]) - menu_sidebar.bind_links(links=[link_transformation_create], sources=['converter:transformation_create', 'converter:transformation_list']) - menu_object.bind_links(links=[link_transformation_edit, link_transformation_delete], sources=[Transformation]) + menu_sidebar.bind_links( + links=[link_transformation_create], sources=[Transformation] + ) + menu_sidebar.bind_links( + links=[link_transformation_create], + sources=[ + 'converter:transformation_create', + 'converter:transformation_list' + ] + ) + menu_object.bind_links( + links=[link_transformation_edit, link_transformation_delete], + sources=[Transformation] + ) diff --git a/mayan/apps/converter/classes.py b/mayan/apps/converter/classes.py index 2201239a64..bf44aa20fd 100644 --- a/mayan/apps/converter/classes.py +++ b/mayan/apps/converter/classes.py @@ -82,7 +82,9 @@ class ConverterBase(object): """ if not os.path.exists(setting_libreoffice_path.value): - raise OfficeConversionError(_('LibreOffice not installed or not found at path: %s') % setting_libreoffice_path.value) + raise OfficeConversionError( + _('LibreOffice not installed or not found at path: %s') % setting_libreoffice_path.value + ) new_file_object, input_filepath = tempfile.mkstemp() file_object.seek(0) @@ -104,7 +106,10 @@ class ConverterBase(object): logger.debug('command: %s', command) os.environ['HOME'] = setting_temporary_directory.value - proc = subprocess.Popen(command, close_fds=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen( + command, close_fds=True, stderr=subprocess.PIPE, + stdout=subprocess.PIPE + ) return_code = proc.wait() logger.debug('return_code: %s', return_code) fs_cleanup(input_filepath) @@ -115,11 +120,17 @@ class ConverterBase(object): if return_code != 0: raise OfficeConversionError(readline) - filename, extension = os.path.splitext(os.path.basename(input_filepath)) + filename, extension = os.path.splitext( + os.path.basename(input_filepath) + ) logger.debug('filename: %s', filename) logger.debug('extension: %s', extension) - converted_output = os.path.join(setting_temporary_directory.value, os.path.extsep.join([filename, 'pdf'])) + converted_output = os.path.join( + setting_temporary_directory.value, os.path.extsep.join( + [filename, 'pdf'] + ) + ) logger.debug('converted_output: %s', converted_output) with open(converted_output) as converted_file_object: @@ -134,7 +145,9 @@ class ConverterBase(object): def __init__(self, file_object, mime_type=None): self.file_object = file_object self.image = None - self.mime_type = mime_type or get_mimetype(file_object=file_object, mimetype_only=False)[0] + self.mime_type = mime_type or get_mimetype( + file_object=file_object, mimetype_only=False + )[0] self.soffice_file = None def to_pdf(self): @@ -201,7 +214,9 @@ class BaseTransformation(object): @classmethod def get_transformation_choices(cls): - return [(name, klass.get_label()) for name, klass in cls._registry.items()] + return [ + (name, klass.get_label()) for name, klass in cls._registry.items() + ] @classmethod def get(cls, name): @@ -236,7 +251,10 @@ class TransformationResize(BaseTransformation): while self.image.size[0] / factor > 2 * width and self.image.size[1] * 2 / factor > 2 * height: factor *= 2 if factor > 1: - self.image.thumbnail((self.image.size[0] / factor, self.image.size[1] / factor), Image.NEAREST) + self.image.thumbnail( + (self.image.size[0] / factor, self.image.size[1] / factor), + Image.NEAREST + ) # calculate the cropping box and get the cropped part if fit: @@ -265,8 +283,9 @@ class TransformationRotate(BaseTransformation): def execute_on(self, *args, **kwargs): super(TransformationRotate, self).execute_on(*args, **kwargs) - - return self.image.rotate(360 - self.degrees, resample=Image.BICUBIC, expand=True) + return self.image.rotate( + 360 - self.degrees, resample=Image.BICUBIC, expand=True + ) class TransformationZoom(BaseTransformation): @@ -278,7 +297,10 @@ class TransformationZoom(BaseTransformation): super(TransformationZoom, self).execute_on(*args, **kwargs) decimal_value = float(self.percent) / 100 - return self.image.resize((int(self.image.size[0] * decimal_value), int(self.image.size[1] * decimal_value)), Image.ANTIALIAS) + return self.image.resize( + (int(self.image.size[0] * decimal_value), + int(self.image.size[1] * decimal_value)), Image.ANTIALIAS + ) BaseTransformation.register(TransformationResize) diff --git a/mayan/apps/converter/links.py b/mayan/apps/converter/links.py index aebf96ae42..e5026082b2 100644 --- a/mayan/apps/converter/links.py +++ b/mayan/apps/converter/links.py @@ -13,13 +13,33 @@ from .permissions import ( def get_kwargs_factory(variable_name): def get_kwargs(context): - content_type = ContentType.objects.get_for_model(context[variable_name]) - return {'app_label': '"{}"'.format(content_type.app_label), 'model': '"{}"'.format(content_type.model), 'object_id': '{}.pk'.format(variable_name)} + content_type = ContentType.objects.get_for_model( + context[variable_name] + ) + return { + 'app_label': '"{}"'.format(content_type.app_label), + 'model': '"{}"'.format(content_type.model), + 'object_id': '{}.pk'.format(variable_name) + } return get_kwargs -link_transformation_create = Link(kwargs=get_kwargs_factory('content_object'), permissions=[permission_transformation_create], text=_('Create new transformation'), view='converter:transformation_create') -link_transformation_delete = Link(args='resolved_object.pk', permissions=[permission_transformation_delete], tags='dangerous', text=_('Delete'), view='converter:transformation_delete') -link_transformation_edit = Link(args='resolved_object.pk', permissions=[permission_transformation_edit], text=_('Edit'), view='converter:transformation_edit') -link_transformation_list = Link(kwargs=get_kwargs_factory('resolved_object'), permissions=[permission_transformation_view], text=_('Transformations'), view='converter:transformation_list') +link_transformation_create = Link( + kwargs=get_kwargs_factory('content_object'), + permissions=[permission_transformation_create], + text=_('Create new transformation'), view='converter:transformation_create' +) +link_transformation_delete = Link( + args='resolved_object.pk', permissions=[permission_transformation_delete], + tags='dangerous', text=_('Delete'), view='converter:transformation_delete' +) +link_transformation_edit = Link( + args='resolved_object.pk', permissions=[permission_transformation_edit], + text=_('Edit'), view='converter:transformation_edit' +) +link_transformation_list = Link( + kwargs=get_kwargs_factory('resolved_object'), + permissions=[permission_transformation_view], text=_('Transformations'), + view='converter:transformation_list' +) diff --git a/mayan/apps/converter/managers.py b/mayan/apps/converter/managers.py index c1b841f3b8..3b942b20db 100644 --- a/mayan/apps/converter/managers.py +++ b/mayan/apps/converter/managers.py @@ -20,11 +20,20 @@ class TransformationManager(models.Manager): content_type = ContentType.objects.get_for_model(source) # Get transformations - transformations = self.filter(content_type=content_type, object_id=source.pk).values('name', 'arguments', 'order') + transformations = self.filter( + content_type=content_type, object_id=source.pk + ).values('name', 'arguments', 'order') logger.debug('source transformations: %s', transformations) # Get all targets from target QS - targets_dict = map(lambda entry: {'content_type': entry[0], 'object_id': entry[1]}, zip(ContentType.objects.get_for_models(*targets).values(), targets.values_list('pk', flat=True))) + targets_dict = map( + lambda entry: { + 'content_type': entry[0], 'object_id': entry[1] + }, zip( + ContentType.objects.get_for_models(*targets).values(), + targets.values_list('pk', flat=True) + ) + ) logger.debug('targets: %s', targets_dict) # Combine the two @@ -51,21 +60,36 @@ class TransformationManager(models.Manager): content_type = ContentType.objects.get_for_model(obj) - transformations = self.filter(content_type=content_type, object_id=obj.pk) + transformations = self.filter( + content_type=content_type, object_id=obj.pk + ) if as_classes: result = [] for transformation in transformations: try: - transformation_class = BaseTransformation.get(transformation.name) + transformation_class = BaseTransformation.get( + transformation.name + ) except KeyError: # Non existant transformation, but we don't raise an error - logger.error('Non existant transformation: %s for %s', transformation.name, obj) + logger.error( + 'Non existant transformation: %s for %s', + transformation.name, obj + ) else: try: - result.append(transformation_class(**yaml.safe_load(transformation.arguments))) + result.append( + transformation_class( + **yaml.safe_load(transformation.arguments) + ) + ) except Exception as exception: - logger.error('Error while parsing transformation "%s", arguments "%s", for object "%s"; %s', transformation, transformation.arguments, obj, exception) + logger.error( + 'Error while parsing transformation "%s", arguments "%s", for object "%s"; %s', + transformation, transformation.arguments, obj, + exception + ) return result else: diff --git a/mayan/apps/converter/migrations/0001_initial.py b/mayan/apps/converter/migrations/0001_initial.py index ed818e3428..3b21ffe27b 100644 --- a/mayan/apps/converter/migrations/0001_initial.py +++ b/mayan/apps/converter/migrations/0001_initial.py @@ -15,12 +15,38 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Transformation', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ( + 'id', models.AutoField( + verbose_name='ID', serialize=False, auto_created=True, + primary_key=True + ) + ), ('object_id', models.PositiveIntegerField()), - ('order', models.PositiveIntegerField(default=0, null=True, verbose_name='Order', db_index=True, blank=True)), - ('transformation', models.CharField(max_length=128, verbose_name='Transformation', choices=[('rotate', 'Rotate'), ('zoom', 'Zoom'), ('resize', 'Resize')])), - ('arguments', models.TextField(blank=True, null=True, verbose_name='Arguments', validators=[converter.validators.YAMLValidator])), - ('content_type', models.ForeignKey(to='contenttypes.ContentType')), + ( + 'order', models.PositiveIntegerField( + default=0, null=True, verbose_name='Order', + db_index=True, blank=True + ) + ), + ( + 'transformation', models.CharField( + max_length=128, verbose_name='Transformation', + choices=[ + ('rotate', 'Rotate'), ('zoom', 'Zoom'), + ('resize', 'Resize') + ] + ) + ), + ( + 'arguments', models.TextField( + blank=True, null=True, verbose_name='Arguments', + validators=[converter.validators.YAMLValidator] + ) + ), + ( + 'content_type', + models.ForeignKey(to='contenttypes.ContentType') + ), ], options={ 'ordering': ('order',), diff --git a/mayan/apps/converter/migrations/0004_auto_20150704_0753.py b/mayan/apps/converter/migrations/0004_auto_20150704_0753.py index 892db29185..88511f03b0 100644 --- a/mayan/apps/converter/migrations/0004_auto_20150704_0753.py +++ b/mayan/apps/converter/migrations/0004_auto_20150704_0753.py @@ -15,7 +15,11 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='transformation', name='arguments', - field=models.TextField(help_text='Enter the arguments for the transformation as a YAML dictionary. ie: {"degrees": 180}', blank=True, verbose_name='Arguments', validators=[converter.validators.YAMLValidator()]), + field=models.TextField( + help_text='Enter the arguments for the transformation as a YAML dictionary. ie: {"degrees": 180}', + blank=True, verbose_name='Arguments', + validators=[converter.validators.YAMLValidator()] + ), preserve_default=True, ), ] diff --git a/mayan/apps/converter/models.py b/mayan/apps/converter/models.py index e58c763426..00d4a538c5 100644 --- a/mayan/apps/converter/models.py +++ b/mayan/apps/converter/models.py @@ -27,9 +27,20 @@ class Transformation(models.Model): object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') - order = models.PositiveIntegerField(blank=True, db_index=True, default=0, help_text=_('Order in which the transformations will be executed. If left unchanged, an automatic order value will be assigned.'), verbose_name=_('Order')) - name = models.CharField(choices=BaseTransformation.get_transformation_choices(), max_length=128, verbose_name=_('Name')) - arguments = models.TextField(blank=True, help_text=_('Enter the arguments for the transformation as a YAML dictionary. ie: {"degrees": 180}'), validators=[YAMLValidator()], verbose_name=_('Arguments')) + order = models.PositiveIntegerField( + blank=True, db_index=True, default=0, + help_text=_('Order in which the transformations will be executed. If left unchanged, an automatic order value will be assigned.'), + verbose_name=_('Order') + ) + name = models.CharField( + choices=BaseTransformation.get_transformation_choices(), + max_length=128, verbose_name=_('Name') + ) + arguments = models.TextField( + blank=True, + help_text=_('Enter the arguments for the transformation as a YAML dictionary. ie: {"degrees": 180}'), + validators=[YAMLValidator()], verbose_name=_('Arguments') + ) objects = TransformationManager() @@ -38,7 +49,9 @@ class Transformation(models.Model): def save(self, *args, **kwargs): if not self.order: - last_order = Transformation.objects.filter(content_type=self.content_type, object_id=self.object_id).aggregate(Max('order'))['order__max'] + last_order = Transformation.objects.filter( + content_type=self.content_type, object_id=self.object_id + ).aggregate(Max('order'))['order__max'] if last_order is not None: self.order = last_order + 1 super(Transformation, self).save(*args, **kwargs) diff --git a/mayan/apps/converter/permissions.py b/mayan/apps/converter/permissions.py index 1c023832f1..73d7ea86ba 100644 --- a/mayan/apps/converter/permissions.py +++ b/mayan/apps/converter/permissions.py @@ -6,7 +6,15 @@ from permissions import PermissionNamespace namespace = PermissionNamespace('converter', _('Converter')) -permission_transformation_create = namespace.add_permission(name='transformation_create', label=_('Create new transformations')) -permission_transformation_delete = namespace.add_permission(name='transformation_delete', label=_('Delete transformations')) -permission_transformation_edit = namespace.add_permission(name='transformation_edit', label=_('Edit transformations')) -permission_transformation_view = namespace.add_permission(name='transformation_view', label=_('View existing transformations')) +permission_transformation_create = namespace.add_permission( + name='transformation_create', label=_('Create new transformations') +) +permission_transformation_delete = namespace.add_permission( + name='transformation_delete', label=_('Delete transformations') +) +permission_transformation_edit = namespace.add_permission( + name='transformation_edit', label=_('Edit transformations') +) +permission_transformation_view = namespace.add_permission( + name='transformation_view', label=_('View existing transformations') +) diff --git a/mayan/apps/converter/settings.py b/mayan/apps/converter/settings.py index e2857388a2..15df41bfff 100644 --- a/mayan/apps/converter/settings.py +++ b/mayan/apps/converter/settings.py @@ -5,6 +5,17 @@ from django.utils.translation import ugettext_lazy as _ from smart_settings import Namespace namespace = Namespace(name='converter', label=_('Converter')) -setting_graphics_backend = namespace.add_setting(global_name='CONVERTER_GRAPHICS_BACKEND', default='converter.backends.python.Python', help_text=_('Graphics conversion backend to use.')) -setting_libreoffice_path = namespace.add_setting(global_name='CONVERTER_LIBREOFFICE_PATH', default='/usr/bin/libreoffice', help_text=_('Path to the libreoffice program.'), is_path=True) -setting_pdftoppm_path = namespace.add_setting(global_name='CONVERTER_PDFTOPPM_PATH', default='/usr/bin/pdftoppm', help_text=_('Path to the Popple program pdftoppm.'), is_path=True) +setting_graphics_backend = namespace.add_setting( + default='converter.backends.python.Python', + help_text=_('Graphics conversion backend to use.'), + global_name='CONVERTER_GRAPHICS_BACKEND', +) +setting_libreoffice_path = namespace.add_setting( + default='/usr/bin/libreoffice', + global_name='CONVERTER_LIBREOFFICE_PATH', + help_text=_('Path to the libreoffice program.'), is_path=True +) +setting_pdftoppm_path = namespace.add_setting( + default='/usr/bin/pdftoppm', global_name='CONVERTER_PDFTOPPM_PATH', + help_text=_('Path to the Popple program pdftoppm.'), is_path=True +) diff --git a/mayan/apps/converter/urls.py b/mayan/apps/converter/urls.py index bead36a931..d1f6da99b7 100644 --- a/mayan/apps/converter/urls.py +++ b/mayan/apps/converter/urls.py @@ -9,8 +9,20 @@ from .views import ( urlpatterns = patterns( 'converter.views', - url(r'^create_for/(?P[-\w]+)/(?P[-\w]+)/(?P\d+)/$', TransformationCreateView.as_view(), name='transformation_create'), - url(r'^list_for/(?P[-\w]+)/(?P[-\w]+)/(?P\d+)/$', TransformationListView.as_view(), name='transformation_list'), - url(r'^delete/(?P\d+)/$', TransformationDeleteView.as_view(), name='transformation_delete'), - url(r'^edit/(?P\d+)/$', TransformationEditView.as_view(), name='transformation_edit'), + url( + r'^create_for/(?P[-\w]+)/(?P[-\w]+)/(?P\d+)/$', + TransformationCreateView.as_view(), name='transformation_create' + ), + url( + r'^list_for/(?P[-\w]+)/(?P[-\w]+)/(?P\d+)/$', + TransformationListView.as_view(), name='transformation_list' + ), + url( + r'^delete/(?P\d+)/$', TransformationDeleteView.as_view(), + name='transformation_delete' + ), + url( + r'^edit/(?P\d+)/$', TransformationEditView.as_view(), + name='transformation_edit' + ), ) diff --git a/mayan/apps/converter/validators.py b/mayan/apps/converter/validators.py index 46a1b49428..20f8a2ac19 100644 --- a/mayan/apps/converter/validators.py +++ b/mayan/apps/converter/validators.py @@ -18,7 +18,10 @@ class YAMLValidator(object): try: yaml.safe_load(value) except yaml.error.YAMLError: - raise ValidationError(_('Enter a valid YAML value.'), code='invalid') + raise ValidationError( + _('Enter a valid YAML value.'), + code='invalid' + ) def __eq__(self, other): return ( diff --git a/mayan/apps/converter/views.py b/mayan/apps/converter/views.py index 19d7760081..848dd30592 100644 --- a/mayan/apps/converter/views.py +++ b/mayan/apps/converter/views.py @@ -30,26 +30,49 @@ class TransformationDeleteView(SingleObjectDeleteView): model = Transformation def dispatch(self, request, *args, **kwargs): - self.transformation = get_object_or_404(Transformation, pk=self.kwargs['pk']) + self.transformation = get_object_or_404( + Transformation, pk=self.kwargs['pk'] + ) try: - Permission.check_permissions(request.user, [permission_transformation_delete]) + Permission.check_permissions( + request.user, [permission_transformation_delete] + ) except PermissionDenied: - AccessControlList.objects.check_access(permission_transformation_delete, request.user, self.transformation.content_object) + AccessControlList.objects.check_access( + permission_transformation_delete, request.user, + self.transformation.content_object + ) - return super(TransformationDeleteView, self).dispatch(request, *args, **kwargs) + return super(TransformationDeleteView, self).dispatch( + request, *args, **kwargs + ) def get_post_action_redirect(self): - return reverse('converter:transformation_list', args=[self.transformation.content_type.app_label, self.transformation.content_type.model, self.transformation.object_id]) + return reverse( + 'converter:transformation_list', args=[ + self.transformation.content_type.app_label, + self.transformation.content_type.model, + self.transformation.object_id + ] + ) def get_extra_context(self): return { 'content_object': self.transformation.content_object, 'navigation_object_list': ['content_object', 'transformation'], - 'previous': reverse('converter:transformation_list', args=[self.transformation.content_type.app_label, self.transformation.content_type.model, self.transformation.object_id]), - 'title': _('Delete transformation "%(transformation)s" for: %(content_object)s?') % { - 'transformation': self.transformation, - 'content_object': self.transformation.content_object}, + 'previous': reverse( + 'converter:transformation_list', args=[ + self.transformation.content_type.app_label, + self.transformation.content_type.model, + self.transformation.object_id + ] + ), + 'title': _( + 'Delete transformation "%(transformation)s" for: %(content_object)s?') % { + 'transformation': self.transformation, + 'content_object': self.transformation.content_object + }, 'transformation': self.transformation, } @@ -58,19 +81,31 @@ class TransformationCreateView(SingleObjectCreateView): fields = ('name', 'arguments') def dispatch(self, request, *args, **kwargs): - content_type = get_object_or_404(ContentType, app_label=self.kwargs['app_label'], model=self.kwargs['model']) + content_type = get_object_or_404( + ContentType, app_label=self.kwargs['app_label'], + model=self.kwargs['model'] + ) try: - self.content_object = content_type.get_object_for_this_type(pk=self.kwargs['object_id']) + self.content_object = content_type.get_object_for_this_type( + pk=self.kwargs['object_id'] + ) except content_type.model_class().DoesNotExist: raise Http404 try: - Permission.check_permissions(request.user, [permission_transformation_create]) + Permission.check_permissions( + request.user, [permission_transformation_create] + ) except PermissionDenied: - AccessControlList.objects.check_access(permission_transformation_create, request.user, self.content_object) + AccessControlList.objects.check_access( + permission_transformation_create, request.user, + self.content_object + ) - return super(TransformationCreateView, self).dispatch(request, *args, **kwargs) + return super(TransformationCreateView, self).dispatch( + request, *args, **kwargs + ) def form_valid(self, form): instance = form.save(commit=False) @@ -84,7 +119,12 @@ class TransformationCreateView(SingleObjectCreateView): return super(TransformationCreateView, self).form_valid(form) def get_post_action_redirect(self): - return reverse('converter:transformation_list', args=[self.kwargs['app_label'], self.kwargs['model'], self.kwargs['object_id']]) + return reverse( + 'converter:transformation_list', args=[ + self.kwargs['app_label'], self.kwargs['model'], + self.kwargs['object_id'] + ] + ) def get_queryset(self): return Transformation.objects.get_for_model(self.content_object) @@ -93,7 +133,9 @@ class TransformationCreateView(SingleObjectCreateView): return { 'content_object': self.content_object, 'navigation_object_list': ['content_object'], - 'title': _('Create new transformation for: %s') % self.content_object, + 'title': _( + 'Create new transformation for: %s' + ) % self.content_object, } @@ -102,14 +144,23 @@ class TransformationEditView(SingleObjectEditView): model = Transformation def dispatch(self, request, *args, **kwargs): - self.transformation = get_object_or_404(Transformation, pk=self.kwargs['pk']) + self.transformation = get_object_or_404( + Transformation, pk=self.kwargs['pk'] + ) try: - Permission.check_permissions(request.user, [permission_transformation_edit]) + Permission.check_permissions( + request.user, [permission_transformation_edit] + ) except PermissionDenied: - AccessControlList.objects.check_access(permission_transformation_edit, request.user, self.transformation.content_object) + AccessControlList.objects.check_access( + permission_transformation_edit, request.user, + self.transformation.content_object + ) - return super(TransformationEditView, self).dispatch(request, *args, **kwargs) + return super(TransformationEditView, self).dispatch( + request, *args, **kwargs + ) def form_valid(self, form): instance = form.save(commit=False) @@ -122,34 +173,55 @@ class TransformationEditView(SingleObjectEditView): return super(TransformationEditView, self).form_valid(form) def get_post_action_redirect(self): - return reverse('converter:transformation_list', args=[self.transformation.content_type.app_label, self.transformation.content_type.model, self.transformation.object_id]) + return reverse( + 'converter:transformation_list', args=[ + self.transformation.content_type.app_label, + self.transformation.content_type.model, + self.transformation.object_id + ] + ) def get_extra_context(self): return { 'content_object': self.transformation.content_object, 'navigation_object_list': ['content_object', 'transformation'], - 'title': _('Edit transformation "%(transformation)s" for: %(content_object)s') % { + 'title': _( + 'Edit transformation "%(transformation)s" for: %(content_object)s' + ) % { 'transformation': self.transformation, - 'content_object': self.transformation.content_object}, + 'content_object': self.transformation.content_object + }, 'transformation': self.transformation, } class TransformationListView(SingleObjectListView): def dispatch(self, request, *args, **kwargs): - content_type = get_object_or_404(ContentType, app_label=self.kwargs['app_label'], model=self.kwargs['model']) + content_type = get_object_or_404( + ContentType, app_label=self.kwargs['app_label'], + model=self.kwargs['model'] + ) try: - self.content_object = content_type.get_object_for_this_type(pk=self.kwargs['object_id']) + self.content_object = content_type.get_object_for_this_type( + pk=self.kwargs['object_id'] + ) except content_type.model_class().DoesNotExist: raise Http404 try: - Permission.check_permissions(request.user, [permission_transformation_view]) + Permission.check_permissions( + request.user, [permission_transformation_view] + ) except PermissionDenied: - AccessControlList.objects.check_access(permission_transformation_view, request.user, self.content_object) + AccessControlList.objects.check_access( + permission_transformation_view, request.user, + self.content_object + ) - return super(TransformationListView, self).dispatch(request, *args, **kwargs) + return super(TransformationListView, self).dispatch( + request, *args, **kwargs + ) def get_queryset(self): return Transformation.objects.get_for_model(self.content_object) @@ -159,7 +231,11 @@ class TransformationListView(SingleObjectListView): 'content_object': self.content_object, 'extra_columns': [ {'name': _('Order'), 'attribute': 'order'}, - {'name': _('Transformation'), 'attribute': encapsulate(lambda transformation: unicode(transformation))}, + { + 'name': _('Transformation'), 'attribute': encapsulate( + lambda transformation: unicode(transformation) + ) + }, {'name': _('Arguments'), 'attribute': 'arguments'} ], 'hide_link': True, diff --git a/mayan/apps/documents/migrations/0025_auto_20150718_0742.py b/mayan/apps/documents/migrations/0025_auto_20150718_0742.py index 5d62e45054..faf3a39e46 100644 --- a/mayan/apps/documents/migrations/0025_auto_20150718_0742.py +++ b/mayan/apps/documents/migrations/0025_auto_20150718_0742.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import pycountry -from django.db import models, migrations +from django.db import migrations def change_bibliographic_to_terminology(apps, schema_editor): diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index 962001b407..f69fb11da4 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -15,7 +15,6 @@ from django.utils.timezone import now from django.utils.translation import ugettext, ugettext_lazy as _ from common.literals import TIME_DELTA_UNIT_CHOICES -from common.models import SharedUploadedFile from common.settings import setting_temporary_directory from converter import ( converter_class, TransformationResize, TransformationRotate, diff --git a/mayan/apps/documents/settings.py b/mayan/apps/documents/settings.py index d6a9015c42..e5bd1ce859 100644 --- a/mayan/apps/documents/settings.py +++ b/mayan/apps/documents/settings.py @@ -1,9 +1,7 @@ from __future__ import unicode_literals -import os import pycountry -from django.conf import settings from django.utils.translation import ugettext_lazy as _ from smart_settings import Namespace diff --git a/mayan/apps/documents/test_models.py b/mayan/apps/documents/test_models.py index 3fe28024b8..53fff7806e 100644 --- a/mayan/apps/documents/test_models.py +++ b/mayan/apps/documents/test_models.py @@ -13,6 +13,7 @@ TEST_ADMIN_PASSWORD = 'test_admin_password' TEST_ADMIN_USERNAME = 'test_admin' TEST_ADMIN_EMAIL = 'admin@admin.com' TEST_DEU_DOCUMENT_FILENAME = 'deu_website.png' +TEST_COMPRESSED_DOCUMENTS_FILENAME = 'compressed_documents.zip' TEST_SMALL_DOCUMENT_FILENAME = 'title_page.png' TEST_NON_ASCII_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png' TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png.zip' @@ -21,6 +22,7 @@ TEST_SMALL_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_do TEST_NON_ASCII_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_NON_ASCII_DOCUMENT_FILENAME) TEST_NON_ASCII_COMPRESSED_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME) TEST_DEU_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_DEU_DOCUMENT_FILENAME) +TEST_COMPRESSED_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_COMPRESSED_DOCUMENTS_FILENAME) TEST_DOCUMENT_DESCRIPTION = 'test description' TEST_DOCUMENT_TYPE = 'test_document_type' diff --git a/mayan/apps/dynamic_search/test_views.py b/mayan/apps/dynamic_search/test_views.py index 1d619e3521..3a5767c864 100644 --- a/mayan/apps/dynamic_search/test_views.py +++ b/mayan/apps/dynamic_search/test_views.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -from django.conf import settings from django.contrib.auth.models import User from django.core.files.base import File from django.core.urlresolvers import reverse diff --git a/mayan/apps/lock_manager/managers.py b/mayan/apps/lock_manager/managers.py index b5d12fa77e..629ef5f760 100644 --- a/mayan/apps/lock_manager/managers.py +++ b/mayan/apps/lock_manager/managers.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import datetime import logging -from django.db import OperationalError, models, transaction +from django.db import OperationalError, models, transaction from django.db.utils import IntegrityError from django.utils.timezone import now diff --git a/mayan/apps/mailer/literals.py b/mayan/apps/mailer/literals.py index 948cf8deb1..20f47eaafb 100644 --- a/mayan/apps/mailer/literals.py +++ b/mayan/apps/mailer/literals.py @@ -4,22 +4,20 @@ from django.conf import settings from django.utils.translation import ugettext_lazy as _ -DEFAULT_DOCUMENT_BODY_TEMPLATE =_('\ - Attached to this email is the document: {{ document }}

\n\n\ +DEFAULT_DOCUMENT_BODY_TEMPLATE = _( + 'Attached to this email is the document: {{ document }}

\n\n\ --------
\nThis email has been sent from \ %(project_title)s (%(project_website)s)' - ) % { - 'project_title': settings.PROJECT_TITLE, - 'project_website': settings.PROJECT_WEBSITE - } +) % { + 'project_title': settings.PROJECT_TITLE, + 'project_website': settings.PROJECT_WEBSITE +} -DEFAULT_LINK_BODY_TEMPLATE = _('\ - To access this document click on the following link: \ +DEFAULT_LINK_BODY_TEMPLATE = _( + 'To access this document click on the following link: \ {{ link }}

\n\n--------
\ - \nThis email has been sent from %(project_title)s (%(project_website)s)\ - ') % { - 'project_title': settings.PROJECT_TITLE, - 'project_website': settings.PROJECT_WEBSITE - } - - + \nThis email has been sent from %(project_title)s (%(project_website)s)' +) % { + 'project_title': settings.PROJECT_TITLE, + 'project_website': settings.PROJECT_WEBSITE +} diff --git a/mayan/apps/mailer/settings.py b/mayan/apps/mailer/settings.py index a86a56faa7..24dabbb3d1 100644 --- a/mayan/apps/mailer/settings.py +++ b/mayan/apps/mailer/settings.py @@ -10,8 +10,23 @@ from .literals import ( namespace = Namespace(name='mailer', label=_('Mailing')) -setting_link_subject_template = namespace.add_setting(global_name='MAILER_LINK_SUBJECT_TEMPLATE', default=_('Link for document: {{ document }}'), help_text=_('Template for the document link email form subject line.')) -setting_link_body_template = namespace.add_setting(global_name='MAILER_LINK_BODY_TEMPLATE', default=DEFAULT_LINK_BODY_TEMPLATE, help_text=_('Template for the document link email form body line.')) -setting_document_subject_template = namespace.add_setting(global_name='MAILER_DOCUMENT_SUBJECT_TEMPLATE', default=_('Document: {{ document }}'), help_text=_('Template for the document email form subject line.')) -setting_document_body_template = namespace.add_setting(global_name='MAILER_DOCUMENT_BODY_TEMPLATE', default=DEFAULT_DOCUMENT_BODY_TEMPLATE, help_text=_('Template for the document email form body line.')) - +setting_link_subject_template = namespace.add_setting( + default=_('Link for document: {{ document }}'), + help_text=_('Template for the document link email form subject line.'), + global_name='MAILER_LINK_SUBJECT_TEMPLATE', +) +setting_link_body_template = namespace.add_setting( + default=DEFAULT_LINK_BODY_TEMPLATE, + help_text=_('Template for the document link email form body line.'), + global_name='MAILER_LINK_BODY_TEMPLATE', +) +setting_document_subject_template = namespace.add_setting( + default=_('Document: {{ document }}'), + help_text=_('Template for the document email form subject line.'), + global_name='MAILER_DOCUMENT_SUBJECT_TEMPLATE', +) +setting_document_body_template = namespace.add_setting( + default=DEFAULT_DOCUMENT_BODY_TEMPLATE, + help_text=_('Template for the document email form body line.'), + global_name='MAILER_DOCUMENT_BODY_TEMPLATE', +) diff --git a/mayan/apps/smart_settings/apps.py b/mayan/apps/smart_settings/apps.py index 09bf6e41f9..a956d1fcfa 100644 --- a/mayan/apps/smart_settings/apps.py +++ b/mayan/apps/smart_settings/apps.py @@ -42,4 +42,3 @@ class SmartSettingsApp(MayanAppConfig): logger.debug('App %s has not settings.py file', app.name) else: logger.debug('Imported settings.py file for app %s', app.name) - diff --git a/mayan/apps/smart_settings/classes.py b/mayan/apps/smart_settings/classes.py index c8aebdb10a..cfbdcc68b9 100644 --- a/mayan/apps/smart_settings/classes.py +++ b/mayan/apps/smart_settings/classes.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import yaml from django.conf import settings -from django.utils.functional import Promise, allow_lazy +from django.utils.functional import Promise from django.utils.encoding import force_text diff --git a/mayan/apps/sources/handlers.py b/mayan/apps/sources/handlers.py index 53b699a84f..1c71eefa6b 100644 --- a/mayan/apps/sources/handlers.py +++ b/mayan/apps/sources/handlers.py @@ -15,6 +15,8 @@ def create_default_document_source(sender, **kwargs): def copy_transformations_to_version(sender, **kwargs): instance = kwargs['instance'] + # TODO: Fix this, source should be previous version + # TODO: Fix this, shouldn't this be at the documents app Transformation.objects.copy(source=instance.document, targets=instance.pages.all()) diff --git a/mayan/apps/sources/tasks.py b/mayan/apps/sources/tasks.py index 5da0253daf..b1960021c5 100644 --- a/mayan/apps/sources/tasks.py +++ b/mayan/apps/sources/tasks.py @@ -2,17 +2,14 @@ import logging from django.contrib.auth.models import User from django.core.files import File -from django.db import OperationalError, transaction +from django.db import OperationalError from django.utils.translation import ugettext_lazy as _ from mayan.celery import app from common.compressed_files import CompressedFile, NotACompressedFile from common.models import SharedUploadedFile -from converter.models import Transformation -from documents.models import Document, DocumentType -from documents.settings import setting_language -from metadata.api import save_metadata_list +from documents.models import DocumentType from .literals import DEFAULT_SOURCE_TASK_RETRY_DELAY from .models import Source @@ -62,14 +59,8 @@ def task_upload_document(self, source_id, document_type_id, shared_uploaded_file def task_source_handle_upload(self, document_type_id, shared_uploaded_file_id, source_id, description=None, expand=False, label=None, language=None, metadata_dict_list=None, skip_list=None, user_id=None): try: document_type = DocumentType.objects.get(pk=document_type_id) - source = Source.objects.get_subclass(pk=source_id) shared_upload = SharedUploadedFile.objects.get(pk=shared_uploaded_file_id) - if user_id: - user = User.objects.get(pk=user_id) - else: - user = None - if not label: label = shared_upload.filename @@ -122,7 +113,7 @@ def task_source_handle_upload(self, document_type_id, shared_uploaded_file_id, s try: shared_upload.delete() except OperationalError as exception: - logger.warning('Operational error during attempt to delete shared upload file: %s; %s. Retrying.', shared_uploaded_file, exception) + logger.warning('Operational error during attempt to delete shared upload file: %s; %s. Retrying.', shared_upload, exception) except NotACompressedFile: logging.debug('Exception: NotACompressedFile') task_upload_document.delay(shared_uploaded_file_id=shared_upload.pk, **kwargs) diff --git a/mayan/apps/statistics/views.py b/mayan/apps/statistics/views.py index 5256326750..4bcb9bdc7b 100644 --- a/mayan/apps/statistics/views.py +++ b/mayan/apps/statistics/views.py @@ -1,8 +1,5 @@ from __future__ import unicode_literals -from django.core.exceptions import PermissionDenied -from django.shortcuts import render_to_response -from django.template import RequestContext from django.utils.translation import ugettext_lazy as _ from common.views import SimpleView diff --git a/mayan/apps/tags/migrations/0002_tag_selection.py b/mayan/apps/tags/migrations/0002_tag_selection.py index 34811471a7..01627c9e28 100644 --- a/mayan/apps/tags/migrations/0002_tag_selection.py +++ b/mayan/apps/tags/migrations/0002_tag_selection.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations import colorful.fields diff --git a/mayan/apps/tags/migrations/0003_remove_tag_color.py b/mayan/apps/tags/migrations/0003_remove_tag_color.py index fa18cbb14e..bcd52569fe 100644 --- a/mayan/apps/tags/migrations/0003_remove_tag_color.py +++ b/mayan/apps/tags/migrations/0003_remove_tag_color.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations class Migration(migrations.Migration): diff --git a/mayan/apps/tags/migrations/0004_auto_20150717_2336.py b/mayan/apps/tags/migrations/0004_auto_20150717_2336.py index bd70b4100f..8ac24d9610 100644 --- a/mayan/apps/tags/migrations/0004_auto_20150717_2336.py +++ b/mayan/apps/tags/migrations/0004_auto_20150717_2336.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations class Migration(migrations.Migration): diff --git a/mayan/apps/tags/migrations/0005_auto_20150718_0616.py b/mayan/apps/tags/migrations/0005_auto_20150718_0616.py index 8e1bff4e53..c1a3eee6ab 100644 --- a/mayan/apps/tags/migrations/0005_auto_20150718_0616.py +++ b/mayan/apps/tags/migrations/0005_auto_20150718_0616.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations + import colorful.fields diff --git a/mayan/apps/tags/test_models.py b/mayan/apps/tags/test_models.py index d44254b254..6160c7eccf 100644 --- a/mayan/apps/tags/test_models.py +++ b/mayan/apps/tags/test_models.py @@ -1,12 +1,9 @@ from __future__ import unicode_literals -import os - -from django.conf import settings from django.core.files.base import File from django.test import TestCase -from documents.models import Document, DocumentType +from documents.models import DocumentType from documents.test_models import TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE from .models import Tag