appadmin.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. {{extend 'layout.html'}}
  2. <script><!--
  3. jQuery(document).ready(function(){
  4. jQuery("table.sortable tbody tr").mouseover( function() {
  5. jQuery(this).addClass("highlight"); }).mouseout( function() {
  6. jQuery(this).removeClass("highlight"); });
  7. jQuery('table.sortable tbody tr:odd').addClass('odd');
  8. jQuery('table.sortable tbody tr:even').addClass('even');
  9. });
  10. //--></script>
  11. {{if request.function=='index':}}
  12. <h2>{{=T("Available Databases and Tables")}}</h2>
  13. {{if not databases:}}{{=T("No databases in this application")}}{{pass}}
  14. <ul class="nav nav-tabs" id="myTab">
  15. <li class="active" ><a href="#alltables" data-toggle="tab">Tables</a></li>
  16. <li><a href="#hooks" data-toggle="tab">Hooks</a></li>
  17. </ul>
  18. <div class="tab-content">
  19. <div class="tab-pane active" id="alltables">
  20. <table class="table">
  21. {{for db in sorted(databases):}}
  22. {{for table in databases[db].tables:}}
  23. {{qry='%s.%s.id>0'%(db,table)}}
  24. {{tbl=databases[db][table]}}
  25. {{if hasattr(tbl,'_primarykey'):}}
  26. {{if tbl._primarykey:}}
  27. {{firstkey=tbl[tbl._primarykey[0]]}}
  28. {{if firstkey.type in ['string','text']:}}
  29. {{qry='%s.%s.%s!=""'%(db,table,firstkey.name)}}
  30. {{else:}}
  31. {{qry='%s.%s.%s>0'%(db,table,firstkey.name)}}
  32. {{pass}}
  33. {{else:}}
  34. {{qry=''}}
  35. {{pass}}
  36. {{pass}}
  37. <tr>
  38. <th style="font-size: 1.75em;">
  39. {{=A("%s.%s" % (db,table),_href=URL('select',args=[db],vars=dict(query=qry)))}}
  40. </th>
  41. <td>
  42. {{=A(str(T('New Record')),_href=URL('insert',args=[db,table]),_class="btn btn-default")}}
  43. </td>
  44. </tr>
  45. {{pass}}
  46. {{pass}}
  47. </table>
  48. </div>
  49. <div class="tab-pane" id="hooks">
  50. {{=LOAD('appadmin', 'hooks', ajax=True)}}
  51. </div>
  52. </div>
  53. {{elif request.function=='select':}}
  54. <h2>{{=XML(str(T("Database %s select"))%A(request.args[0],_href=URL('index'))) }}
  55. </h2>
  56. {{if tb:}}
  57. <h3>{{=T('Traceback')}}</h3>
  58. <pre>
  59. {{=tb}}
  60. </pre>
  61. {{pass}}
  62. {{if table:}}
  63. {{=A(str(T('New Record')),_href=URL('insert',args=[request.args[0],table]),_class="btn btn-default")}}<br/><br/>
  64. <h3>{{=T("Rows in Table")}}</h3><br/>
  65. {{else:}}
  66. <h3>{{=T("Rows selected")}}</h3><br/>
  67. {{pass}}
  68. {{=form}}
  69. <p>{{=T('The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.')}}<br/>
  70. {{=T('Use (...)&(...) for AND, (...)|(...) for OR, and ~(...) for NOT to build more complex queries.')}}<br/>
  71. {{=T('"update" is an optional expression like "field1=\'newvalue\'". You cannot update or delete the results of a JOIN')}}</p>
  72. <br/><br/>
  73. <h4>{{=T("%s selected", nrows)}}</h4>
  74. {{if start>0:}}{{=A(T('previous %s rows') % step,_href=URL('select',args=request.args[0],vars=dict(start=start-step)),_class="btn btn-default")}}{{pass}}
  75. {{if stop<nrows:}}{{=A(T('next %s rows') % step,_href=URL('select',args=request.args[0],vars=dict(start=start+step)),_class="btn btn-default")}}{{pass}}
  76. {{if rows:}}
  77. <div style="overflow:auto; width:80%;">
  78. {{linkto = lambda f, t, r: URL('update', args=[request.args[0], r, f]) if f else "#"}}
  79. {{upload=URL('download',args=request.args[0])}}
  80. {{=SQLTABLE(rows,linkto,upload,orderby=True,_class='sortable')}}
  81. </div>
  82. {{pass}}
  83. <br/><br/><h3>{{=T("Import/Export")}}</h3><br/>
  84. <a href="{{=URL('csv',args=request.args[0],vars=dict(query=query))}}" class="btn btn-default">{{=T("export as csv file")}}</a>
  85. {{=formcsv or ''}}
  86. {{elif request.function=='insert':}}
  87. <h2>{{=T("Database")}} {{=A(request.args[0],_href=URL('index'))}}
  88. {{if hasattr(table,'_primarykey'):}}
  89. {{fieldname=table._primarykey[0]}}
  90. {{dbname=request.args[0]}}
  91. {{tablename=request.args[1]}}
  92. {{cond = table[fieldname].type in ['string','text'] and '!=""' or '>0'}}
  93. {{=T("Table")}} {{=A(tablename,_href=URL('select',args=dbname,vars=dict(query='%s.%s.%s%s'%(dbname,tablename,fieldname,cond))))}}
  94. {{else:}}
  95. {{=T("Table")}} {{=A(request.args[1],_href=URL('select',args=request.args[0],vars=dict(query='%s.%s.id>0'%tuple(request.args[:2]))))}}
  96. {{pass}}
  97. </h2>
  98. <h3>{{=T("New Record")}}</h3><br/>
  99. {{=form}}
  100. {{elif request.function=='update':}}
  101. <h2>{{=T("Database")}} {{=A(request.args[0],_href=URL('index'))}}
  102. {{if hasattr(table,'_primarykey'):}}
  103. {{fieldname=request.vars.keys()[0]}}
  104. {{dbname=request.args[0]}}
  105. {{tablename=request.args[1]}}
  106. {{cond = table[fieldname].type in ['string','text'] and '!=""' or '>0'}}
  107. {{=T("Table")}} {{=A(tablename,_href=URL('select',args=dbname,vars=dict(query='%s.%s.%s%s'%(dbname,tablename,fieldname,cond))))}}
  108. {{=T("Record")}} {{=A('%s=%s'%request.vars.items()[0],_href=URL('update',args=request.args[:2],vars=request.vars))}}
  109. {{else:}}
  110. {{=T("Table")}} {{=A(request.args[1],_href=URL('select',args=request.args[0],vars=dict(query='%s.%s.id>0'%tuple(request.args[:2]))))}}
  111. {{=T("Record id")}} {{=A(request.args[2],_href=URL('update',args=request.args[:3]))}}
  112. {{pass}}
  113. </h2>
  114. <h3>{{=T("Edit current record")}}</h3><br/><br/>{{=form}}
  115. {{elif request.function=='state':}}
  116. <h2>{{=T("Internal State")}}</h2>
  117. <h3>{{=T("Current request")}}</h3>
  118. {{=BEAUTIFY(request)}}
  119. <br/><h3>{{=T("Current response")}}</h3>
  120. {{=BEAUTIFY(response)}}
  121. <br/><h3>{{=T("Current session")}}</h3>
  122. {{=BEAUTIFY(session)}}
  123. {{elif request.function == 'ccache':}}
  124. <h2>{{T("Cache")}}</h2>
  125. <div class="list">
  126. <div class="list-header">
  127. <h3>{{T("Statistics")}}</h3>
  128. </div>
  129. <div class="content">
  130. <h4>{{=T("Overview")}}</h4>
  131. <p>{{=T.M("Number of entries: **%s**", total['entries'])}}</p>
  132. {{if total['entries'] > 0:}}
  133. <p>{{=T.M("Hit Ratio: **%(ratio)s%%** (**%(hits)s** %%{hit(hits)} and **%(misses)s** %%{miss(misses)})",
  134. dict( ratio=total['ratio'], hits=total['hits'], misses=total['misses']))}}
  135. </p>
  136. <p>
  137. {{=T("Size of cache:")}}
  138. {{if object_stats:}}
  139. {{=T.M("**%(items)s** %%{item(items)}, **%(bytes)s** %%{byte(bytes)}", dict(items=total['objects'], bytes=total['bytes']))}}
  140. {{if total['bytes'] > 524287:}}
  141. {{=T.M("(**%.0d MB**)", total['bytes'] / 1048576)}}
  142. {{pass}}
  143. {{else:}}
  144. {{=T.M("**not available** (requires the Python [[guppy http://pypi.python.org/pypi/guppy/ popup]] library)")}}
  145. {{pass}}
  146. </p>
  147. <p>
  148. {{=T.M("Cache contains items up to **%(hours)02d** %%{hour(hours)} **%(min)02d** %%{minute(min)} **%(sec)02d** %%{second(sec)} old.",
  149. dict(hours=total['oldest'][0], min=total['oldest'][1], sec=total['oldest'][2]))}}
  150. </p>
  151. {{=BUTTON(T('Cache Keys'), _onclick='jQuery("#all_keys").toggle().toggleClass( "w2p_hidden" );')}}
  152. <div class="w2p_hidden" id="all_keys">
  153. {{=total['keys']}}
  154. </div>
  155. <br />
  156. {{pass}}
  157. <h4>{{=T("RAM")}}</h4>
  158. <p>{{=T.M("Number of entries: **%s**", ram['entries'])}}</p>
  159. {{if ram['entries'] > 0:}}
  160. <p>{{=T.M("Hit Ratio: **%(ratio)s%%** (**%(hits)s** %%{hit(hits)} and **%(misses)s** %%{miss(misses)})",
  161. dict( ratio=ram['ratio'], hits=ram['hits'], misses=ram['misses']))}}
  162. </p>
  163. <p>
  164. {{=T("Size of cache:")}}
  165. {{if object_stats:}}
  166. {{=T.M("**%(items)s** items, **%(bytes)s** %%{byte(bytes)}", dict(items=ram['objects'], bytes=ram['bytes']))}}
  167. {{if ram['bytes'] > 524287:}}
  168. {{=T.M("(**%.0d MB**)", ram['bytes'] / 10485576)}}
  169. {{pass}}
  170. {{else:}}
  171. {{=T.M("``**not available**``:red (requires the Python [[guppy http://pypi.python.org/pypi/guppy/ popup]] library)")}}
  172. {{pass}}
  173. </p>
  174. <p>
  175. {{=T.M("RAM contains items up to **%(hours)02d** %%{hour(hours)} **%(min)02d** %%{minute(min)} **%(sec)02d** %%{second(sec)} old.",
  176. dict(hours=ram['oldest'][0], min=ram['oldest'][1], sec=ram['oldest'][2]))}}
  177. </p>
  178. {{=BUTTON(T('RAM Cache Keys'), _onclick='jQuery("#ram_keys").toggle().toggleClass( "w2p_hidden" );')}}
  179. <div class="w2p_hidden" id="ram_keys">
  180. {{=ram['keys']}}
  181. </div>
  182. <br />
  183. {{pass}}
  184. <h4>{{=T("DISK")}}</h4>
  185. <p>{{=T.M("Number of entries: **%s**", disk['entries'])}}</p>
  186. {{if disk['entries'] > 0:}}
  187. <p>
  188. {{=T.M("Hit Ratio: **%(ratio)s%%** (**%(hits)s** %%{hit(hits)} and **%(misses)s** %%{miss(misses)})",
  189. dict(ratio=disk['ratio'], hits=disk['hits'], misses=disk['misses']))}}
  190. </p>
  191. <p>
  192. {{=T("Size of cache:")}}
  193. {{if object_stats:}}
  194. {{=T.M("**%(items)s** %%{item(items)}, **%(bytes)s** %%{byte(bytes)}", dict( items=disk['objects'], bytes=disk['bytes']))}}
  195. {{if disk['bytes'] > 524287:}}
  196. {{=T.M("(**%.0d MB**)", disk['bytes'] / 1048576)}}
  197. {{pass}}
  198. {{else:}}
  199. {{=T.M("``**not available**``:red (requires the Python [[guppy http://pypi.python.org/pypi/guppy/ popup]] library)")}}
  200. {{pass}}
  201. </p>
  202. <p>
  203. {{=T.M("DISK contains items up to **%(hours)02d** %%{hour(hours)} **%(min)02d** %%{minute(min)} **%(sec)02d** %%{second(sec)} old.",
  204. dict(hours=disk['oldest'][0], min=disk['oldest'][1], sec=disk['oldest'][2]))}}
  205. </p>
  206. {{=BUTTON(T('Disk Cache Keys'), _onclick='jQuery("#disk_keys").toggle().toggleClass( "w2p_hidden" );')}}
  207. <div class="w2p_hidden" id="disk_keys">
  208. {{=disk['keys']}}
  209. </div>
  210. <br />
  211. {{pass}}
  212. </div>
  213. <div class="list-header">
  214. <h3>{{=T("Manage Cache")}}</h3>
  215. </div>
  216. <div class="content">
  217. <p>
  218. {{=form}}
  219. </p>
  220. </div>
  221. </div>
  222. <div class="clear"></div>
  223. {{pass}}
  224. {{if request.function=='graph_model':}}
  225. <h2>{{=T("Graph Model")}}</h2>
  226. {{if not pgv:}}
  227. {{=T('pygraphviz library not found')}}
  228. {{elif not databases:}}
  229. {{=T("No databases in this application")}}
  230. {{else:}}
  231. <div class="btn-group">
  232. <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
  233. <i class="icon-download"></i> {{=T('Save model as...')}}
  234. <span class="caret"></span>
  235. </a>
  236. <ul class="dropdown-menu">
  237. <li><a href="{{=URL('appadmin', 'bg_graph_model', args=['png'])}}">png</a></li>
  238. <li><a href="{{=URL('appadmin', 'bg_graph_model', args=['svg'])}}">svg</a></li>
  239. <li><a href="{{=URL('appadmin', 'bg_graph_model', args=['pdf'])}}">pdf</a></li>
  240. <li><a href="{{=URL('appadmin', 'bg_graph_model', args=['ps'])}}">ps</a></li>
  241. <li><a href="{{=URL('appadmin', 'bg_graph_model', args=['dot'])}}">dot</a></li>
  242. </ul>
  243. </div>
  244. <br />
  245. {{=IMG(_src=URL('appadmin', 'bg_graph_model'))}}
  246. {{pass}}
  247. {{pass}}
  248. {{if request.function == 'manage':}}
  249. <h2>{{=heading}}</h2>
  250. <ul class="nav nav-tabs">
  251. {{for k, tablename in enumerate(tablenames):}}
  252. <li{{=XML(' class="active"') if k == 0 else ''}}>
  253. <a href="#table-{{=tablename}}" data-toggle="tab">{{=labels[k]}}</a>
  254. </li>
  255. {{pass}}
  256. </ul>
  257. <div class="tab-content">
  258. {{for k, tablename in enumerate(tablenames):}}
  259. <div class="tab-pane{{=XML(' active') if k == 0 else ''}}" id="table-{{=tablename}}">
  260. {{=LOAD(f='manage.load', args=[request.args(0), k], ajax=True)}}
  261. </div>
  262. {{pass}}
  263. </div>
  264. {{pass}}