Added encapsulate factory function to get around Django bug #15791

This commit is contained in:
Roberto Rosario
2011-08-05 09:30:26 -04:00
parent 7b0e177ba2
commit 1b7183be85
15 changed files with 57 additions and 37 deletions

View File

@@ -357,3 +357,15 @@ def validate_path(path):
return False
return True
#def encapsulate(function):
# def wrapper():
# return function
# return wrapper
def encapsulate(function):
# Workaround Django ticket 15791
# Changeset 16045
# http://stackoverflow.com/questions/6861601/cannot-resolve-callable-context-variable/6955045#6955045
return lambda: function

View File

@@ -2,8 +2,9 @@ from django.utils.translation import ugettext_lazy as _
from django.shortcuts import render_to_response
from django.template import RequestContext
from converter import backend
from common.utils import encapsulate
from converter import backend
from converter.conf.settings import GRAPHICS_BACKEND
def formats_list(request):
@@ -16,11 +17,11 @@ def formats_list(request):
'extra_columns': [
{
'name': _(u'name'),
'attribute': lambda x: x[0]
'attribute': encapsulate(lambda x: x[0])
},
{
'name': _(u'description'),
'attribute': lambda x: x[1]
'attribute': encapsulate(lambda x: x[1])
}
],
'backend': GRAPHICS_BACKEND,

View File

@@ -5,6 +5,7 @@ from django.contrib.comments.models import Comment
from navigation.api import register_links, \
register_model_list_columns
from permissions.api import register_permission, set_namespace_title
from common.utils import encapsulate
from documents.models import Document
@@ -34,7 +35,7 @@ register_model_list_columns(Comment, [
},
{
'name': _(u'user'),
'attribute': lambda x: x.user.get_full_name() if x.user.get_full_name() else x.user
'attribute': encapsulate(lambda x: x.user.get_full_name() if x.user.get_full_name() else x.user)
},
{
'name': _(u'comment'),

View File

@@ -1,6 +1,6 @@
from django.utils.translation import ugettext_lazy as _
from common.utils import validate_path
from common.utils import validate_path, encapsulate
from navigation.api import register_links, register_top_menu, \
register_model_list_columns, register_multi_item_links, \
register_sidebar_template
@@ -168,13 +168,13 @@ def document_exists(document):
register_model_list_columns(Document, [
{'name':_(u'thumbnail'), 'attribute':
lambda x: document_thumbnail(x)
encapsulate(lambda x: document_thumbnail(x))
},
{'name':_(u'tags'), 'attribute':
lambda x: get_tags_inline_widget_simple(x)
encapsulate(lambda x: get_tags_inline_widget_simple(x))
},
{'name':_(u'metadata'), 'attribute':
lambda x: get_metadata_string(x)
encapsulate(lambda x: get_metadata_string(x))
},
])

View File

@@ -13,7 +13,7 @@ from django.utils.http import urlencode
import sendfile
from common.utils import pretty_size, parse_range, urlquote, \
return_diff
return_diff, encapsulate
from common.widgets import two_state_template
from common.literals import PAGE_SIZE_DIMENSIONS, \
PAGE_ORIENTATION_PORTRAIT, PAGE_ORIENTATION_LANDSCAPE
@@ -978,7 +978,7 @@ def document_type_filename_list(request, document_type_id):
'extra_columns': [
{
'name': _(u'enabled'),
'attribute': lambda x: two_state_template(x.enabled),
'attribute': encapsulate(lambda x: two_state_template(x.enabled)),
}
]
}

View File

@@ -11,6 +11,7 @@ from documents.literals import PERMISSION_DOCUMENT_VIEW
from documents.models import Document
from documents.widgets import document_thumbnail, document_link
from permissions.api import check_permissions
from common.utils import encapsulate
from folders.models import Folder, FolderDocument
from folders.forms import FolderForm, AddDocumentForm
@@ -22,7 +23,7 @@ def folder_list(request, queryset=None, extra_context=None):
'multi_select_as_buttons': True,
'extra_columns': [
{'name': _(u'created'), 'attribute': 'datetime_created'},
{'name': _(u'documents'), 'attribute': lambda x: x.folderdocument_set.count()}
{'name': _(u'documents'), 'attribute': encapsulate(lambda x: x.folderdocument_set.count())}
]
}
if extra_context:

View File

@@ -7,6 +7,7 @@ from django.db.models.loading import get_model
from django.http import Http404
from permissions.api import check_permissions
from common.utils import encapsulate
from history.models import History
from history.forms import HistoryDetailForm
@@ -27,11 +28,11 @@ def history_list(request):
},
{
'name': _(u'object'),
'attribute': lambda x: history_entry_object_link(x)
'attribute': encapsulate(lambda x: history_entry_object_link(x))
},
{
'name': _(u'summary'),
'attribute': lambda x: history_entry_summary(x)
'attribute': encapsulate(lambda x: history_entry_summary(x))
}
],
'hide_object': True,
@@ -61,7 +62,7 @@ def history_for_object(request, app_label, module_name, object_id):
},
{
'name': _(u'summary'),
'attribute': lambda x: history_entry_summary(x)
'attribute': encapsulate(lambda x: history_entry_summary(x))
}
],
'hide_object': True,

View File

@@ -9,7 +9,8 @@ from converter import formats_list
from documents import document_type_views
from metadata import setup_metadata_type_list, metadata_type_setup_views
from metadata import setup_metadata_set_list, metadata_set_setup_views
from sources import source_list, source_views
#from sources import source_list, source_views
#from sources import source_views
from main.conf.settings import SIDE_BAR_SEARCH
from main.conf.settings import DISABLE_HOME_VIEW
@@ -51,14 +52,15 @@ register_top_menu('about', link={'text': _(u'about'), 'view': 'about', 'famfam':
register_links(['tools_menu', 'statistics', 'history_list', 'history_view', 'formats_list'], [tools_menu, statistics, history_list, formats_list, sentry], menu_name='secondary_menu')
setup_links = [check_settings, role_list, user_list, group_list, document_types, setup_metadata_type_list, setup_metadata_set_list, source_list, admin_site]
#setup_links = [check_settings, role_list, user_list, group_list, document_types, setup_metadata_type_list, setup_metadata_set_list, source_list, admin_site]
setup_links = [check_settings, role_list, user_list, group_list, document_types, setup_metadata_type_list, setup_metadata_set_list, admin_site]
register_links(['setting_list'], setup_links, menu_name='secondary_menu')
register_links(permission_views, setup_links, menu_name='secondary_menu')
register_links(user_management_views, setup_links, menu_name='secondary_menu')
register_links(document_type_views, setup_links, menu_name='secondary_menu')
register_links(metadata_type_setup_views, setup_links, menu_name='secondary_menu')
register_links(metadata_set_setup_views, setup_links, menu_name='secondary_menu')
register_links(source_views, setup_links, menu_name='secondary_menu')
#register_links(source_views, setup_links, menu_name='secondary_menu')
def get_version():

View File

@@ -12,7 +12,7 @@ from documents.models import Document, RecentDocument, DocumentType
from permissions.api import check_permissions
from document_indexing.api import update_indexes, delete_indexes
from common.utils import generate_choices_w_labels#, two_state_template
from common.utils import generate_choices_w_labels, encapsulate
from common.views import assign_remove
from metadata import PERMISSION_METADATA_DOCUMENT_VIEW, \
@@ -396,7 +396,7 @@ def setup_metadata_set_list(request):
'extra_columns': [
{
'name': _(u'members'),
'attribute': lambda x: x.metadatasetitem_set.count(),
'attribute': encapsulate(lambda x: x.metadatasetitem_set.count()),
},
]
}

View File

@@ -13,6 +13,7 @@ from celery.task.control import inspect
from permissions.api import check_permissions
from documents.models import Document
from documents.widgets import document_link, document_thumbnail
from common.utils import encapsulate
from ocr import PERMISSION_OCR_DOCUMENT, PERMISSION_OCR_DOCUMENT_DELETE, \
PERMISSION_OCR_QUEUE_ENABLE_DISABLE, PERMISSION_OCR_CLEAN_ALL_PAGES, \
@@ -44,11 +45,11 @@ def queue_document_list(request, queue_name='default'):
'navigation_object_name': 'queue',
'list_object_variable_name': 'queue_document',
'extra_columns': [
{'name': 'document', 'attribute': lambda x: document_link(x.document) if hasattr(x, 'document') else _(u'Missing document.')},
{'name': _(u'thumbnail'), 'attribute': lambda x: document_thumbnail(x.document)},
{'name': 'submitted', 'attribute': lambda x: unicode(x.datetime_submitted).split('.')[0], 'keep_together':True},
{'name': 'document', 'attribute': encapsulate(lambda x: document_link(x.document) if hasattr(x, 'document') else _(u'Missing document.'))},
{'name': _(u'thumbnail'), 'attribute': encapsulate(lambda x: document_thumbnail(x.document))},
{'name': 'submitted', 'attribute': encapsulate(lambda x: unicode(x.datetime_submitted).split('.')[0]), 'keep_together':True},
{'name': 'delay', 'attribute': 'delay'},
{'name': 'state', 'attribute': lambda x: x.get_state_display()},
{'name': 'state', 'attribute': encapsulate(lambda x: x.get_state_display())},
{'name': 'node', 'attribute': 'node_name'},
{'name': 'result', 'attribute': 'result'},
],

View File

@@ -11,7 +11,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.models import User, Group
from common.views import assign_remove
from common.utils import generate_choices_w_labels
from common.utils import generate_choices_w_labels, encapsulate
from permissions.models import Role, Permission, PermissionHolder, RoleMember
from permissions.forms import RoleForm, RoleForm_view
@@ -50,11 +50,11 @@ def role_permissions(request, role_id):
'title': _(u'permissions'),
'object_list': Permission.objects.all(),
'extra_columns': [
{'name': _(u'namespace'), 'attribute': lambda x: namespace_titles[x.namespace] if x.namespace in namespace_titles else x.namespace},
{'name': _(u'namespace'), 'attribute': encapsulate(lambda x: namespace_titles[x.namespace] if x.namespace in namespace_titles else x.namespace)},
{'name': _(u'name'), 'attribute': u'label'},
{
'name':_(u'state'),
'attribute': lambda x: role_permission_link(role, x, role_permissions_list),
'attribute': encapsulate(lambda x: role_permission_link(role, x, role_permissions_list)),
}
],
'hide_link': True,

View File

@@ -3,7 +3,7 @@ from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
from common.utils import return_type
from common.utils import return_type, encapsulate
from common.widgets import exists_with_famfam
from smart_settings.api import settings
@@ -28,12 +28,12 @@ def setting_list(request):
'hide_link': True,
'hide_object': True,
'extra_columns': [
{'name': _(u'name'), 'attribute': lambda x: mark_safe(u'<span style="font-weight: bold;">%s</span><br>%s' % (x.get('global_name'), x.get('description')))},
{'name': _(u'default'), 'attribute': lambda x: return_type(x['default'])},
{'name': _(u'value'), 'attribute': lambda x: mark_safe(u'<div class="nowrap">%s&nbsp;%s</div>' % (
{'name': _(u'name'), 'attribute': encapsulate(lambda x: mark_safe(u'<span style="font-weight: bold;">%s</span><br>%s' % (x.get('global_name'), x.get('description'))))},
{'name': _(u'default'), 'attribute': encapsulate(lambda x: return_type(x['default']))},
{'name': _(u'value'), 'attribute': encapsulate(lambda x: mark_safe(u'<div class="nowrap">%s&nbsp;%s</div>' % (
return_type(getattr(x['module'], x['name'])),
exists_with_famfam(getattr(x['module'], x['name'])) if x['exists'] else ''
))
)))
},
]
}

View File

@@ -3,7 +3,7 @@ from django.utils.translation import ugettext_lazy as _
from navigation.api import register_links, register_top_menu, \
register_model_list_columns, register_multi_item_links
from permissions.api import register_permission, set_namespace_title
from common.utils import encapsulate
from documents.models import Document
from taggit.models import Tag
@@ -38,11 +38,11 @@ tag_multiple_delete = {'text': _(u'delete'), 'view': 'tag_multiple_delete', 'fam
register_model_list_columns(Tag, [
{
'name': _(u'color'),
'attribute': lambda x: tag_color_block(x)
'attribute': encapsulate(lambda x: tag_color_block(x))
},
{
'name': _(u'color name'),
'attribute': lambda x: x.tagproperties_set.get().get_color_display(),
'attribute': encapsulate(lambda x: x.tagproperties_set.get().get_color_display()),
}
])

View File

@@ -9,6 +9,7 @@ from permissions.api import check_permissions
from taggit.models import Tag
from documents.models import Document
from documents.views import document_list
from common.utils import encapsulate
from tags.forms import AddTagForm, TagForm
from tags.models import TagProperties
@@ -116,7 +117,7 @@ def tag_list(request):
'extra_columns': [
{
'name': _(u'count'),
'attribute': lambda x: x.taggit_taggeditem_items.count()
'attribute': encapsulate(lambda x: x.taggit_taggeditem_items.count())
}
]
}, context_instance=RequestContext(request))

View File

@@ -8,7 +8,7 @@ from django.core.urlresolvers import reverse
from django.contrib.auth.models import User, Group
from permissions.api import check_permissions
from common.utils import generate_choices_w_labels
from common.utils import generate_choices_w_labels, encapsulate
from common.widgets import two_state_template
from common.views import assign_remove
@@ -41,7 +41,7 @@ def user_list(request):
},
{
'name': _(u'active'),
'attribute': lambda x: two_state_template(x.is_active),
'attribute': encapsulate(lambda x: two_state_template(x.is_active)),
}
],