Fix appadmin code inspection for db hooks

This commit is contained in:
ilvalle
2015-02-09 19:38:23 +01:00
parent 69c2bfba9a
commit e939d084fe
3 changed files with 42 additions and 30 deletions
+14 -10
View File
@@ -672,16 +672,20 @@ def hooks():
functions = [] functions = []
for f in getattr(db[t], op): for f in getattr(db[t], op):
if hasattr(f, '__call__'): if hasattr(f, '__call__'):
if isinstance(f, (functools.partial)): try:
f = f.func if isinstance(f, (functools.partial)):
filename = inspect.getsourcefile(f) f = f.func
details = {'funcname':f.__name__, filename = inspect.getsourcefile(f)
'filename':filename[len(request.folder):] if request.folder in filename else None, details = {'funcname':f.__name__,
'lineno': inspect.getsourcelines(f)[1]} 'filename':filename[len(request.folder):] if request.folder in filename else None,
if details['filename']: # Built in functions as delete_uploaded_files are not editable 'lineno': inspect.getsourcelines(f)[1]}
details['url'] = URL(a='admin',c='default',f='edit', args=[request['application'], details['filename']],vars={'lineno':details['lineno']}) if details['filename']: # Built in functions as delete_uploaded_files are not editable
if details['filename'] or with_build_it: details['url'] = URL(a='admin',c='default',f='edit', args=[request['application'], details['filename']],vars={'lineno':details['lineno']})
functions.append(details) if details['filename'] or with_build_it:
functions.append(details)
# compiled app and windows build don't support code inspection
except:
pass
if len(functions): if len(functions):
method_hooks.append({'name':op, 'functions':functions}) method_hooks.append({'name':op, 'functions':functions})
if len(method_hooks): if len(method_hooks):
+14 -10
View File
@@ -672,16 +672,20 @@ def hooks():
functions = [] functions = []
for f in getattr(db[t], op): for f in getattr(db[t], op):
if hasattr(f, '__call__'): if hasattr(f, '__call__'):
if isinstance(f, (functools.partial)): try:
f = f.func if isinstance(f, (functools.partial)):
filename = inspect.getsourcefile(f) f = f.func
details = {'funcname':f.__name__, filename = inspect.getsourcefile(f)
'filename':filename[len(request.folder):] if request.folder in filename else None, details = {'funcname':f.__name__,
'lineno': inspect.getsourcelines(f)[1]} 'filename':filename[len(request.folder):] if request.folder in filename else None,
if details['filename']: # Built in functions as delete_uploaded_files are not editable 'lineno': inspect.getsourcelines(f)[1]}
details['url'] = URL(a='admin',c='default',f='edit', args=[request['application'], details['filename']],vars={'lineno':details['lineno']}) if details['filename']: # Built in functions as delete_uploaded_files are not editable
if details['filename'] or with_build_it: details['url'] = URL(a='admin',c='default',f='edit', args=[request['application'], details['filename']],vars={'lineno':details['lineno']})
functions.append(details) if details['filename'] or with_build_it:
functions.append(details)
# compiled app and windows build don't support code inspection
except:
pass
if len(functions): if len(functions):
method_hooks.append({'name':op, 'functions':functions}) method_hooks.append({'name':op, 'functions':functions})
if len(method_hooks): if len(method_hooks):
+14 -10
View File
@@ -672,16 +672,20 @@ def hooks():
functions = [] functions = []
for f in getattr(db[t], op): for f in getattr(db[t], op):
if hasattr(f, '__call__'): if hasattr(f, '__call__'):
if isinstance(f, (functools.partial)): try:
f = f.func if isinstance(f, (functools.partial)):
filename = inspect.getsourcefile(f) f = f.func
details = {'funcname':f.__name__, filename = inspect.getsourcefile(f)
'filename':filename[len(request.folder):] if request.folder in filename else None, details = {'funcname':f.__name__,
'lineno': inspect.getsourcelines(f)[1]} 'filename':filename[len(request.folder):] if request.folder in filename else None,
if details['filename']: # Built in functions as delete_uploaded_files are not editable 'lineno': inspect.getsourcelines(f)[1]}
details['url'] = URL(a='admin',c='default',f='edit', args=[request['application'], details['filename']],vars={'lineno':details['lineno']}) if details['filename']: # Built in functions as delete_uploaded_files are not editable
if details['filename'] or with_build_it: details['url'] = URL(a='admin',c='default',f='edit', args=[request['application'], details['filename']],vars={'lineno':details['lineno']})
functions.append(details) if details['filename'] or with_build_it:
functions.append(details)
# compiled app and windows build don't support code inspection
except:
pass
if len(functions): if len(functions):
method_hooks.append({'name':op, 'functions':functions}) method_hooks.append({'name':op, 'functions':functions})
if len(method_hooks): if len(method_hooks):