PEP8 Cleanups.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import optparse
|
import optparse
|
||||||
|
|
||||||
|
|||||||
@@ -8,4 +8,3 @@ if __name__ == "__main__":
|
|||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
|
|
||||||
execute_from_command_line(sys.argv)
|
execute_from_command_line(sys.argv)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import apps
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from common import MayanAppConfig
|
from common import MayanAppConfig
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from authentication.tests.literals import (
|
|||||||
)
|
)
|
||||||
from documents.models import DocumentType
|
from documents.models import DocumentType
|
||||||
from documents.tests.literals import (
|
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 (
|
from ..exceptions import (
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ from django.test.client import Client
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from documents.tests.literals import (
|
from documents.tests.literals import (
|
||||||
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL,
|
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL
|
||||||
TEST_SMALL_DOCUMENT_PATH, TEST_DOCUMENT_TYPE
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -159,10 +159,10 @@ class PackagesLicensesView(SimpleView):
|
|||||||
# Use a function so that PackagesLicensesForm get initialized at every
|
# Use a function so that PackagesLicensesForm get initialized at every
|
||||||
# request
|
# request
|
||||||
return {
|
return {
|
||||||
'form': PackagesLicensesForm(),
|
'form': PackagesLicensesForm(),
|
||||||
'read_only': True,
|
'read_only': True,
|
||||||
'title': _('Other packages licenses'),
|
'title': _('Other packages licenses'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SetupListView(TemplateView):
|
class SetupListView(TemplateView):
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -131,7 +130,7 @@ class ConverterBase(object):
|
|||||||
if self.mime_type == 'text/plain':
|
if self.mime_type == 'text/plain':
|
||||||
libreoffice_filter = 'Text (encoded):UTF8,LF,,,'
|
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}}
|
kwargs = {'_env': {'HOME': setting_temporary_directory.value}}
|
||||||
|
|
||||||
|
|||||||
@@ -28,18 +28,20 @@ class Transformation(models.Model):
|
|||||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||||
|
|
||||||
order = models.PositiveIntegerField(
|
order = models.PositiveIntegerField(
|
||||||
blank=True, db_index=True, default=0,
|
blank=True, db_index=True, default=0, help_text=_(
|
||||||
help_text=_('Order in which the transformations will be executed. If left unchanged, an automatic order value will be assigned.'),
|
'Order in which the transformations will be executed. If left '
|
||||||
verbose_name=_('Order')
|
'unchanged, an automatic order value will be assigned.'
|
||||||
|
), verbose_name=_('Order')
|
||||||
)
|
)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
choices=BaseTransformation.get_transformation_choices(),
|
choices=BaseTransformation.get_transformation_choices(),
|
||||||
max_length=128, verbose_name=_('Name')
|
max_length=128, verbose_name=_('Name')
|
||||||
)
|
)
|
||||||
arguments = models.TextField(
|
arguments = models.TextField(
|
||||||
blank=True,
|
blank=True, help_text=_(
|
||||||
help_text=_('Enter the arguments for the transformation as a YAML dictionary. ie: {"degrees": 180}'),
|
'Enter the arguments for the transformation as a YAML '
|
||||||
validators=[YAMLValidator()], verbose_name=_('Arguments')
|
'dictionary. ie: {"degrees": 180}'
|
||||||
|
), validators=[YAMLValidator()], verbose_name=_('Arguments')
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = TransformationManager()
|
objects = TransformationManager()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models, migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ from __future__ import unicode_literals
|
|||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
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 django.utils.translation import ugettext, ugettext_lazy as _
|
||||||
|
|
||||||
from common.literals import TIME_DELTA_UNIT_CHOICES
|
from common.literals import TIME_DELTA_UNIT_CHOICES
|
||||||
from common.settings import setting_temporary_directory
|
|
||||||
from converter import (
|
from converter import (
|
||||||
converter_class, TransformationResize, TransformationRotate,
|
converter_class, TransformationResize, TransformationRotate,
|
||||||
TransformationZoom
|
TransformationZoom
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ from .literals import (
|
|||||||
UPDATE_PAGE_COUNT_RETRY_DELAY, UPLOAD_NEW_VERSION_RETRY_DELAY,
|
UPDATE_PAGE_COUNT_RETRY_DELAY, UPLOAD_NEW_VERSION_RETRY_DELAY,
|
||||||
NEW_DOCUMENT_RETRY_DELAY, STUB_EXPIRATION_INTERVAL
|
NEW_DOCUMENT_RETRY_DELAY, STUB_EXPIRATION_INTERVAL
|
||||||
)
|
)
|
||||||
from .models import (
|
from .models import Document, DocumentPage, DocumentType, DocumentVersion
|
||||||
DeletedDocument, Document, DocumentPage, DocumentType, DocumentVersion
|
|
||||||
)
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import time
|
|||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
|
||||||
from common.literals import TIME_DELTA_UNIT_DAYS
|
|
||||||
|
|
||||||
from .literals import (
|
from .literals import (
|
||||||
TEST_DOCUMENT_TYPE, TEST_DOCUMENT_PATH, TEST_MULTI_PAGE_TIFF_PATH,
|
TEST_DOCUMENT_TYPE, TEST_DOCUMENT_PATH, TEST_MULTI_PAGE_TIFF_PATH,
|
||||||
TEST_OFFICE_DOCUMENT_PATH, TEST_SMALL_DOCUMENT_PATH
|
TEST_OFFICE_DOCUMENT_PATH, TEST_SMALL_DOCUMENT_PATH
|
||||||
|
|||||||
@@ -17,4 +17,6 @@ class AdvancedSearchForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
class SearchForm(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
|
from .classes import SearchModel
|
||||||
document_search = SearchModel.get('documents.Document')
|
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():
|
if self.is_advanced():
|
||||||
# Advanced search
|
# Advanced search
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ from .models import RecentSearch
|
|||||||
|
|
||||||
|
|
||||||
class RecentSearchSerializer(serializers.HyperlinkedModelSerializer):
|
class RecentSearchSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='rest_api:recentsearch-detail')
|
url = serializers.HyperlinkedIdentityField(
|
||||||
|
view_name='rest_api:recentsearch-detail'
|
||||||
|
)
|
||||||
user = UserSerializer()
|
user = UserSerializer()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ class ResultsView(SingleObjectListView):
|
|||||||
# Only do search if there is user input, otherwise just render
|
# Only do search if there is user input, otherwise just render
|
||||||
# the template with the extra_context
|
# 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
|
return queryset
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models, migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
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:
|
if document_id:
|
||||||
documents = [get_object_or_404(Document, pk=document_id)]
|
documents = [get_object_or_404(Document, pk=document_id)]
|
||||||
elif document_id_list:
|
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:
|
if as_attachment:
|
||||||
permission = permission_mailing_send_document
|
permission = permission_mailing_send_document
|
||||||
@@ -48,15 +50,25 @@ def send_document_link(request, document_id=None, document_id_list=None, as_atta
|
|||||||
try:
|
try:
|
||||||
Permission.check_permissions(request.user, (permission,))
|
Permission.check_permissions(request.user, (permission,))
|
||||||
except PermissionDenied:
|
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:
|
if not documents:
|
||||||
messages.error(request, _('Must provide at least one document.'))
|
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')
|
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:
|
for document in documents:
|
||||||
document.add_as_recent_document_for_user(request.user)
|
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_template = Template(form.cleaned_data['subject'])
|
||||||
subject_text = strip_tags(subject_template.render(context))
|
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
|
# TODO: Pluralize
|
||||||
messages.success(request, _('Successfully queued for delivery via email.'))
|
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:
|
else:
|
||||||
context['title'] = _('Email links for documents: %s') % ', '.join([unicode(d) for d in documents])
|
context['title'] = _('Email links for documents: %s') % ', '.join([unicode(d) for d in documents])
|
||||||
|
|
||||||
return render_to_response('appearance/generic_form.html', context,
|
return render_to_response(
|
||||||
context_instance=RequestContext(request))
|
'appearance/generic_form.html', context,
|
||||||
|
context_instance=RequestContext(request)
|
||||||
|
)
|
||||||
|
|||||||
@@ -137,7 +137,9 @@ class MetadataApp(MayanAppConfig):
|
|||||||
)
|
)
|
||||||
SourceColumn(
|
SourceColumn(
|
||||||
source=DocumentMetadata, label=_('Required'),
|
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(
|
app.conf.CELERY_QUEUES.append(
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ class MetadataForm(forms.Form):
|
|||||||
self.document_type = kwargs['initial'].pop('document_type', None)
|
self.document_type = kwargs['initial'].pop('document_type', None)
|
||||||
required_string = ''
|
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:
|
if required:
|
||||||
self.fields['value'].required = True
|
self.fields['value'].required = True
|
||||||
required_string = ' (%s)' % _('Required')
|
required_string = ' (%s)' % _('Required')
|
||||||
@@ -66,7 +68,9 @@ class MetadataForm(forms.Form):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def clean_value(self):
|
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)
|
id = forms.CharField(label=_('ID'), widget=forms.HiddenInput)
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ from .views import (
|
|||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'metadata.views',
|
'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(
|
url(
|
||||||
r'^(?P<pk>\d+)/view/$', DocumentMetadataListView.as_view(),
|
r'^(?P<pk>\d+)/view/$', DocumentMetadataListView.as_view(),
|
||||||
name='metadata_view'
|
name='metadata_view'
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import apps
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from common import MayanAppConfig
|
from common import MayanAppConfig
|
||||||
from common.classes import Package
|
from common.classes import Package
|
||||||
|
|
||||||
|
|
||||||
class MIMETypesApp(apps.AppConfig):
|
class MIMETypesApp(MayanAppConfig):
|
||||||
name = 'mimetype'
|
name = 'mimetype'
|
||||||
verbose_name = _('MIME types')
|
verbose_name = _('MIME types')
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
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 import generics, status
|
||||||
from rest_framework.response import Response
|
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 documents.models import Document, DocumentPage, DocumentVersion
|
||||||
from permissions import Permission
|
|
||||||
from rest_api.filters import MayanObjectPermissionsFilter
|
|
||||||
from rest_api.permissions import MayanPermission
|
from rest_api.permissions import MayanPermission
|
||||||
|
|
||||||
from .models import DocumentPageContent
|
from .models import DocumentPageContent
|
||||||
|
|||||||
@@ -75,7 +75,9 @@ class Parser(object):
|
|||||||
raise NoMIMETypeMatch
|
raise NoMIMETypeMatch
|
||||||
|
|
||||||
def process_document_version(self, document_version):
|
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)
|
logger.debug('document version: %d', document_version.pk)
|
||||||
|
|
||||||
for document_page in document_version.pages.all():
|
for document_page in document_version.pages.all():
|
||||||
@@ -124,7 +126,9 @@ class PopplerParser(Parser):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.pdftotext_path = setting_pdftotext_path.value
|
self.pdftotext_path = setting_pdftotext_path.value
|
||||||
if not os.path.exists(self.pdftotext_path):
|
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)
|
logger.error(error_message)
|
||||||
raise ParserError(error_message)
|
raise ParserError(error_message)
|
||||||
|
|
||||||
@@ -178,9 +182,13 @@ class PDFMinerParser(Parser):
|
|||||||
|
|
||||||
with BytesIO() as string_buffer:
|
with BytesIO() as string_buffer:
|
||||||
rsrcmgr = PDFResourceManager()
|
rsrcmgr = PDFResourceManager()
|
||||||
device = TextConverter(rsrcmgr, outfp=string_buffer, laparams=LAParams())
|
device = TextConverter(
|
||||||
|
rsrcmgr, outfp=string_buffer, laparams=LAParams()
|
||||||
|
)
|
||||||
interpreter = PDFPageInterpreter(rsrcmgr, device)
|
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())
|
interpreter.process_page(page.next())
|
||||||
device.close()
|
device.close()
|
||||||
|
|
||||||
@@ -189,5 +197,6 @@ class PDFMinerParser(Parser):
|
|||||||
return string_buffer.getvalue()
|
return string_buffer.getvalue()
|
||||||
|
|
||||||
Parser.register(
|
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'
|
name='document-ocr-submit-view'
|
||||||
),
|
),
|
||||||
url(
|
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'
|
name='document-version-ocr-submit-view'
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r'^page/(?P<pk>\d+)/content/$', APIDocumentPageContentView.as_view(),
|
r'^page/(?P<pk>\d+)/content/$', APIDocumentPageContentView.as_view(),
|
||||||
name='document-page-content-view'
|
name='document-page-content-view'
|
||||||
),
|
),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,9 @@ class APIDocumentTagListView(generics.ListCreateAPIView):
|
|||||||
Attach a tag to a document.
|
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):
|
class APIDocumentTagView(generics.RetrieveDestroyAPIView):
|
||||||
@@ -176,7 +178,9 @@ class APIDocumentTagView(generics.RetrieveDestroyAPIView):
|
|||||||
Remove a tag from the selected document.
|
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):
|
def get(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ class TagsApp(MayanAppConfig):
|
|||||||
|
|
||||||
APIEndPoint(app=self, version_string='1')
|
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(
|
ModelPermission.register(
|
||||||
model=Document, permissions=(
|
model=Document, permissions=(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models, migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|||||||
@@ -15,14 +15,18 @@ from .permissions import permission_tag_attach
|
|||||||
|
|
||||||
|
|
||||||
class TagSerializer(serializers.HyperlinkedModelSerializer):
|
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()
|
documents_count = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'url': {'view_name': 'rest_api:tag-detail'},
|
'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
|
model = Tag
|
||||||
|
|
||||||
def get_documents_count(self, instance):
|
def get_documents_count(self, instance):
|
||||||
@@ -30,14 +34,18 @@ class TagSerializer(serializers.HyperlinkedModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class NewDocumentTagSerializer(serializers.Serializer):
|
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):
|
def create(self, validated_data):
|
||||||
try:
|
try:
|
||||||
tag = Tag.objects.get(pk=validated_data['tag'])
|
tag = Tag.objects.get(pk=validated_data['tag'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Permission.check_permissions(self.context['request'].user, (permission_tag_attach,))
|
Permission.check_permissions(
|
||||||
|
self.context['request'].user, (permission_tag_attach,)
|
||||||
|
)
|
||||||
except PermissionDenied:
|
except PermissionDenied:
|
||||||
AccessControlList.objects.check_access(
|
AccessControlList.objects.check_access(
|
||||||
permission_tag_attach, self.context['request'], tag
|
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:
|
if '__init__.py' in filenames:
|
||||||
packages.append('.'.join(fullsplit(dirpath)))
|
packages.append('.'.join(fullsplit(dirpath)))
|
||||||
elif filenames:
|
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
|
return packages
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user