flake8 cleanups, ununsed imports and variables cleanup, changed register_diagnostics to use reverse_lazy instead of reverse
This commit is contained in:
@@ -19,11 +19,11 @@ class RenderSubtemplateNode(Node):
|
|||||||
|
|
||||||
new_context = Context(context)
|
new_context = Context(context)
|
||||||
new_context.update(Context(template_context, autoescape=context.autoescape))
|
new_context.update(Context(template_context, autoescape=context.autoescape))
|
||||||
|
|
||||||
csrf_token = context.get('csrf_token', None)
|
csrf_token = context.get('csrf_token', None)
|
||||||
if csrf_token is not None:
|
if csrf_token is not None:
|
||||||
new_context['csrf_token'] = csrf_token
|
new_context['csrf_token'] = csrf_token
|
||||||
|
|
||||||
context[self.var_name] = get_template(template_name).render(new_context)
|
context[self.var_name] = get_template(template_name).render(new_context)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@@ -40,12 +40,12 @@ def render_subtemplate(parser, token):
|
|||||||
if not m:
|
if not m:
|
||||||
raise TemplateSyntaxError('%r tag had invalid arguments' % tag_name)
|
raise TemplateSyntaxError('%r tag had invalid arguments' % tag_name)
|
||||||
template_name, template_context, var_name = m.groups()
|
template_name, template_context, var_name = m.groups()
|
||||||
|
|
||||||
if (template_name[0] == template_name[-1] and template_name[0] in ('"', "'")):
|
if (template_name[0] == template_name[-1] and template_name[0] in ('"', "'")):
|
||||||
raise TemplateSyntaxError('%r tag\'s template name argument should not be in quotes' % tag_name)
|
raise TemplateSyntaxError('%r tag\'s template name argument should not be in quotes' % tag_name)
|
||||||
|
|
||||||
if (template_context[0] == template_context[-1] and template_context[0] in ('"', "'")):
|
if (template_context[0] == template_context[-1] and template_context[0] in ('"', "'")):
|
||||||
raise TemplateSyntaxError('%r tag\'s template context argument should not be in quotes' % tag_name)
|
raise TemplateSyntaxError('%r tag\'s template context argument should not be in quotes' % tag_name)
|
||||||
|
|
||||||
return RenderSubtemplateNode(template_name, template_context, var_name)
|
return RenderSubtemplateNode(template_name, template_context, var_name)
|
||||||
#format_string[1:-1]
|
#format_string[1:-1]
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ def pretty_size(size, suffixes=None):
|
|||||||
|
|
||||||
def pretty_size_10(size):
|
def pretty_size_10(size):
|
||||||
return pretty_size(
|
return pretty_size(
|
||||||
size,
|
size,
|
||||||
suffixes=[
|
suffixes=[
|
||||||
(u'B', 1000L), (u'K', 1000000L), (u'M', 1000000000L),
|
(u'B', 1000L), (u'K', 1000000L), (u'M', 1000000000L),
|
||||||
(u'G', 1000000000000L), (u'T', 1000000000000000L)
|
(u'G', 1000000000000L), (u'T', 1000000000000000L)
|
||||||
@@ -302,12 +302,12 @@ def return_type(value):
|
|||||||
return ','.join(list(value))
|
return ','.join(list(value))
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
# http://stackoverflow.com/questions/4248399/page-range-for-printing-algorithm
|
# http://stackoverflow.com/questions/4248399/page-range-for-printing-algorithm
|
||||||
def parse_range(astr):
|
def parse_range(astr):
|
||||||
result=set()
|
result = set()
|
||||||
for part in astr.split(u','):
|
for part in astr.split(u','):
|
||||||
x=part.split(u'-')
|
x = part.split(u'-')
|
||||||
result.update(range(int(x[0]),int(x[-1])+1))
|
result.update(range(int(x[0]), int(x[-1]) + 1))
|
||||||
return sorted(result)
|
return sorted(result)
|
||||||
|
|||||||
@@ -126,9 +126,9 @@ def convert_document(document, *args, **kwargs):
|
|||||||
document_filepath = create_image_cache_filename(document.checksum, *args, **kwargs)
|
document_filepath = create_image_cache_filename(document.checksum, *args, **kwargs)
|
||||||
if os.path.exists(document_filepath):
|
if os.path.exists(document_filepath):
|
||||||
return document_filepath
|
return document_filepath
|
||||||
|
|
||||||
return convert(document_save_to_temp_dir(document, document.checksum), *args, **kwargs)
|
return convert(document_save_to_temp_dir(document, document.checksum), *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def convert(input_filepath, *args, **kwargs):
|
def convert(input_filepath, *args, **kwargs):
|
||||||
size = kwargs.get('size')
|
size = kwargs.get('size')
|
||||||
@@ -139,9 +139,9 @@ def convert(input_filepath, *args, **kwargs):
|
|||||||
page = kwargs.get('page', DEFAULT_PAGE_INDEX_NUMBER)
|
page = kwargs.get('page', DEFAULT_PAGE_INDEX_NUMBER)
|
||||||
cleanup_files = kwargs.get('cleanup_files', True)
|
cleanup_files = kwargs.get('cleanup_files', True)
|
||||||
quality = kwargs.get('quality', QUALITY_DEFAULT)
|
quality = kwargs.get('quality', QUALITY_DEFAULT)
|
||||||
|
|
||||||
unoconv_output = None
|
unoconv_output = None
|
||||||
|
|
||||||
output_filepath = create_image_cache_filename(input_filepath, *args, **kwargs)
|
output_filepath = create_image_cache_filename(input_filepath, *args, **kwargs)
|
||||||
if os.path.exists(output_filepath):
|
if os.path.exists(output_filepath):
|
||||||
return output_filepath
|
return output_filepath
|
||||||
@@ -190,7 +190,7 @@ def get_document_dimensions(document, *args, **kwargs):
|
|||||||
return [int(dimension) for dimension in backend.execute_identify(unicode(document_filepath), options).split()]
|
return [int(dimension) for dimension in backend.execute_identify(unicode(document_filepath), options).split()]
|
||||||
else:
|
else:
|
||||||
return [0, 0]
|
return [0, 0]
|
||||||
|
|
||||||
|
|
||||||
def convert_document_for_ocr(document, page=DEFAULT_PAGE_INDEX_NUMBER, file_format=DEFAULT_OCR_FILE_FORMAT):
|
def convert_document_for_ocr(document, page=DEFAULT_PAGE_INDEX_NUMBER, file_format=DEFAULT_OCR_FILE_FORMAT):
|
||||||
#Extract document file
|
#Extract document file
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ def execute_identify(input_filepath, arguments=None):
|
|||||||
command = []
|
command = []
|
||||||
command.append(unicode(IM_IDENTIFY_PATH))
|
command.append(unicode(IM_IDENTIFY_PATH))
|
||||||
if arguments:
|
if arguments:
|
||||||
command.extend(arguments)
|
command.extend(arguments)
|
||||||
command.append(unicode(input_filepath))
|
command.append(unicode(input_filepath))
|
||||||
|
|
||||||
proc = subprocess.Popen(command, close_fds=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
proc = subprocess.Popen(command, close_fds=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from navigation.api import register_menu
|
from navigation.api import register_menu
|
||||||
|
|
||||||
from permissions import role_list
|
from permissions import role_list
|
||||||
|
|
||||||
from documents import document_find_all_duplicates
|
|
||||||
from filesystem_serving import filesystem_serving_recreate_all_links
|
|
||||||
from ocr import all_document_ocr_cleanup
|
|
||||||
from user_management import user_list
|
from user_management import user_list
|
||||||
|
|
||||||
from main.conf.settings import SIDE_BAR_SEARCH
|
from main.conf.settings import SIDE_BAR_SEARCH
|
||||||
@@ -55,7 +50,7 @@ def get_version():
|
|||||||
Return the formatted version information
|
Return the formatted version information
|
||||||
"""
|
"""
|
||||||
vers = ["%(major)i.%(minor)i" % __version_info__, ]
|
vers = ["%(major)i.%(minor)i" % __version_info__, ]
|
||||||
|
|
||||||
if __version_info__['micro']:
|
if __version_info__['micro']:
|
||||||
vers.append(".%(micro)i" % __version_info__)
|
vers.append(".%(micro)i" % __version_info__)
|
||||||
if __version_info__['releaselevel'] != 'final':
|
if __version_info__['releaselevel'] != 'final':
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils.functional import lazy
|
from django.utils.functional import lazy
|
||||||
|
|
||||||
diagnostics = {}
|
diagnostics = {}
|
||||||
tools = {}
|
tools = {}
|
||||||
@@ -9,7 +9,7 @@ reverse_lazy = lazy(reverse, str)
|
|||||||
def register_diagnostic(namespace, title, link):
|
def register_diagnostic(namespace, title, link):
|
||||||
namespace_dict = diagnostics.get(namespace, {'title': None, 'links': []})
|
namespace_dict = diagnostics.get(namespace, {'title': None, 'links': []})
|
||||||
namespace_dict['title'] = title
|
namespace_dict['title'] = title
|
||||||
link['url'] = link.get('url', reverse(link['view']))
|
link['url'] = link.get('url', reverse_lazy(link['view']))
|
||||||
namespace_dict['links'].append(link)
|
namespace_dict['links'].append(link)
|
||||||
diagnostics[namespace] = namespace_dict
|
diagnostics[namespace] = namespace_dict
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ def tools_menu(request):
|
|||||||
user_tools[namespace] = {
|
user_tools[namespace] = {
|
||||||
'title': values['title']
|
'title': values['title']
|
||||||
}
|
}
|
||||||
user_links = user_tools[namespace].setdefault('links', [])
|
user_tools[namespace].setdefault('links', [])
|
||||||
user_tools[namespace]['links'].append(link)
|
user_tools[namespace]['links'].append(link)
|
||||||
except PermissionDenied:
|
except PermissionDenied:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ from django.template import TemplateSyntaxError, Library, \
|
|||||||
from django.utils.text import unescape_string_literal
|
from django.utils.text import unescape_string_literal
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from django.template import TemplateSyntaxError, Library, Context
|
from django.template import Context
|
||||||
|
|
||||||
from navigation.api import object_navigation, multi_object_navigation, \
|
from navigation.api import object_navigation, multi_object_navigation, \
|
||||||
menu_links as menu_navigation, sidebar_templates
|
menu_links as menu_navigation, sidebar_templates
|
||||||
from navigation.forms import MultiItemForm
|
from navigation.forms import MultiItemForm
|
||||||
@@ -34,14 +34,13 @@ def process_links(links, view_name, url):
|
|||||||
child_view = 'view' in child_link and child_link['view']
|
child_view = 'view' in child_link and child_link['view']
|
||||||
child_url = 'url' in child_link and child_link['url']
|
child_url = 'url' in child_link and child_link['url']
|
||||||
if view_name == child_view or url == child_url:
|
if view_name == child_view or url == child_url:
|
||||||
active = True
|
|
||||||
active_item = item
|
active_item = item
|
||||||
new_link.update({
|
new_link.update({
|
||||||
'first': count == 0,
|
'first': count == 0,
|
||||||
'url': item_view and reverse(item_view) or item_url or u'#',
|
'url': item_view and reverse(item_view) or item_url or u'#',
|
||||||
})
|
})
|
||||||
items.append(new_link)
|
items.append(new_link)
|
||||||
|
|
||||||
return items, active_item
|
return items, active_item
|
||||||
|
|
||||||
|
|
||||||
@@ -151,7 +150,7 @@ def _get_object_navigation_links(context, menu_name=None, links_dict=object_navi
|
|||||||
obj = Variable(object_name).resolve(context)
|
obj = Variable(object_name).resolve(context)
|
||||||
except VariableDoesNotExist:
|
except VariableDoesNotExist:
|
||||||
obj = None
|
obj = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
links = links_dict[menu_name][current_view]['links']
|
links = links_dict[menu_name][current_view]['links']
|
||||||
for link in resolve_links(context, links, current_view, current_path):
|
for link in resolve_links(context, links, current_view, current_path):
|
||||||
@@ -267,8 +266,8 @@ class EvaluateLinkNone(Node):
|
|||||||
def render(self, context):
|
def render(self, context):
|
||||||
condition = Variable(self.condition).resolve(context)
|
condition = Variable(self.condition).resolve(context)
|
||||||
if condition:
|
if condition:
|
||||||
context[self.var_name] = condition(Context(context))
|
context[self.var_name] = condition(Context(context))
|
||||||
return u''
|
return u''
|
||||||
else:
|
else:
|
||||||
context[self.var_name] = True
|
context[self.var_name] = True
|
||||||
return u''
|
return u''
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
from django.db.utils import DatabaseError
|
from django.db.utils import DatabaseError
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
|
|
||||||
from navigation.api import register_links, register_menu, register_multi_item_links
|
from navigation.api import register_links, register_menu, register_multi_item_links
|
||||||
from permissions.api import register_permissions
|
from permissions.api import register_permissions
|
||||||
@@ -11,7 +10,6 @@ from main.api import register_tool
|
|||||||
|
|
||||||
from ocr.conf.settings import AUTOMATIC_OCR
|
from ocr.conf.settings import AUTOMATIC_OCR
|
||||||
from ocr.models import DocumentQueue
|
from ocr.models import DocumentQueue
|
||||||
from ocr.urls import urlpatterns
|
|
||||||
|
|
||||||
#Permissions
|
#Permissions
|
||||||
PERMISSION_OCR_DOCUMENT = 'ocr_document'
|
PERMISSION_OCR_DOCUMENT = 'ocr_document'
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ def ocr_cleanup(text):
|
|||||||
Cleanup the OCR's output passing it thru the selected language's
|
Cleanup the OCR's output passing it thru the selected language's
|
||||||
cleanup filter
|
cleanup filter
|
||||||
"""
|
"""
|
||||||
|
|
||||||
output = []
|
output = []
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ from ocr.conf.settings import NODE_CONCURRENT_EXECUTION
|
|||||||
from ocr.conf.settings import REPLICATION_DELAY
|
from ocr.conf.settings import REPLICATION_DELAY
|
||||||
from ocr.conf.settings import QUEUE_PROCESSING_INTERVAL
|
from ocr.conf.settings import QUEUE_PROCESSING_INTERVAL
|
||||||
|
|
||||||
LOCK_EXPIRE = 60 * 5 # Lock expires in 5 minutes
|
LOCK_EXPIRE = 60 * 5 # Lock expires in 5 minutes
|
||||||
local_cache = CacheClass([], {})
|
local_cache = CacheClass([], {})
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def task_process_queue_document(queue_document_id):
|
def task_process_queue_document(queue_document_id):
|
||||||
queue_document = QueueDocument.objects.get(id=queue_document_id)
|
queue_document = QueueDocument.objects.get(id=queue_document_id)
|
||||||
@@ -40,7 +41,7 @@ def reset_orphans():
|
|||||||
i = inspect().active()
|
i = inspect().active()
|
||||||
active_tasks = []
|
active_tasks = []
|
||||||
orphans = []
|
orphans = []
|
||||||
|
|
||||||
if i:
|
if i:
|
||||||
for host, instances in i.items():
|
for host, instances in i.items():
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ def all_document_ocr_cleanup(request):
|
|||||||
def display_link(obj):
|
def display_link(obj):
|
||||||
output = []
|
output = []
|
||||||
if hasattr(obj, 'get_absolute_url'):
|
if hasattr(obj, 'get_absolute_url'):
|
||||||
output.append(u'<a href="%(url)s">%(obj)s</a>'% {
|
output.append(u'<a href="%(url)s">%(obj)s</a>' % {
|
||||||
'url': obj.get_absolute_url(),
|
'url': obj.get_absolute_url(),
|
||||||
'obj': obj
|
'obj': obj
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def tag_remove(request, tag_id, document_id):
|
|||||||
|
|
||||||
tag = get_object_or_404(Tag, pk=tag_id)
|
tag = get_object_or_404(Tag, pk=tag_id)
|
||||||
document = get_object_or_404(Document, pk=document_id)
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
|
|
||||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', None)))
|
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', None)))
|
||||||
document.tags.remove(tag)
|
document.tags.remove(tag)
|
||||||
messages.success(request, _(u'Tag "%s" removed successfully.') % tag)
|
messages.success(request, _(u'Tag "%s" removed successfully.') % tag)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ def get_tags_inline_widget(document):
|
|||||||
tags_template.append(u'<div class="tc">')
|
tags_template.append(u'<div class="tc">')
|
||||||
tags_template.append(u'<div>%(tag_string)s: %(tag_count)s</div>' % {
|
tags_template.append(u'<div>%(tag_string)s: %(tag_count)s</div>' % {
|
||||||
'tag_string': _(u'Tags'), 'tag_count': tag_count})
|
'tag_string': _(u'Tags'), 'tag_count': tag_count})
|
||||||
|
|
||||||
for tag in document.tags.all():
|
for tag in document.tags.all():
|
||||||
tags_template.append(tag_block_template % (tag.tagproperties_set.get().get_color_code(), tag.name))
|
tags_template.append(tag_block_template % (tag.tagproperties_set.get().get_color_code(), tag.name))
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ def get_tags_inline_widget_simple(document):
|
|||||||
tag_count = document.tags.count()
|
tag_count = document.tags.count()
|
||||||
if tag_count:
|
if tag_count:
|
||||||
tags_template.append(u'<div class="tc">')
|
tags_template.append(u'<div class="tc">')
|
||||||
|
|
||||||
for tag in document.tags.all():
|
for tag in document.tags.all():
|
||||||
tags_template.append(tag_block_template % (tag.tagproperties_set.get().get_color_code(), tag.name))
|
tags_template.append(tag_block_template % (tag.tagproperties_set.get().get_color_code(), tag.name))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user