cleaned up examples/controller/global.py

This commit is contained in:
mdipierro
2013-03-09 00:17:56 -06:00
parent 1f8bdd6061
commit 5a560fee8a
3 changed files with 76 additions and 93 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.4.2-stable+timestamp.2013.03.08.19.22.01
Version 2.4.2-stable+timestamp.2013.03.09.00.16.49
+33 -57
View File
@@ -4,72 +4,48 @@ response.menu = [['home', False, '/%s/default/index'
% request.application], ['docs', True,
'/%s/global/vars' % request.application]]
def get(args):
try:
obj = globals(),get(args[0])
for k in range(1,len(args)):
obj = getattr(obj,args[k])
return obj
except:
return None
def vars():
"""the running controller function!"""
title = '.'.join(request.args)
attributes = {}
if not request.args:
(
doc,
keys,
t,
c,
d,
value,
) = (
'Global variables',
globals(),
None,
None,
(),
None,
)
(title, args) = ('globals()', '')
(doc,keys,t,c,d,value)=('Global variables',globals(),None,None,[],None)
elif len(request.args) < 3:
args = '.'.join(request.args)
try:
doc = eval(args + '.__doc__')
except:
doc = 'no documentation'
try:
keys = eval('dir(%s)' % args)
except:
obj = get(request.args)
if obj:
doc = getattr(obj,'__doc__','no documentation')
keys = dir(obj)
t = type(obj)
c = getattr(obj,'__class__',None)
d = getattr(obj,'__bases__',None)
for key in keys:
a = getattr(obj,key,None)
if a and not isinstance(a,DAL):
doc1 = getattr(a, '__doc__', '')
t1 = type(a)
c1 = getattr(a,'__class__',None)
d1 = getattr(a,'__bases__',None)
key = '.'.join(request.args)+'.'+key
attributes[key] = (doc1, t1, c1, d1)
else:
doc = 'Unkown'
keys = []
t = eval('type(%s)' % args)
try:
c = eval('%s.__class__' % args)
except:
c = None
try:
d = eval('%s.__bases__' % args)
except:
d = None
title = args
args += '.'
t = c = d = None
else:
raise HTTP(400)
attributes = {}
for key in keys:
a = args + key
if eval('isinstance(%s,SQLDB)' % a) or a == 'vars':
continue
try:
doc1 = eval(a + '.__doc__')
except:
doc1 = 'no documentation'
t1 = eval('type(%s)' % a)
try:
c1 = eval('%s.__class__' % a)
except:
c1 = None
try:
d1 = eval('%s.__bases__' % a)
except:
d1 = ()
attributes[a] = (doc1, t1, c1, d1)
return dict(
title=title,
args=args,
args=request.args,
t=t,
c=c,
d=d,
+42 -35
View File
@@ -2,46 +2,53 @@
{{import cgi}}
<div class="contentleft">
<h1>{{=T('Docs for')}} {{=title}}</h1>
<div align="right">
<h1>{{=T('Docs for')}} {{=title}}</h1>
<div align="right">
[ <a href="http://docs.python.org/tut/">Python Tutorial</a> ]
[ <a href="http://docs.python.org/lib/">Python Libraries</a> ]
[ <a href="/{{=request.application}}/static/epydoc/index.html">web2py epydoc</a> ]
</div>
<h2>{{=T('Description')}}</h2>
<br/>
{{if t:}}
{{=t}}{{if d:}} extends {{=d}}{{pass}}
{{pass}}
<br/>
{{pass}}
{{if doc:}}<br/><br/>{{=CODE(str(doc),language=None,counter=None,_class='boxCode')}}{{pass}}
<br/><br/>
<div class="boxInfo">
</div>
<h2>{{=T('Description')}}</h2>
<br/>
{{if t:}}
{{=t}}{{if d:}} extends {{=d}}{{pass}}
{{pass}}
<br/>
{{pass}}
{{if doc:}}<br/><br/>{{=CODE(str(doc),language=None,counter=None,_class='boxCode')}}{{pass}}
<br/><br/>
<div class="boxInfo">
{{if attributes:}}
<h2>{{=T('Attributes')}}</h2>
{{keys=attributes.keys(); keys.sort()}}
<table>
<tr><td colspan=2><hr/></td></tr>
{{for a in keys:}}
{{doc1,t1,c1,d1=attributes[a]}}
<tr>
<td><b>{{#=a}}</b>{{=A(a,_href=URL(r=request,args=a.split('.')))}}</td>
<td>
{{if t1:}}
{{=t1}}{{if d1:}} extends {{=d1}}{{pass}}
{{if c1:}} belongs to class {{=c1}}{{pass}}
<br/>
{{pass}}
{{if doc1:}}{{=XML(cgi.escape(str(doc1)).replace(chr(13),'<br/>'))}}{{pass}}
<tr><td colspan=2><hr/></td></tr>
{{for key in sorted(attributes):}}
{{doc1,t1,c1,d1=attributes[key]}}
<tr>
<td>
{{if key.count('.')<2:}}
{{=A(key,_href=URL(args=key.split('.')))}}
{{else:}}
{{=key}}
{{pass}}
</td>
<td>
{{if t1:}}
{{=t1}}{{if d1:}} extends {{=d1}}{{pass}}
{{if c1:}} belongs to class {{=c1}}{{pass}}
<br/>
{{pass}}
{{if doc1:}}{{=XML(cgi.escape(str(doc1)).replace(chr(13),'<br/>'))}}{{pass}}
</td>
</tr>
<tr><td colspan=2><hr/></td></tr>
{{pass}}
</tr>
<tr><td colspan=2><hr/></td></tr>
{{pass}}
</table>
</div>
</div>
{{pass}}
</div>