PEP8 Cleanups.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
import os
|
||||
import optparse
|
||||
|
||||
|
||||
@@ -8,4 +8,3 @@ if __name__ == "__main__":
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import apps
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common import MayanAppConfig
|
||||
|
||||
@@ -13,7 +13,7 @@ from authentication.tests.literals import (
|
||||
)
|
||||
from documents.models import DocumentType
|
||||
from documents.tests.literals import (
|
||||
TEST_DOCUMENT_TYPE, TEST_DOCUMENT_PATH, TEST_SMALL_DOCUMENT_PATH
|
||||
TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
|
||||
)
|
||||
|
||||
from ..exceptions import (
|
||||
|
||||
@@ -7,8 +7,7 @@ from django.test.client import Client
|
||||
from django.test import TestCase
|
||||
|
||||
from documents.tests.literals import (
|
||||
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL,
|
||||
TEST_SMALL_DOCUMENT_PATH, TEST_DOCUMENT_TYPE
|
||||
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -159,10 +159,10 @@ class PackagesLicensesView(SimpleView):
|
||||
# Use a function so that PackagesLicensesForm get initialized at every
|
||||
# request
|
||||
return {
|
||||
'form': PackagesLicensesForm(),
|
||||
'read_only': True,
|
||||
'title': _('Other packages licenses'),
|
||||
}
|
||||
'form': PackagesLicensesForm(),
|
||||
'read_only': True,
|
||||
'title': _('Other packages licenses'),
|
||||
}
|
||||
|
||||
|
||||
class SetupListView(TemplateView):
|
||||
|
||||
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
try:
|
||||
@@ -131,7 +130,7 @@ class ConverterBase(object):
|
||||
if self.mime_type == 'text/plain':
|
||||
libreoffice_filter = 'Text (encoded):UTF8,LF,,,'
|
||||
|
||||
args=(input_filepath, '--outdir', setting_temporary_directory.value)
|
||||
args = (input_filepath, '--outdir', setting_temporary_directory.value)
|
||||
|
||||
kwargs = {'_env': {'HOME': setting_temporary_directory.value}}
|
||||
|
||||
|
||||
@@ -28,18 +28,20 @@ class Transformation(models.Model):
|
||||
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')
|
||||
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')
|
||||
blank=True, help_text=_(
|
||||
'Enter the arguments for the transformation as a YAML '
|
||||
'dictionary. ie: {"degrees": 180}'
|
||||
), validators=[YAMLValidator()], verbose_name=_('Arguments')
|
||||
)
|
||||
|
||||
objects = TransformationManager()
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -3,7 +3,6 @@ from __future__ import unicode_literals
|
||||
import base64
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
@@ -15,7 +14,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.settings import setting_temporary_directory
|
||||
from converter import (
|
||||
converter_class, TransformationResize, TransformationRotate,
|
||||
TransformationZoom
|
||||
|
||||
@@ -15,9 +15,7 @@ from .literals import (
|
||||
UPDATE_PAGE_COUNT_RETRY_DELAY, UPLOAD_NEW_VERSION_RETRY_DELAY,
|
||||
NEW_DOCUMENT_RETRY_DELAY, STUB_EXPIRATION_INTERVAL
|
||||
)
|
||||
from .models import (
|
||||
DeletedDocument, Document, DocumentPage, DocumentType, DocumentVersion
|
||||
)
|
||||
from .models import Document, DocumentPage, DocumentType, DocumentVersion
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ import time
|
||||
from django.core.files import File
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from common.literals import TIME_DELTA_UNIT_DAYS
|
||||
|
||||
from .literals import (
|
||||
TEST_DOCUMENT_TYPE, TEST_DOCUMENT_PATH, TEST_MULTI_PAGE_TIFF_PATH,
|
||||
TEST_OFFICE_DOCUMENT_PATH, TEST_SMALL_DOCUMENT_PATH
|
||||
|
||||
@@ -17,4 +17,6 @@ class AdvancedSearchForm(forms.Form):
|
||||
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
q = forms.CharField(max_length=128, label=_('Search terms'), required=False)
|
||||
q = forms.CharField(
|
||||
max_length=128, label=_('Search terms'), required=False
|
||||
)
|
||||
|
||||
@@ -35,7 +35,9 @@ class RecentSearch(models.Model):
|
||||
from .classes import SearchModel
|
||||
document_search = SearchModel.get('documents.Document')
|
||||
|
||||
query_dict = urlparse.parse_qs(urllib.unquote_plus(smart_str(self.query)))
|
||||
query_dict = urlparse.parse_qs(
|
||||
urllib.unquote_plus(smart_str(self.query))
|
||||
)
|
||||
|
||||
if self.is_advanced():
|
||||
# Advanced search
|
||||
|
||||
@@ -8,7 +8,9 @@ from .models import RecentSearch
|
||||
|
||||
|
||||
class RecentSearchSerializer(serializers.HyperlinkedModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='rest_api:recentsearch-detail')
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='rest_api:recentsearch-detail'
|
||||
)
|
||||
user = UserSerializer()
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -44,7 +44,9 @@ class ResultsView(SingleObjectListView):
|
||||
# Only do search if there is user input, otherwise just render
|
||||
# the template with the extra_context
|
||||
|
||||
queryset, ids, timedelta = document_search.search(self.request.GET, self.request.user)
|
||||
queryset, ids, timedelta = document_search.search(
|
||||
self.request.GET, self.request.user
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -38,7 +38,9 @@ def send_document_link(request, document_id=None, document_id_list=None, as_atta
|
||||
if document_id:
|
||||
documents = [get_object_or_404(Document, pk=document_id)]
|
||||
elif document_id_list:
|
||||
documents = [get_object_or_404(Document, pk=document_id) for document_id in document_id_list.split(',')]
|
||||
documents = [
|
||||
get_object_or_404(Document, pk=document_id) for document_id in document_id_list.split(',')
|
||||
]
|
||||
|
||||
if as_attachment:
|
||||
permission = permission_mailing_send_document
|
||||
@@ -48,15 +50,25 @@ def send_document_link(request, document_id=None, document_id_list=None, as_atta
|
||||
try:
|
||||
Permission.check_permissions(request.user, (permission,))
|
||||
except PermissionDenied:
|
||||
documents = AccessControlList.objects.filter_by_access(permission, request.user, documents)
|
||||
documents = AccessControlList.objects.filter_by_access(
|
||||
permission, request.user, documents
|
||||
)
|
||||
|
||||
if not documents:
|
||||
messages.error(request, _('Must provide at least one document.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL)))
|
||||
return HttpResponseRedirect(
|
||||
request.META.get(
|
||||
'HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL)
|
||||
)
|
||||
)
|
||||
|
||||
post_action_redirect = reverse('documents:document_list_recent')
|
||||
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', post_action_redirect)))
|
||||
next = request.POST.get(
|
||||
'next', request.GET.get(
|
||||
'next', request.META.get('HTTP_REFERER', post_action_redirect)
|
||||
)
|
||||
)
|
||||
|
||||
for document in documents:
|
||||
document.add_as_recent_document_for_user(request.user)
|
||||
@@ -77,7 +89,15 @@ def send_document_link(request, document_id=None, document_id_list=None, as_atta
|
||||
subject_template = Template(form.cleaned_data['subject'])
|
||||
subject_text = strip_tags(subject_template.render(context))
|
||||
|
||||
task_send_document.apply_async(args=(subject_text, body_text_content, request.user.email, form.cleaned_data['email']), kwargs={'document_id': document.pk, 'as_attachment': as_attachment})
|
||||
task_send_document.apply_async(
|
||||
args=(
|
||||
subject_text, body_text_content, request.user.email,
|
||||
form.cleaned_data['email']
|
||||
), kwargs={
|
||||
'document_id': document.pk,
|
||||
'as_attachment': as_attachment
|
||||
}
|
||||
)
|
||||
|
||||
# TODO: Pluralize
|
||||
messages.success(request, _('Successfully queued for delivery via email.'))
|
||||
@@ -103,5 +123,7 @@ def send_document_link(request, document_id=None, document_id_list=None, as_atta
|
||||
else:
|
||||
context['title'] = _('Email links for documents: %s') % ', '.join([unicode(d) for d in documents])
|
||||
|
||||
return render_to_response('appearance/generic_form.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
return render_to_response(
|
||||
'appearance/generic_form.html', context,
|
||||
context_instance=RequestContext(request)
|
||||
)
|
||||
|
||||
@@ -137,7 +137,9 @@ class MetadataApp(MayanAppConfig):
|
||||
)
|
||||
SourceColumn(
|
||||
source=DocumentMetadata, label=_('Required'),
|
||||
func=lambda context: two_state_template(context['object'].is_required)
|
||||
func=lambda context: two_state_template(
|
||||
context['object'].is_required
|
||||
)
|
||||
)
|
||||
|
||||
app.conf.CELERY_QUEUES.append(
|
||||
|
||||
@@ -18,7 +18,9 @@ class MetadataForm(forms.Form):
|
||||
self.document_type = kwargs['initial'].pop('document_type', None)
|
||||
required_string = ''
|
||||
|
||||
required = self.metadata_type.get_required_for(document_type=self.document_type)
|
||||
required = self.metadata_type.get_required_for(
|
||||
document_type=self.document_type
|
||||
)
|
||||
if required:
|
||||
self.fields['value'].required = True
|
||||
required_string = ' (%s)' % _('Required')
|
||||
@@ -66,7 +68,9 @@ class MetadataForm(forms.Form):
|
||||
)
|
||||
|
||||
def clean_value(self):
|
||||
return self.metadata_type.validate_value(document_type=self.document_type, value=self.cleaned_data['value'])
|
||||
return self.metadata_type.validate_value(
|
||||
document_type=self.document_type, value=self.cleaned_data['value']
|
||||
)
|
||||
|
||||
id = forms.CharField(label=_('ID'), widget=forms.HiddenInput)
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ from .views import (
|
||||
|
||||
urlpatterns = patterns(
|
||||
'metadata.views',
|
||||
url(r'^(?P<document_id>\d+)/edit/$', 'metadata_edit', name='metadata_edit'),
|
||||
url(
|
||||
r'^(?P<document_id>\d+)/edit/$', 'metadata_edit', name='metadata_edit'
|
||||
),
|
||||
url(
|
||||
r'^(?P<pk>\d+)/view/$', DocumentMetadataListView.as_view(),
|
||||
name='metadata_view'
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import apps
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common import MayanAppConfig
|
||||
from common.classes import Package
|
||||
|
||||
|
||||
class MIMETypesApp(apps.AppConfig):
|
||||
class MIMETypesApp(MayanAppConfig):
|
||||
name = 'mimetype'
|
||||
verbose_name = _('MIME types')
|
||||
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from rest_framework import generics, status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from acls.models import AccessControlList
|
||||
from documents.models import Document, DocumentPage, DocumentVersion
|
||||
from permissions import Permission
|
||||
from rest_api.filters import MayanObjectPermissionsFilter
|
||||
from rest_api.permissions import MayanPermission
|
||||
|
||||
from .models import DocumentPageContent
|
||||
|
||||
@@ -75,7 +75,9 @@ class Parser(object):
|
||||
raise NoMIMETypeMatch
|
||||
|
||||
def process_document_version(self, document_version):
|
||||
logger.info('Starting parsing for document version: %s', document_version)
|
||||
logger.info(
|
||||
'Starting parsing for document version: %s', document_version
|
||||
)
|
||||
logger.debug('document version: %d', document_version.pk)
|
||||
|
||||
for document_page in document_version.pages.all():
|
||||
@@ -124,7 +126,9 @@ class PopplerParser(Parser):
|
||||
def __init__(self):
|
||||
self.pdftotext_path = setting_pdftotext_path.value
|
||||
if not os.path.exists(self.pdftotext_path):
|
||||
error_message = _('Cannot find pdftotext executable at: %s') % self.pdftotext_path
|
||||
error_message = _(
|
||||
'Cannot find pdftotext executable at: %s'
|
||||
) % self.pdftotext_path
|
||||
logger.error(error_message)
|
||||
raise ParserError(error_message)
|
||||
|
||||
@@ -178,9 +182,13 @@ class PDFMinerParser(Parser):
|
||||
|
||||
with BytesIO() as string_buffer:
|
||||
rsrcmgr = PDFResourceManager()
|
||||
device = TextConverter(rsrcmgr, outfp=string_buffer, laparams=LAParams())
|
||||
device = TextConverter(
|
||||
rsrcmgr, outfp=string_buffer, laparams=LAParams()
|
||||
)
|
||||
interpreter = PDFPageInterpreter(rsrcmgr, device)
|
||||
page = PDFPage.get_pages(file_object, maxpages=1, pagenos=(page_number - 1,))
|
||||
page = PDFPage.get_pages(
|
||||
file_object, maxpages=1, pagenos=(page_number - 1,)
|
||||
)
|
||||
interpreter.process_page(page.next())
|
||||
device.close()
|
||||
|
||||
@@ -189,5 +197,6 @@ class PDFMinerParser(Parser):
|
||||
return string_buffer.getvalue()
|
||||
|
||||
Parser.register(
|
||||
mimetypes=('application/pdf',), parser_classes=(PopplerParser, PDFMinerParser)
|
||||
mimetypes=('application/pdf',),
|
||||
parser_classes=(PopplerParser, PDFMinerParser)
|
||||
)
|
||||
|
||||
@@ -58,13 +58,12 @@ api_urls = patterns(
|
||||
name='document-ocr-submit-view'
|
||||
),
|
||||
url(
|
||||
r'^document_version/(?P<pk>\d+)/submit/$', APIDocumentVersionOCRView.as_view(),
|
||||
r'^document_version/(?P<pk>\d+)/submit/$',
|
||||
APIDocumentVersionOCRView.as_view(),
|
||||
name='document-version-ocr-submit-view'
|
||||
),
|
||||
url(
|
||||
r'^page/(?P<pk>\d+)/content/$', APIDocumentPageContentView.as_view(),
|
||||
name='document-page-content-view'
|
||||
),
|
||||
|
||||
)
|
||||
|
||||
|
||||
@@ -160,7 +160,9 @@ class APIDocumentTagListView(generics.ListCreateAPIView):
|
||||
Attach a tag to a document.
|
||||
"""
|
||||
|
||||
return super(APIDocumentTagListView, self).post(request, *args, **kwargs)
|
||||
return super(
|
||||
APIDocumentTagListView, self
|
||||
).post(request, *args, **kwargs)
|
||||
|
||||
|
||||
class APIDocumentTagView(generics.RetrieveDestroyAPIView):
|
||||
@@ -176,7 +178,9 @@ class APIDocumentTagView(generics.RetrieveDestroyAPIView):
|
||||
Remove a tag from the selected document.
|
||||
"""
|
||||
|
||||
return super(APIDocumentTagView, self).delete(request, *args, **kwargs)
|
||||
return super(
|
||||
APIDocumentTagView, self
|
||||
).delete(request, *args, **kwargs)
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
"""
|
||||
|
||||
@@ -37,7 +37,10 @@ class TagsApp(MayanAppConfig):
|
||||
|
||||
APIEndPoint(app=self, version_string='1')
|
||||
|
||||
Document.add_to_class('attached_tags', lambda document: DocumentTag.objects.filter(documents=document))
|
||||
Document.add_to_class(
|
||||
'attached_tags',
|
||||
lambda document: DocumentTag.objects.filter(documents=document)
|
||||
)
|
||||
|
||||
ModelPermission.register(
|
||||
model=Document, permissions=(
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -15,14 +15,18 @@ from .permissions import permission_tag_attach
|
||||
|
||||
|
||||
class TagSerializer(serializers.HyperlinkedModelSerializer):
|
||||
documents = serializers.HyperlinkedIdentityField(view_name='rest_api:tag-document-list')
|
||||
documents = serializers.HyperlinkedIdentityField(
|
||||
view_name='rest_api:tag-document-list'
|
||||
)
|
||||
documents_count = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
extra_kwargs = {
|
||||
'url': {'view_name': 'rest_api:tag-detail'},
|
||||
}
|
||||
fields = ('color', 'documents', 'documents_count', 'id', 'label', 'url')
|
||||
fields = (
|
||||
'color', 'documents', 'documents_count', 'id', 'label', 'url'
|
||||
)
|
||||
model = Tag
|
||||
|
||||
def get_documents_count(self, instance):
|
||||
@@ -30,14 +34,18 @@ class TagSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
|
||||
class NewDocumentTagSerializer(serializers.Serializer):
|
||||
tag = serializers.IntegerField(help_text=_('Primary key of the tag to be added.'))
|
||||
tag = serializers.IntegerField(
|
||||
help_text=_('Primary key of the tag to be added.')
|
||||
)
|
||||
|
||||
def create(self, validated_data):
|
||||
try:
|
||||
tag = Tag.objects.get(pk=validated_data['tag'])
|
||||
|
||||
try:
|
||||
Permission.check_permissions(self.context['request'].user, (permission_tag_attach,))
|
||||
Permission.check_permissions(
|
||||
self.context['request'].user, (permission_tag_attach,)
|
||||
)
|
||||
except PermissionDenied:
|
||||
AccessControlList.objects.check_access(
|
||||
permission_tag_attach, self.context['request'], tag
|
||||
|
||||
4
setup.py
4
setup.py
@@ -49,7 +49,9 @@ def find_packages(directory):
|
||||
if '__init__.py' in filenames:
|
||||
packages.append('.'.join(fullsplit(dirpath)))
|
||||
elif filenames:
|
||||
data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
|
||||
data_files.append(
|
||||
[dirpath, [os.path.join(dirpath, f) for f in filenames]]
|
||||
)
|
||||
|
||||
return packages
|
||||
|
||||
|
||||
Reference in New Issue
Block a user