Moved return_type function to common.utils
This commit is contained in:
@@ -7,6 +7,7 @@ from django.utils.http import urlquote as django_urlquote
|
||||
from django.utils.http import urlencode as django_urlencode
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
def urlquote(link=None, get=None):
|
||||
@@ -113,19 +114,6 @@ def exists_with_famfam(path):
|
||||
# The code here is based loosely on John Cardinal's notes found at:
|
||||
# http://www.johncardinal.com/tmgutil/capitalizenames.htm
|
||||
|
||||
# 2006-03-16
|
||||
# Thanks to David Kern <kernd@reasonspace.com> for fixing some bugs.
|
||||
|
||||
#class Name(str):
|
||||
# """A Class (based on the string type) that properly capitalizes a name."""
|
||||
#
|
||||
# def __new__(cls, value=''):
|
||||
# original = value
|
||||
# proper = Capitalize(value)
|
||||
# obj = str.__new__(cls, proper)
|
||||
# obj.original = original
|
||||
# return obj
|
||||
|
||||
def proper_name(name):
|
||||
"""Does the work of capitalizing a name (can be a full name)."""
|
||||
|
||||
@@ -303,3 +291,15 @@ def proper_name(name):
|
||||
|
||||
mc = re.compile(r'^Mc(\w)(?=\w)', re.I)
|
||||
mac = re.compile(r'^Mac(\w)(?=\w)', re.I)
|
||||
|
||||
def return_type(value):
|
||||
if isinstance(value, types.FunctionType):
|
||||
return value.__doc__ if value.__doc__ else _(u'function found')
|
||||
elif isinstance(value, types.ClassType):
|
||||
return _(u'class found: %s') % unicode(value).split("'")[1].split('.')[-1]
|
||||
elif isinstance(value, types.TypeType):
|
||||
return _(u'class found: %s') % unicode(value).split("'")[1].split('.')[-1]
|
||||
elif isinstance(value, types.DictType) or isinstance(value, types.DictionaryType):
|
||||
return ','.join(list(value))
|
||||
else:
|
||||
return value
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.conf.urls.defaults import patterns, url
|
||||
urlpatterns = patterns('main.views',
|
||||
url(r'^$', 'home', (), 'home'),
|
||||
url(r'^check_settings/$', 'check_settings', (), 'check_settings'),
|
||||
url(r'^tools_menu/$', 'blank_menu', (), 'tools_menu'),
|
||||
url(r'^tools_menu/$', 'tools_menu', (), 'tools_menu'),
|
||||
url(r'^statistics/$', 'statistics', (), 'statistics'),
|
||||
url(r'^diagnostics/$', 'diagnostics_view', (), 'diagnostics'),
|
||||
)
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import types
|
||||
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.utils import exists_with_famfam
|
||||
|
||||
from common.utils import exists_with_famfam, return_type
|
||||
from common.conf import settings as common_settings
|
||||
from documents.conf import settings as documents_settings
|
||||
from documents.statistics import get_statistics as documents_statistics
|
||||
@@ -14,8 +11,8 @@ from ocr.conf import settings as ocr_settings
|
||||
from ocr.statistics import get_statistics as ocr_statistics
|
||||
from filesystem_serving.conf import settings as filesystem_serving_settings
|
||||
from dynamic_search.conf import settings as search_settings
|
||||
from main.conf import settings as main_settings
|
||||
|
||||
from main.conf import settings as main_settings
|
||||
from main.api import diagnostics
|
||||
|
||||
|
||||
@@ -110,7 +107,7 @@ def check_settings(request):
|
||||
'hide_object': True,
|
||||
'extra_columns': [
|
||||
{'name': _(u'name'), 'attribute': 'name'},
|
||||
{'name': _(u'value'), 'attribute': lambda x: _return_type(x['value'])},
|
||||
{'name': _(u'value'), 'attribute': lambda x: return_type(x['value'])},
|
||||
{'name': _(u'description'), 'attribute': lambda x: x.get('description', {}).get(x['name'], '')},
|
||||
{'name': _(u'exists'), 'attribute': lambda x: exists_with_famfam(x['value']) if 'exists' in x else ''},
|
||||
]
|
||||
@@ -120,20 +117,7 @@ def check_settings(request):
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def _return_type(value):
|
||||
if isinstance(value, types.FunctionType):
|
||||
return value.__doc__ if value.__doc__ else _(u'function found')
|
||||
elif isinstance(value, types.ClassType):
|
||||
return _(u'class found: %s') % unicode(value).split("'")[1].split('.')[-1]
|
||||
elif isinstance(value, types.TypeType):
|
||||
return _(u'class found: %s') % unicode(value).split("'")[1].split('.')[-1]
|
||||
elif isinstance(value, types.DictType) or isinstance(value, types.DictionaryType):
|
||||
return ','.join(list(value))
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
def blank_menu(request):
|
||||
def tools_menu(request):
|
||||
return render_to_response('generic_template.html', {
|
||||
'title': _(u'Tools menu'),
|
||||
'paragraphs': [
|
||||
|
||||
Reference in New Issue
Block a user