From 9f2692d36af045a6a204c849326c8fda1dbe606a Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 2 Nov 2014 21:20:29 -0400 Subject: [PATCH] PEP8 cleanup, unused import removal --- mayan/apps/checkouts/widgets.py | 4 ++-- mayan/apps/documents/forms.py | 3 +-- mayan/apps/documents/literals.py | 1 - mayan/apps/documents/tasks.py | 2 +- mayan/apps/documents/tests.py | 6 +++--- mayan/apps/documents/views.py | 5 +---- mayan/apps/dynamic_search/__init__.py | 2 -- mayan/apps/metadata/admin.py | 2 +- mayan/apps/metadata/classes.py | 4 ++-- mayan/apps/metadata/forms.py | 2 +- mayan/apps/metadata/views.py | 1 - mayan/apps/navigation/classes.py | 5 ++--- mayan/apps/ocr/api.py | 2 +- mayan/apps/project_setup/api.py | 2 -- mayan/apps/project_tools/api.py | 2 -- mayan/apps/registration/views.py | 3 +-- mayan/apps/rest_api/__init__.py | 2 -- mayan/apps/rest_api/classes.py | 3 +-- mayan/apps/rest_api/views.py | 2 -- mayan/apps/sources/models.py | 2 +- mayan/apps/sources/tasks.py | 2 +- mayan/apps/sources/views.py | 5 +---- mayan/apps/tags/tests.py | 1 - mayan/apps/user_management/__init__.py | 1 - 24 files changed, 20 insertions(+), 44 deletions(-) diff --git a/mayan/apps/checkouts/widgets.py b/mayan/apps/checkouts/widgets.py index 5c78d76f19..1429956839 100644 --- a/mayan/apps/checkouts/widgets.py +++ b/mayan/apps/checkouts/widgets.py @@ -35,8 +35,8 @@ class SplitHiddenDeltaWidget(forms.widgets.SplitDateTimeWidget): """ is_hidden = True - def __init__(self, attrs=None): - super(SplitHiddenDeltaWidget, self).__init__(attrs, date_format, time_format) + def __init__(self, *args, **kwargs): + super(SplitHiddenDeltaWidget, self).__init__(*args, **kwargs) for widget in self.widgets: widget.input_type = 'hidden' widget.is_hidden = True diff --git a/mayan/apps/documents/forms.py b/mayan/apps/documents/forms.py index 81e12ff4b7..32141a50ba 100644 --- a/mayan/apps/documents/forms.py +++ b/mayan/apps/documents/forms.py @@ -11,8 +11,7 @@ from common.forms import DetailForm from common.widgets import TextAreaDiv from .models import (Document, DocumentType, DocumentPage, - DocumentPageTransformation, DocumentTypeFilename, - DocumentVersion) + DocumentPageTransformation, DocumentTypeFilename) from .literals import DEFAULT_ZIP_FILENAME from .widgets import DocumentPagesCarouselWidget, DocumentPageImageWidget diff --git a/mayan/apps/documents/literals.py b/mayan/apps/documents/literals.py index b822089869..396b4cd877 100644 --- a/mayan/apps/documents/literals.py +++ b/mayan/apps/documents/literals.py @@ -12,4 +12,3 @@ VERSION_UPDATE_MICRO = u'micro' DEFAULT_ZIP_FILENAME = u'document_bundle.zip' LANGUAGE_CHOICES = [(i.bibliographic, i.name) for i in list(pycountry.languages)] - diff --git a/mayan/apps/documents/tasks.py b/mayan/apps/documents/tasks.py index 79ef28caec..1c838bf651 100644 --- a/mayan/apps/documents/tasks.py +++ b/mayan/apps/documents/tasks.py @@ -41,7 +41,7 @@ def task_new_document(document_type_id, shared_uploaded_file_id, label, descript user = None with File(file=shared_uploaded_file.file) as file_object: - new_version = Document.objects.new_document(document_type=document_type, expand=expand, file_object=file_object, label=label, description=description, language=language, user=user) + Document.objects.new_document(document_type=document_type, expand=expand, file_object=file_object, label=label, description=description, language=language, user=user) shared_uploaded_file.delete() diff --git a/mayan/apps/documents/tests.py b/mayan/apps/documents/tests.py index 0b9b9df0bb..1eed639a7c 100644 --- a/mayan/apps/documents/tests.py +++ b/mayan/apps/documents/tests.py @@ -167,7 +167,7 @@ class DocumentUploadFunctionalTestCase(TestCase): self.failUnlessEqual(self.document.page_count, 47) # Delete the document - response = self.client.post(reverse('documents:document_delete', args=[self.document.pk])) + self.client.post(reverse('documents:document_delete', args=[self.document.pk])) self.assertEqual(Document.objects.count(), 0) def test_issue_25(self): @@ -198,7 +198,7 @@ class DocumentUploadFunctionalTestCase(TestCase): self.failUnlessEqual(document.description, '') # Test for issue 25 during editing - response = self.client.post(reverse('documents:document_edit', args=[document.pk]), {'description': TEST_DOCUMENT_DESCRIPTION}) + self.client.post(reverse('documents:document_edit', args=[document.pk]), {'description': TEST_DOCUMENT_DESCRIPTION}) # Fetch document again and test description document = Document.objects.all().first() self.failUnlessEqual(document.description, TEST_DOCUMENT_DESCRIPTION) @@ -300,7 +300,7 @@ class DocumentsViewsFunctionalTestCase(TestCase): # Upload the test document with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor: - response = self.client.post(reverse('sources:upload_interactive'), {'file': file_descriptor, 'document_type_id': self.document_type.pk}) + self.client.post(reverse('sources:upload_interactive'), {'file': file_descriptor, 'document_type_id': self.document_type.pk}) self.assertEqual(Document.objects.count(), 1) self.document = Document.objects.first() diff --git a/mayan/apps/documents/views.py b/mayan/apps/documents/views.py index 033b37b92c..e8fd3ca9ba 100644 --- a/mayan/apps/documents/views.py +++ b/mayan/apps/documents/views.py @@ -1,6 +1,5 @@ from __future__ import absolute_import -import copy import logging import urlparse @@ -18,13 +17,11 @@ import sendfile from acls.models import AccessEntry from common.compressed_files import CompressedFile -from common.utils import (encapsulate, pretty_size, parse_range, return_diff, - urlquote) +from common.utils import encapsulate, pretty_size, parse_range, urlquote from common.views import SingleObjectListView from common.widgets import two_state_template from converter.literals import (DEFAULT_FILE_FORMAT_MIMETYPE, DEFAULT_PAGE_NUMBER, DEFAULT_ROTATION, DEFAULT_ZOOM_LEVEL) -from converter.office_converter import OfficeConverter from filetransfers.api import serve_file from history.api import create_history from navigation.utils import resolve_to_name diff --git a/mayan/apps/dynamic_search/__init__.py b/mayan/apps/dynamic_search/__init__.py index 14dad1b416..dd4da12854 100644 --- a/mayan/apps/dynamic_search/__init__.py +++ b/mayan/apps/dynamic_search/__init__.py @@ -1,7 +1,5 @@ from __future__ import absolute_import -from django.utils.translation import ugettext_lazy as _ - from navigation.api import register_links, register_top_menu from rest_api.classes import APIEndPoint diff --git a/mayan/apps/metadata/admin.py b/mayan/apps/metadata/admin.py index c9ae2ae29d..6f8534f34e 100644 --- a/mayan/apps/metadata/admin.py +++ b/mayan/apps/metadata/admin.py @@ -2,7 +2,7 @@ from __future__ import absolute_import from django.contrib import admin -from .models import DocumentMetadata, MetadataType +from .models import MetadataType class MetadataTypeAdmin(admin.ModelAdmin): diff --git a/mayan/apps/metadata/classes.py b/mayan/apps/metadata/classes.py index 7065dd7974..6008ab04b7 100644 --- a/mayan/apps/metadata/classes.py +++ b/mayan/apps/metadata/classes.py @@ -43,7 +43,7 @@ class DocumentTypeMetadataTypeManager(object): return MetadataType.objects.none() def add(self, metadata_type, required=False): - DocumentTypeMetadataType.objects.create(document_type=self.document_type, metadata_type= metadata_type, required=required) + DocumentTypeMetadataType.objects.create(document_type=self.document_type, metadata_type=metadata_type, required=required) def remove(self, metadata_type): - DocumentTypeMetadataType.objects.get(document_type=self.document_type, metadata_type= metadata_type).delete() + DocumentTypeMetadataType.objects.get(document_type=self.document_type, metadata_type=metadata_type).delete() diff --git a/mayan/apps/metadata/forms.py b/mayan/apps/metadata/forms.py index df286a490c..17d4c34d27 100644 --- a/mayan/apps/metadata/forms.py +++ b/mayan/apps/metadata/forms.py @@ -71,7 +71,7 @@ class AddMetadataForm(forms.Form): def __init__(self, *args, **kwargs): document_type = kwargs.pop('document_type') super(AddMetadataForm, self).__init__(*args, **kwargs) - self.fields['metadata_type'].queryset=document_type.metadata_type.all() + self.fields['metadata_type'].queryset = document_type.metadata_type.all() metadata_type = forms.ModelChoiceField(queryset=MetadataType.objects.all(), label=_(u'Metadata type')) diff --git a/mayan/apps/metadata/views.py b/mayan/apps/metadata/views.py index d283fddfe5..03de8fc97f 100644 --- a/mayan/apps/metadata/views.py +++ b/mayan/apps/metadata/views.py @@ -19,7 +19,6 @@ from common.utils import encapsulate, generate_choices_w_labels from common.views import assign_remove from .api import save_metadata_list -from .classes import MetadataObjectWrapper from .forms import (AddMetadataForm, MetadataFormSet, MetadataRemoveFormSet, MetadataTypeForm) from .models import DocumentMetadata, MetadataType diff --git a/mayan/apps/navigation/classes.py b/mayan/apps/navigation/classes.py index 91d2936dd4..03d671e527 100644 --- a/mayan/apps/navigation/classes.py +++ b/mayan/apps/navigation/classes.py @@ -2,7 +2,6 @@ from __future__ import absolute_import import inspect import logging -import re import urllib import urlparse @@ -257,7 +256,7 @@ class Link(object): args = [] kwargs = {} - if type(src_args) == type([]): + if isinstance(src_args, list): for i in src_args: try: # Try to execute as a function @@ -268,7 +267,7 @@ class Link(object): args.append(val) else: args.append(val) - elif type(src_args) == type({}): + elif isinstance(src_args, dict): for key, value in src_args.items(): try: # Try to execute as a function diff --git a/mayan/apps/ocr/api.py b/mayan/apps/ocr/api.py index a050628789..ffa35e9f12 100644 --- a/mayan/apps/ocr/api.py +++ b/mayan/apps/ocr/api.py @@ -112,7 +112,7 @@ def clean_pages(): """ for page in DocumentPage.objects.all(): if page.content: - page.content = ocr_cleanup(document.language, page.content) + page.content = ocr_cleanup(page.document.language, page.content) page.save() diff --git a/mayan/apps/project_setup/api.py b/mayan/apps/project_setup/api.py index 5f532e1afc..1790d624dd 100644 --- a/mayan/apps/project_setup/api.py +++ b/mayan/apps/project_setup/api.py @@ -1,7 +1,5 @@ from __future__ import absolute_import -from . import setup_link - setup_items = [] diff --git a/mayan/apps/project_tools/api.py b/mayan/apps/project_tools/api.py index b599d28d2f..ed6fba2673 100644 --- a/mayan/apps/project_tools/api.py +++ b/mayan/apps/project_tools/api.py @@ -1,7 +1,5 @@ from __future__ import absolute_import -from . import tool_link - tool_items = [] diff --git a/mayan/apps/registration/views.py b/mayan/apps/registration/views.py index 85512896ec..607fc5e9cd 100644 --- a/mayan/apps/registration/views.py +++ b/mayan/apps/registration/views.py @@ -31,5 +31,4 @@ def form_view(request): return render_to_response('main/generic_form.html', { 'title': _(u'Registration form'), 'form': form, - }, - context_instance=RequestContext(request)) + }, context_instance=RequestContext(request)) diff --git a/mayan/apps/rest_api/__init__.py b/mayan/apps/rest_api/__init__.py index 6ce45d06ff..4302aec3ad 100644 --- a/mayan/apps/rest_api/__init__.py +++ b/mayan/apps/rest_api/__init__.py @@ -1,7 +1,5 @@ from __future__ import absolute_import -from django.utils.translation import ugettext_lazy as _ - from project_tools.api import register_tool from .classes import APIEndPoint diff --git a/mayan/apps/rest_api/classes.py b/mayan/apps/rest_api/classes.py index 919f7acfcc..29e631b435 100644 --- a/mayan/apps/rest_api/classes.py +++ b/mayan/apps/rest_api/classes.py @@ -1,7 +1,6 @@ from __future__ import absolute_import from django.conf.urls import include, patterns, url -from django.utils.importlib import import_module from common.utils import load_backend @@ -25,7 +24,7 @@ class APIEndPoint(object): self.endpoints = [] try: api_urls = load_backend('{}.urls.api_urls'.format(app_name or name)) - except Exception as exception: + except Exception: # Ignore import time errors pass else: diff --git a/mayan/apps/rest_api/views.py b/mayan/apps/rest_api/views.py index 2f3f639404..1997e4c0d1 100644 --- a/mayan/apps/rest_api/views.py +++ b/mayan/apps/rest_api/views.py @@ -53,8 +53,6 @@ class APIAppView(generics.GenericAPIView): serializer_class = APIAppSerializer def get(self, request, app_name, format=None): - result = [] - api_app = APIEndPoint.get(app_name) return Response({ diff --git a/mayan/apps/sources/models.py b/mayan/apps/sources/models.py index 2516000aad..ed57ec7326 100644 --- a/mayan/apps/sources/models.py +++ b/mayan/apps/sources/models.py @@ -13,7 +13,7 @@ from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.core.files import File -from django.db import models, transaction +from django.db import models from django.utils.translation import ugettext_lazy as _ from model_utils.managers import InheritanceManager diff --git a/mayan/apps/sources/tasks.py b/mayan/apps/sources/tasks.py index 0e6a776e1e..917c0f1574 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 common.models import SharedUploadedFile -from documents.models import Document, DocumentType +from documents.models import DocumentType from .models import Source diff --git a/mayan/apps/sources/views.py b/mayan/apps/sources/views.py index a019d5fc69..fcd8a33224 100644 --- a/mayan/apps/sources/views.py +++ b/mayan/apps/sources/views.py @@ -1,7 +1,5 @@ from __future__ import absolute_import -import tempfile - from django.conf import settings from django.contrib import messages from django.core.exceptions import PermissionDenied @@ -10,7 +8,6 @@ from django.http import HttpResponseRedirect from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from django.utils.http import urlencode -from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from acls.models import AccessEntry @@ -20,7 +17,7 @@ from common.views import MultiFormView from documents.models import DocumentType, Document from documents.permissions import (PERMISSION_DOCUMENT_CREATE, PERMISSION_DOCUMENT_NEW_VERSION) -from documents.tasks import task_new_document, task_upload_new_version +from documents.tasks import task_upload_new_version from metadata.api import decode_metadata_from_url, metadata_repr_as_list from permissions.models import Permission diff --git a/mayan/apps/tags/tests.py b/mayan/apps/tags/tests.py index ca90d6806a..15e7cad474 100644 --- a/mayan/apps/tags/tests.py +++ b/mayan/apps/tags/tests.py @@ -1,7 +1,6 @@ import os from django.conf import settings -from django.contrib.auth.models import User from django.core.files.base import File from django.test import TestCase diff --git a/mayan/apps/user_management/__init__.py b/mayan/apps/user_management/__init__.py index 791d0c4928..6edf42c966 100644 --- a/mayan/apps/user_management/__init__.py +++ b/mayan/apps/user_management/__init__.py @@ -1,7 +1,6 @@ from __future__ import absolute_import from django.contrib.auth.models import User, Group -from django.utils.translation import ugettext_lazy as _ from navigation.api import register_links from navigation.links import link_spacer