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.update(Context(template_context, autoescape=context.autoescape))
|
||||
|
||||
|
||||
csrf_token = context.get('csrf_token', None)
|
||||
if csrf_token is not None:
|
||||
new_context['csrf_token'] = csrf_token
|
||||
|
||||
|
||||
context[self.var_name] = get_template(template_name).render(new_context)
|
||||
return ''
|
||||
|
||||
@@ -40,12 +40,12 @@ def render_subtemplate(parser, token):
|
||||
if not m:
|
||||
raise TemplateSyntaxError('%r tag had invalid arguments' % tag_name)
|
||||
template_name, template_context, var_name = m.groups()
|
||||
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
return RenderSubtemplateNode(template_name, template_context, var_name)
|
||||
#format_string[1:-1]
|
||||
|
||||
@@ -94,7 +94,7 @@ def pretty_size(size, suffixes=None):
|
||||
|
||||
def pretty_size_10(size):
|
||||
return pretty_size(
|
||||
size,
|
||||
size,
|
||||
suffixes=[
|
||||
(u'B', 1000L), (u'K', 1000000L), (u'M', 1000000000L),
|
||||
(u'G', 1000000000000L), (u'T', 1000000000000000L)
|
||||
@@ -302,12 +302,12 @@ def return_type(value):
|
||||
return ','.join(list(value))
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
|
||||
# http://stackoverflow.com/questions/4248399/page-range-for-printing-algorithm
|
||||
def parse_range(astr):
|
||||
result=set()
|
||||
result = set()
|
||||
for part in astr.split(u','):
|
||||
x=part.split(u'-')
|
||||
result.update(range(int(x[0]),int(x[-1])+1))
|
||||
x = part.split(u'-')
|
||||
result.update(range(int(x[0]), int(x[-1]) + 1))
|
||||
return sorted(result)
|
||||
|
||||
@@ -126,9 +126,9 @@ def convert_document(document, *args, **kwargs):
|
||||
document_filepath = create_image_cache_filename(document.checksum, *args, **kwargs)
|
||||
if os.path.exists(document_filepath):
|
||||
return document_filepath
|
||||
|
||||
|
||||
return convert(document_save_to_temp_dir(document, document.checksum), *args, **kwargs)
|
||||
|
||||
|
||||
|
||||
def convert(input_filepath, *args, **kwargs):
|
||||
size = kwargs.get('size')
|
||||
@@ -139,9 +139,9 @@ def convert(input_filepath, *args, **kwargs):
|
||||
page = kwargs.get('page', DEFAULT_PAGE_INDEX_NUMBER)
|
||||
cleanup_files = kwargs.get('cleanup_files', True)
|
||||
quality = kwargs.get('quality', QUALITY_DEFAULT)
|
||||
|
||||
|
||||
unoconv_output = None
|
||||
|
||||
|
||||
output_filepath = create_image_cache_filename(input_filepath, *args, **kwargs)
|
||||
if os.path.exists(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()]
|
||||
else:
|
||||
return [0, 0]
|
||||
|
||||
|
||||
|
||||
def convert_document_for_ocr(document, page=DEFAULT_PAGE_INDEX_NUMBER, file_format=DEFAULT_OCR_FILE_FORMAT):
|
||||
#Extract document file
|
||||
|
||||
@@ -13,7 +13,7 @@ def execute_identify(input_filepath, arguments=None):
|
||||
command = []
|
||||
command.append(unicode(IM_IDENTIFY_PATH))
|
||||
if arguments:
|
||||
command.extend(arguments)
|
||||
command.extend(arguments)
|
||||
command.append(unicode(input_filepath))
|
||||
|
||||
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 navigation.api import register_menu
|
||||
|
||||
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 main.conf.settings import SIDE_BAR_SEARCH
|
||||
@@ -55,7 +50,7 @@ def get_version():
|
||||
Return the formatted version information
|
||||
"""
|
||||
vers = ["%(major)i.%(minor)i" % __version_info__, ]
|
||||
|
||||
|
||||
if __version_info__['micro']:
|
||||
vers.append(".%(micro)i" % __version_info__)
|
||||
if __version_info__['releaselevel'] != 'final':
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.functional import lazy
|
||||
from django.utils.functional import lazy
|
||||
|
||||
diagnostics = {}
|
||||
tools = {}
|
||||
@@ -9,7 +9,7 @@ reverse_lazy = lazy(reverse, str)
|
||||
def register_diagnostic(namespace, title, link):
|
||||
namespace_dict = diagnostics.get(namespace, {'title': None, 'links': []})
|
||||
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)
|
||||
diagnostics[namespace] = namespace_dict
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ def tools_menu(request):
|
||||
user_tools[namespace] = {
|
||||
'title': values['title']
|
||||
}
|
||||
user_links = user_tools[namespace].setdefault('links', [])
|
||||
user_tools[namespace].setdefault('links', [])
|
||||
user_tools[namespace]['links'].append(link)
|
||||
except PermissionDenied:
|
||||
pass
|
||||
|
||||
@@ -7,8 +7,8 @@ from django.template import TemplateSyntaxError, Library, \
|
||||
from django.utils.text import unescape_string_literal
|
||||
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, \
|
||||
menu_links as menu_navigation, sidebar_templates
|
||||
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_url = 'url' in child_link and child_link['url']
|
||||
if view_name == child_view or url == child_url:
|
||||
active = True
|
||||
active_item = item
|
||||
new_link.update({
|
||||
'first': count == 0,
|
||||
'url': item_view and reverse(item_view) or item_url or u'#',
|
||||
})
|
||||
items.append(new_link)
|
||||
|
||||
|
||||
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)
|
||||
except VariableDoesNotExist:
|
||||
obj = None
|
||||
|
||||
|
||||
try:
|
||||
links = links_dict[menu_name][current_view]['links']
|
||||
for link in resolve_links(context, links, current_view, current_path):
|
||||
@@ -267,8 +266,8 @@ class EvaluateLinkNone(Node):
|
||||
def render(self, context):
|
||||
condition = Variable(self.condition).resolve(context)
|
||||
if condition:
|
||||
context[self.var_name] = condition(Context(context))
|
||||
return u''
|
||||
context[self.var_name] = condition(Context(context))
|
||||
return u''
|
||||
else:
|
||||
context[self.var_name] = True
|
||||
return u''
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext
|
||||
from django.db.utils import DatabaseError
|
||||
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 permissions.api import register_permissions
|
||||
@@ -11,7 +10,6 @@ from main.api import register_tool
|
||||
|
||||
from ocr.conf.settings import AUTOMATIC_OCR
|
||||
from ocr.models import DocumentQueue
|
||||
from ocr.urls import urlpatterns
|
||||
|
||||
#Permissions
|
||||
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 filter
|
||||
"""
|
||||
|
||||
|
||||
output = []
|
||||
for line in text.splitlines():
|
||||
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 QUEUE_PROCESSING_INTERVAL
|
||||
|
||||
LOCK_EXPIRE = 60 * 5 # Lock expires in 5 minutes
|
||||
LOCK_EXPIRE = 60 * 5 # Lock expires in 5 minutes
|
||||
local_cache = CacheClass([], {})
|
||||
|
||||
|
||||
@task
|
||||
def task_process_queue_document(queue_document_id):
|
||||
queue_document = QueueDocument.objects.get(id=queue_document_id)
|
||||
@@ -40,7 +41,7 @@ def reset_orphans():
|
||||
i = inspect().active()
|
||||
active_tasks = []
|
||||
orphans = []
|
||||
|
||||
|
||||
if i:
|
||||
for host, instances in i.items():
|
||||
for instance in instances:
|
||||
|
||||
@@ -274,7 +274,7 @@ def all_document_ocr_cleanup(request):
|
||||
def display_link(obj):
|
||||
output = []
|
||||
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(),
|
||||
'obj': obj
|
||||
})
|
||||
|
||||
@@ -21,7 +21,7 @@ def tag_remove(request, tag_id, document_id):
|
||||
|
||||
tag = get_object_or_404(Tag, pk=tag_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)))
|
||||
document.tags.remove(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>%(tag_string)s: %(tag_count)s</div>' % {
|
||||
'tag_string': _(u'Tags'), 'tag_count': tag_count})
|
||||
|
||||
|
||||
for tag in document.tags.all():
|
||||
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()
|
||||
if tag_count:
|
||||
tags_template.append(u'<div class="tc">')
|
||||
|
||||
|
||||
for tag in document.tags.all():
|
||||
tags_template.append(tag_block_template % (tag.tagproperties_set.get().get_color_code(), tag.name))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user