PEP8, pylint cleanups and removal of relative imports
This commit is contained in:
@@ -10,8 +10,8 @@ from permissions.api import register_permissions
|
||||
from documents.models import Document
|
||||
|
||||
from ocr.conf.settings import AUTOMATIC_OCR
|
||||
from models import DocumentQueue, QueueDocument
|
||||
from literals import QUEUEDOCUMENT_STATE_PROCESSING, \
|
||||
from ocr.models import DocumentQueue, QueueDocument
|
||||
from ocr.literals import QUEUEDOCUMENT_STATE_PROCESSING, \
|
||||
QUEUEDOCUMENT_STATE_PENDING, DOCUMENTQUEUE_STATE_STOPPED, \
|
||||
DOCUMENTQUEUE_STATE_ACTIVE
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from models import DocumentQueue, QueueDocument
|
||||
from ocr.models import DocumentQueue, QueueDocument
|
||||
|
||||
|
||||
class QueueDocumentInline(admin.StackedInline):
|
||||
|
||||
@@ -15,7 +15,7 @@ from documents.models import DocumentPage
|
||||
from ocr.conf.settings import TESSERACT_PATH
|
||||
from ocr.conf.settings import TESSERACT_LANGUAGE
|
||||
from ocr.conf.settings import PDFTOTEXT_PATH
|
||||
from exceptions import TesseractError, PdftotextError
|
||||
from ocr.exceptions import TesseractError, PdftotextError
|
||||
|
||||
|
||||
def get_language_backend():
|
||||
@@ -59,7 +59,7 @@ def run_pdftotext(input_filename, output_filename, page_number=None):
|
||||
if return_code != 0:
|
||||
error_text = proc.stderr.read()
|
||||
raise PdftotextError(error_text)
|
||||
|
||||
|
||||
|
||||
def do_document_ocr(document):
|
||||
for page_index, document_page in enumerate(document.documentpage_set.all()):
|
||||
|
||||
@@ -4,7 +4,7 @@ class AlreadyQueued(Exception):
|
||||
|
||||
class TesseractError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
class PdftotextError(Exception):
|
||||
pass
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import re
|
||||
|
||||
|
||||
def check_word(word):
|
||||
ALL_ALPHANUM = re.compile('([0-9a-z])', re.I)
|
||||
NON_ALPHANUM = re.compile('([^0-9a-z])', re.I)
|
||||
@@ -13,7 +14,7 @@ def check_word(word):
|
||||
if len(word) > 20:
|
||||
return None
|
||||
|
||||
#(A) If a string's ratio of alphanumeric characters to total
|
||||
#(A) If a string's ratio of alphanumeric characters to total
|
||||
#characters is less than 50%, the string is garbage
|
||||
if len(ALL_ALPHANUM.findall(word)) < len(word) / 2:
|
||||
return None
|
||||
@@ -21,18 +22,17 @@ def check_word(word):
|
||||
#Remove word if all the letters in the word are non alphanumeric
|
||||
if len(NON_ALPHANUM.findall(word)) == len(word):
|
||||
return None
|
||||
|
||||
|
||||
#Removed words with too many consecutie vowels
|
||||
if TOO_MANY_VOWELS.findall(word):
|
||||
return None
|
||||
return None
|
||||
|
||||
#Removed words with too many consecutie consonants
|
||||
if TOO_MANY_CONSONANTS.findall(word):
|
||||
return None
|
||||
return None
|
||||
|
||||
#Only allow specific single letter words
|
||||
if len(word) == 1 and not SINGLE_LETTER_WORDS.findall(word):
|
||||
return None
|
||||
|
||||
|
||||
return word
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
|
||||
def check_word(word):
|
||||
ALL_ALPHANUM = re.compile('([0-9a-záéíóúüñ])', re.I)
|
||||
NON_ALPHANUM = re.compile('([^0-9a-záéíóúüñ])', re.I)
|
||||
@@ -14,7 +15,7 @@ def check_word(word):
|
||||
if len(word) > 20:
|
||||
return None
|
||||
|
||||
#(A) If a string’s ratio of alphanumeric characters to total
|
||||
#(A) If a string’s ratio of alphanumeric characters to total
|
||||
#characters is less than 50%, the string is garbage
|
||||
if len(ALL_ALPHANUM.findall(word)) < len(word) / 2:
|
||||
return None
|
||||
@@ -22,18 +23,17 @@ def check_word(word):
|
||||
#Remove word if all the letters in the word are non alphanumeric
|
||||
if len(NON_ALPHANUM.findall(word)) == len(word):
|
||||
return None
|
||||
|
||||
|
||||
#Removed words with too many consecutie vowels
|
||||
if TOO_MANY_VOWELS.findall(word):
|
||||
return None
|
||||
return None
|
||||
|
||||
#Removed words with too many consecutie consonants
|
||||
if TOO_MANY_CONSONANTS.findall(word):
|
||||
return None
|
||||
return None
|
||||
|
||||
#Only allow specific single letter words
|
||||
if len(word) == 1 and not SINGLE_LETTER_WORDS.findall(word):
|
||||
return None
|
||||
|
||||
|
||||
return word
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from documents.models import Document
|
||||
|
||||
from literals import DOCUMENTQUEUE_STATE_STOPPED, \
|
||||
from ocr.literals import DOCUMENTQUEUE_STATE_STOPPED, \
|
||||
DOCUMENTQUEUE_STATE_CHOICES, QUEUEDOCUMENT_STATE_PENDING, \
|
||||
QUEUEDOCUMENT_STATE_CHOICES
|
||||
from exceptions import AlreadyQueued
|
||||
from ocr.exceptions import AlreadyQueued
|
||||
|
||||
|
||||
class DocumentQueueManager(models.Manager):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from models import DocumentQueue, QueueDocument
|
||||
from ocr.models import DocumentQueue, QueueDocument
|
||||
|
||||
|
||||
def get_statistics():
|
||||
|
||||
@@ -9,10 +9,10 @@ from celery.task import PeriodicTask
|
||||
from celery.decorators import task
|
||||
|
||||
from ocr.api import do_document_ocr
|
||||
from literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||
from ocr.literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||
QUEUEDOCUMENT_STATE_PROCESSING, DOCUMENTQUEUE_STATE_ACTIVE, \
|
||||
QUEUEDOCUMENT_STATE_ERROR
|
||||
from models import QueueDocument, DocumentQueue
|
||||
from ocr.models import QueueDocument, DocumentQueue
|
||||
from ocr.conf.settings import NODE_CONCURRENT_EXECUTION
|
||||
from ocr.conf.settings import REPLICATION_DELAY
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ from documents.models import Document
|
||||
from ocr import PERMISSION_OCR_DOCUMENT, PERMISSION_OCR_DOCUMENT_DELETE, \
|
||||
PERMISSION_OCR_QUEUE_ENABLE_DISABLE, PERMISSION_OCR_CLEAN_ALL_PAGES
|
||||
|
||||
from models import DocumentQueue, QueueDocument
|
||||
from literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||
from ocr.models import DocumentQueue, QueueDocument
|
||||
from ocr.literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||
QUEUEDOCUMENT_STATE_PROCESSING, DOCUMENTQUEUE_STATE_STOPPED, \
|
||||
DOCUMENTQUEUE_STATE_ACTIVE
|
||||
from exceptions import AlreadyQueued
|
||||
from api import clean_pages
|
||||
from ocr.exceptions import AlreadyQueued
|
||||
from ocr.api import clean_pages
|
||||
|
||||
|
||||
def _display_thumbnail(ocr_document):
|
||||
@@ -65,15 +65,13 @@ def queue_document_list(request, queue_name='default'):
|
||||
)
|
||||
|
||||
|
||||
def queue_document_delete(request, queue_document_id=None, queue_document_id_list=[]):
|
||||
def queue_document_delete(request, queue_document_id=None, queue_document_id_list=None):
|
||||
check_permissions(request.user, 'ocr', [PERMISSION_OCR_DOCUMENT_DELETE])
|
||||
|
||||
if queue_document_id:
|
||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id)]
|
||||
post_redirect = None
|
||||
elif queue_document_id_list:
|
||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id) for queue_document_id in queue_document_id_list.split(',')]
|
||||
post_redirect = None
|
||||
else:
|
||||
messages.error(request, _(u'Must provide at least one queue document.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
@@ -138,15 +136,13 @@ def submit_document_to_queue(request, document, post_submit_redirect=None):
|
||||
return HttpResponseRedirect(post_submit_redirect)
|
||||
|
||||
|
||||
def re_queue_document(request, queue_document_id=None, queue_document_id_list=[]):
|
||||
def re_queue_document(request, queue_document_id=None, queue_document_id_list=None):
|
||||
check_permissions(request.user, 'ocr', [PERMISSION_OCR_DOCUMENT])
|
||||
|
||||
if queue_document_id:
|
||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id)]
|
||||
post_redirect = None
|
||||
elif queue_document_id_list:
|
||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id) for queue_document_id in queue_document_id_list.split(',')]
|
||||
post_redirect = None
|
||||
else:
|
||||
messages.error(request, _(u'Must provide at least one queue document.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
|
||||
Reference in New Issue
Block a user