From 37875df7a19359d12d59de68281735376e4ca018 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 9 Oct 2014 20:25:55 -0400 Subject: [PATCH] Add missing imports, PEP8 cleanups --- mayan/apps/common/forms.py | 3 ++- mayan/apps/common/models.py | 2 +- mayan/apps/common/tests.py | 2 +- mayan/apps/sources/api_views.py | 3 --- .../management/commands/bulk_upload.py | 18 +++++++-------- ...gingfolder_icon__del_field_webform_icon.py | 5 +--- ...bform__del_watchfolder__del_outofproces.py | 5 +--- mayan/apps/sources/models.py | 10 +------- mayan/apps/sources/tasks.py | 4 +--- mayan/apps/sources/views.py | 23 ++++++++----------- mayan/apps/tags/api_views.py | 1 + mayan/apps/tags/links.py | 4 ++-- mayan/apps/user_management/__init__.py | 9 ++++---- mayan/apps/user_management/api_views.py | 5 ++-- mayan/apps/user_management/links.py | 7 +++--- .../management/commands/import_users.py | 12 +++++----- 16 files changed, 47 insertions(+), 66 deletions(-) diff --git a/mayan/apps/common/forms.py b/mayan/apps/common/forms.py index 2e2406ff65..2068d6b487 100644 --- a/mayan/apps/common/forms.py +++ b/mayan/apps/common/forms.py @@ -1,5 +1,6 @@ from __future__ import absolute_import +import warnings import os from django import forms @@ -11,7 +12,7 @@ from django.utils.html import escape from django.utils.translation import ugettext_lazy as _ from .utils import return_attrib -from .widgets import EmailInput, DetailSelectMultiple, PlainWidget +from .widgets import DetailSelectMultiple, EmailInput, PlainWidget class DetailForm(forms.ModelForm): diff --git a/mayan/apps/common/models.py b/mayan/apps/common/models.py index 0e64de7657..7227271a5f 100644 --- a/mayan/apps/common/models.py +++ b/mayan/apps/common/models.py @@ -1,8 +1,8 @@ from __future__ import absolute_import from django.db import models -from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext +from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User from solo.models import SingletonModel diff --git a/mayan/apps/common/tests.py b/mayan/apps/common/tests.py index 95436bdfda..31c84f9d5b 100644 --- a/mayan/apps/common/tests.py +++ b/mayan/apps/common/tests.py @@ -3,8 +3,8 @@ from __future__ import absolute_import from django.conf import settings from django.contrib.auth.models import User from django.core.urlresolvers import reverse -from django.test.client import Client from django.test import TestCase +from django.test.client import Client import common diff --git a/mayan/apps/sources/api_views.py b/mayan/apps/sources/api_views.py index 34d7badea1..773a4b7919 100644 --- a/mayan/apps/sources/api_views.py +++ b/mayan/apps/sources/api_views.py @@ -71,9 +71,6 @@ class APIStagingSourceFileImageView(generics.GenericAPIView): zoom = int(request.GET.get('zoom', DEFAULT_ZOOM_LEVEL)) - if request.GET.get('as_base64', False): - base64_version = True - if zoom < ZOOM_MIN_LEVEL: zoom = ZOOM_MIN_LEVEL diff --git a/mayan/apps/sources/management/commands/bulk_upload.py b/mayan/apps/sources/management/commands/bulk_upload.py index 0de9840add..d69b066216 100644 --- a/mayan/apps/sources/management/commands/bulk_upload.py +++ b/mayan/apps/sources/management/commands/bulk_upload.py @@ -7,23 +7,24 @@ import sys from django.core.management.base import CommandError, LabelCommand -from documents.models import DocumentType from common.compressed_files import NotACompressedFile +from documents.models import DocumentType from metadata.api import convert_dict_to_dict_list from ...models import OutOfProcess + class Command(LabelCommand): args = '' help = 'Upload documents from a compressed file in to the database.' option_list = LabelCommand.option_list + ( make_option('--noinput', action='store_false', dest='interactive', - default=True, help='Do not ask the user for confirmation before ' - 'starting.'), + default=True, help='Do not ask the user for confirmation before ' + 'starting.'), make_option('--metadata', action='store', dest='metadata', - help='A metadata dictionary list to apply to the documents.'), + help='A metadata dictionary list to apply to the documents.'), make_option('--document_type', action='store', dest='document_type_name', - help='The document type to apply to the uploaded documents.'), + help='The document type to apply to the uploaded documents.'), ) def handle_label(self, label, **options): @@ -60,8 +61,7 @@ class Command(LabelCommand): source = OutOfProcess() fd = open(label) try: - result = source.upload_file(fd, filename=None, use_file_name=False, document_type=document_type, expand=True, metadata_dict_list=metadata_dict_list, user=None, document=None, new_version_data=None, command_line=True) - pass + source.upload_file(fd, filename=None, use_file_name=False, document_type=document_type, expand=True, metadata_dict_list=metadata_dict_list, user=None, document=None, new_version_data=None, command_line=True) except NotACompressedFile: print '%s is not a compressed file.' % label else: @@ -76,5 +76,5 @@ def _confirm(interactive): if not interactive: return 'yes' return raw_input('You have requested to bulk upload a number of documents from a compressed file.\n' - 'Are you sure you want to do this?\n' - 'Type \'yes\' to continue, or any other value to cancel: ') + 'Are you sure you want to do this?\n' + 'Type \'yes\' to continue, or any other value to cancel: ') diff --git a/mayan/apps/sources/migrations/0003_auto__del_field_stagingfolder_icon__del_field_webform_icon.py b/mayan/apps/sources/migrations/0003_auto__del_field_stagingfolder_icon__del_field_webform_icon.py index 64a48c8059..426bf9f851 100644 --- a/mayan/apps/sources/migrations/0003_auto__del_field_stagingfolder_icon__del_field_webform_icon.py +++ b/mayan/apps/sources/migrations/0003_auto__del_field_stagingfolder_icon__del_field_webform_icon.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime from south.db import db from south.v2 import SchemaMigration from django.db import models @@ -14,7 +13,6 @@ class Migration(SchemaMigration): # Deleting field 'WebForm.icon' db.delete_column(u'sources_webform', 'icon') - def backwards(self, orm): # Adding field 'StagingFolder.icon' db.add_column(u'sources_stagingfolder', 'icon', @@ -26,7 +24,6 @@ class Migration(SchemaMigration): self.gf('django.db.models.fields.CharField')(max_length=24, null=True, blank=True), keep_default=False) - models = { u'contenttypes.contenttype': { 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, @@ -88,4 +85,4 @@ class Migration(SchemaMigration): } } - complete_apps = ['sources'] \ No newline at end of file + complete_apps = ['sources'] diff --git a/mayan/apps/sources/migrations/0004_auto__del_stagingfolder__del_webform__del_watchfolder__del_outofproces.py b/mayan/apps/sources/migrations/0004_auto__del_stagingfolder__del_webform__del_watchfolder__del_outofproces.py index 911eae6265..87a239b21b 100644 --- a/mayan/apps/sources/migrations/0004_auto__del_stagingfolder__del_webform__del_watchfolder__del_outofproces.py +++ b/mayan/apps/sources/migrations/0004_auto__del_stagingfolder__del_webform__del_watchfolder__del_outofproces.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime from south.db import db from south.v2 import SchemaMigration from django.db import models @@ -70,7 +69,6 @@ class Migration(SchemaMigration): )) db.send_create_signal(u'sources', ['StagingFolderSource']) - def backwards(self, orm): # Adding model 'StagingFolder' db.create_table(u'sources_stagingfolder', ( @@ -140,7 +138,6 @@ class Migration(SchemaMigration): # Deleting model 'StagingFolderSource' db.delete_table(u'sources_stagingfoldersource') - models = { u'contenttypes.contenttype': { 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, @@ -198,4 +195,4 @@ class Migration(SchemaMigration): } } - complete_apps = ['sources'] \ No newline at end of file + complete_apps = ['sources'] diff --git a/mayan/apps/sources/models.py b/mayan/apps/sources/models.py index f3852022af..36bf9512ae 100644 --- a/mayan/apps/sources/models.py +++ b/mayan/apps/sources/models.py @@ -16,7 +16,6 @@ from acls.utils import apply_default_acls from common.compressed_files import CompressedFile, NotACompressedFile from converter.api import get_available_transformations_choices from converter.literals import DIMENSION_SEPARATOR -from document_indexing.api import update_indexes from documents.events import HISTORY_DOCUMENT_CREATED from documents.models import Document from history.api import create_history @@ -27,7 +26,7 @@ from .literals import (SOURCE_CHOICES, SOURCE_CHOICES_PLURAL, SOURCE_CHOICE_STAGING, SOURCE_CHOICE_WATCH, SOURCE_CHOICE_WEB_FORM, SOURCE_INTERACTIVE_UNCOMPRESS_CHOICES, - SOURCE_UNCOMPRESS_CHOICES, SOURCE_UNCOMPRESS_CHOICE_Y) + SOURCE_UNCOMPRESS_CHOICES) from .managers import SourceTransformationManager logger = logging.getLogger(__name__) @@ -213,13 +212,6 @@ class WatchFolderSource(OutOfProcessSource): delete_after_upload = models.BooleanField(default=True, verbose_name=_(u'Delete after upload'), help_text=_(u'Delete the file after is has been successfully uploaded.')) interval = models.PositiveIntegerField(verbose_name=_(u'Interval'), help_text=_(u'Inverval in seconds where the watch folder path is checked for new documents.')) - def execute(self, source_id): - if self.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y: - expand = True - else: - expand = False - print 'execute: %s' % self.internal_name() - class Meta: verbose_name = _(u'Watch folder') verbose_name_plural = _(u'Watch folders') diff --git a/mayan/apps/sources/tasks.py b/mayan/apps/sources/tasks.py index acf734f76e..dbc47ea878 100644 --- a/mayan/apps/sources/tasks.py +++ b/mayan/apps/sources/tasks.py @@ -6,7 +6,7 @@ from django.core.files import File from mayan.celery import app from documents.exceptions import NewDocumentVersionNotAllowed -from documents.models import DocumentType +from documents.models import Document, DocumentType from .models import Source @@ -49,5 +49,3 @@ def task_upload_document(source_id, file_path, filename=None, use_file_name=Fals # if result['is_compressed'] is False: # messages.warning(request, _(u'File was not a compressed file, uploaded as it was.')) - - diff --git a/mayan/apps/sources/views.py b/mayan/apps/sources/views.py index ad5215fc12..4ed676eb2e 100644 --- a/mayan/apps/sources/views.py +++ b/mayan/apps/sources/views.py @@ -149,7 +149,8 @@ def upload_interactive(request, source_id=None, document_pk=None): context['source'] = source if request.method == 'POST': - form = form_class(request.POST, request.FILES, + form = form_class( + request.POST, request.FILES, document_type=document_type, show_expand=(source.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document, source=source, @@ -319,7 +320,7 @@ def upload_interactive(request, source_id=None, document_pk=None): ) return render_to_response('main/generic_form.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def get_form_filename(form): @@ -384,7 +385,7 @@ def setup_source_list(request, source_type): } return render_to_response('main/generic_list.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def setup_source_edit(request, source_id): @@ -420,8 +421,7 @@ def setup_source_edit(request, source_id): 'next': next, 'object_name': _(u'Source'), 'source_type': source.source_type, - }, - context_instance=RequestContext(request)) + }, context_instance=RequestContext(request)) def setup_source_delete(request, source_id): @@ -464,7 +464,7 @@ def setup_source_delete(request, source_id): } return render_to_response('main/generic_confirm.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def setup_source_create(request, source_type): @@ -497,8 +497,7 @@ def setup_source_create(request, source_type): 'form': form, 'source_type': source_type, 'navigation_object_name': 'source', - }, - context_instance=RequestContext(request)) + }, context_instance=RequestContext(request)) def setup_source_transformation_list(request, source_id): @@ -523,7 +522,7 @@ def setup_source_transformation_list(request, source_id): } return render_to_response('main/generic_list.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def setup_source_transformation_edit(request, transformation_id): @@ -555,8 +554,7 @@ def setup_source_transformation_edit(request, transformation_id): {'object': 'transformation', 'name': _(u'Transformation')} ], 'next': next, - }, - context_instance=RequestContext(request)) + }, context_instance=RequestContext(request)) def setup_source_transformation_delete(request, transformation_id): @@ -589,8 +587,7 @@ def setup_source_transformation_delete(request, transformation_id): }, 'previous': previous, 'form_icon': u'shape_square_delete.png', - }, - context_instance=RequestContext(request)) + }, context_instance=RequestContext(request)) def setup_source_transformation_create(request, source_id): diff --git a/mayan/apps/tags/api_views.py b/mayan/apps/tags/api_views.py index d94f4f12b9..1f3d0dec00 100644 --- a/mayan/apps/tags/api_views.py +++ b/mayan/apps/tags/api_views.py @@ -6,6 +6,7 @@ from django.shortcuts import get_object_or_404 from rest_framework import generics from taggit.models import Tag +from acls.models import AccessEntry from documents.models import Document from documents.permissions import PERMISSION_DOCUMENT_VIEW from permissions.models import Permission diff --git a/mayan/apps/tags/links.py b/mayan/apps/tags/links.py index 10020719fa..a3d158bc33 100644 --- a/mayan/apps/tags/links.py +++ b/mayan/apps/tags/links.py @@ -4,8 +4,8 @@ from django.utils.translation import ugettext_lazy as _ from acls.permissions import ACLS_VIEW_ACL -from .permissions import (PERMISSION_TAG_CREATE, PERMISSION_TAG_DELETE, - PERMISSION_TAG_ATTACH, PERMISSION_TAG_EDIT, +from .permissions import (PERMISSION_TAG_ATTACH, PERMISSION_TAG_CREATE, + PERMISSION_TAG_DELETE, PERMISSION_TAG_EDIT, PERMISSION_TAG_REMOVE) tag_list = {'text': _(u'Tag list'), 'view': 'tags:tag_list', 'famfam': 'tag_blue'} diff --git a/mayan/apps/user_management/__init__.py b/mayan/apps/user_management/__init__.py index 3d33702df6..7f25b704ff 100644 --- a/mayan/apps/user_management/__init__.py +++ b/mayan/apps/user_management/__init__.py @@ -7,10 +7,11 @@ from navigation.api import register_links, register_multi_item_links from project_setup.api import register_setup from rest_api.classes import APIEndPoint -from .links import (user_list, user_setup, user_edit, user_add, user_delete, - user_multiple_delete, user_set_password, user_multiple_set_password, - user_groups, group_list, group_setup, group_edit, group_add, group_delete, - group_multiple_delete, group_members) +from .links import (group_add, group_delete, group_edit, group_list, + group_members, group_multiple_delete, group_setup, + user_add, user_delete, user_edit, user_groups, user_list, + user_multiple_delete, user_multiple_set_password, + user_set_password, user_setup) from .urls import api_urls register_links(User, [user_edit, user_set_password, user_groups, user_delete]) diff --git a/mayan/apps/user_management/api_views.py b/mayan/apps/user_management/api_views.py index 93effdf2d7..eeef513185 100644 --- a/mayan/apps/user_management/api_views.py +++ b/mayan/apps/user_management/api_views.py @@ -7,9 +7,8 @@ from rest_framework import generics from rest_api.filters import MayanObjectPermissionsFilter from rest_api.permissions import MayanPermission -from .permissions import (PERMISSION_USER_CREATE, - PERMISSION_USER_DELETE, PERMISSION_USER_EDIT, - PERMISSION_USER_VIEW) +from .permissions import (PERMISSION_USER_CREATE, PERMISSION_USER_DELETE, + PERMISSION_USER_EDIT, PERMISSION_USER_VIEW) from .serializers import UserSerializer diff --git a/mayan/apps/user_management/links.py b/mayan/apps/user_management/links.py index fd2548dfe0..a029e9cfae 100644 --- a/mayan/apps/user_management/links.py +++ b/mayan/apps/user_management/links.py @@ -2,9 +2,10 @@ from __future__ import absolute_import from django.utils.translation import ugettext_lazy as _ -from .permissions import (PERMISSION_USER_CREATE, PERMISSION_USER_EDIT, - PERMISSION_USER_VIEW, PERMISSION_USER_DELETE, PERMISSION_GROUP_CREATE, - PERMISSION_GROUP_EDIT, PERMISSION_GROUP_VIEW, PERMISSION_GROUP_DELETE) +from .permissions import (PERMISSION_GROUP_CREATE, PERMISSION_GROUP_DELETE, + PERMISSION_GROUP_EDIT, PERMISSION_GROUP_VIEW, + PERMISSION_USER_CREATE, PERMISSION_USER_DELETE, + PERMISSION_USER_EDIT, PERMISSION_USER_VIEW) user_list = {'text': _(u'User list'), 'view': 'user_management:user_list', 'famfam': 'user', 'permissions': [PERMISSION_USER_VIEW]} user_setup = {'text': _(u'Users'), 'view': 'user_management:user_list', 'famfam': 'user', 'icon': 'user.png', 'permissions': [PERMISSION_USER_VIEW], 'children_view_regex': [r'^user_']} diff --git a/mayan/apps/user_management/management/commands/import_users.py b/mayan/apps/user_management/management/commands/import_users.py index e39197b1c9..77de8c9c3e 100644 --- a/mayan/apps/user_management/management/commands/import_users.py +++ b/mayan/apps/user_management/management/commands/import_users.py @@ -1,12 +1,12 @@ from __future__ import absolute_import import csv +from optparse import make_option import os import sys -from optparse import make_option -from django.core.management.base import CommandError, LabelCommand from django.contrib.auth.models import User +from django.core.management.base import CommandError, LabelCommand from django.db.utils import IntegrityError @@ -29,12 +29,12 @@ class Command(LabelCommand): help = 'Import users from a CSV file with the field order: username, firstname, lastname, email.' option_list = LabelCommand.option_list + ( make_option('--noinput', action='store_false', dest='interactive', - default=True, help='Do not ask the user for confirmation before ' - 'starting.'), + default=True, help='Do not ask the user for confirmation before ' + 'starting.'), make_option('--password', action='store', dest='password', - help='The default password to assign to each new user.'), + help='The default password to assign to each new user.'), make_option('--skip-repeated', action='store_true', dest='skip_repeated', - default=False, help='Don\'t exit if the user already exists.'), + default=False, help='Don\'t exit if the user already exists.'), ) def handle_label(self, label, **options):