author | sylvain.thenault@logilab.fr |
Wed, 15 Apr 2009 17:30:03 +0200 | |
branch | tls-sprint |
changeset 1373 | 5e6abf61636d |
parent 981 | d86d1ee3b60e |
child 1802 | d628defebc17 |
permissions | -rw-r--r-- |
0 | 1 |
"""management and error screens |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 |
""" |
|
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from time import strftime, localtime |
|
11 |
||
12 |
from logilab.mtconverter import html_escape |
|
13 |
||
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
14 |
from cubicweb.selectors import none_rset, match_user_groups |
981
d86d1ee3b60e
fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents:
742
diff
changeset
|
15 |
from cubicweb.view import StartupView |
0 | 16 |
|
17 |
def dict_to_html(w, dict): |
|
18 |
# XHTML doesn't allow emtpy <ul> nodes |
|
19 |
if dict: |
|
20 |
w(u'<ul>') |
|
21 |
for key in sorted(dict): |
|
22 |
w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % ( |
|
23 |
html_escape(str(key)), html_escape(repr(dict[key])))) |
|
24 |
w(u'</ul>') |
|
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
25 |
|
0 | 26 |
|
27 |
class DebugView(StartupView): |
|
28 |
id = 'debug' |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
635
diff
changeset
|
29 |
__select__ = none_rset() & match_user_groups('managers') |
0 | 30 |
title = _('server debug information') |
31 |
||
32 |
def call(self, **kwargs): |
|
33 |
"""display server information""" |
|
34 |
w = self.w |
|
35 |
w(u'<h1>server sessions</h1>') |
|
36 |
sessions = self.req.cnx._repo._sessions.items() |
|
37 |
if sessions: |
|
38 |
w(u'<ul>') |
|
39 |
for sid, session in sessions: |
|
40 |
w(u'<li>%s (last usage: %s)<br/>' % (html_escape(str(session)), |
|
41 |
strftime('%Y-%m-%d %H:%M:%S', |
|
42 |
localtime(session.timestamp)))) |
|
43 |
dict_to_html(w, session.data) |
|
44 |
w(u'</li>') |
|
45 |
w(u'</ul>') |
|
46 |
else: |
|
47 |
w(u'<p>no server sessions found</p>') |
|
48 |
from cubicweb.web.application import SESSION_MANAGER |
|
49 |
w(u'<h1>web sessions</h1>') |
|
50 |
sessions = SESSION_MANAGER.current_sessions() |
|
51 |
if sessions: |
|
52 |
w(u'<ul>') |
|
53 |
for session in sessions: |
|
54 |
w(u'<li>%s (last usage: %s)<br/>' % (session.sessionid, |
|
55 |
strftime('%Y-%m-%d %H:%M:%S', |
|
56 |
localtime(session.last_usage_time)))) |
|
57 |
dict_to_html(w, session.data) |
|
58 |
w(u'</li>') |
|
59 |
w(u'</ul>') |
|
60 |
else: |
|
61 |
w(u'<p>no web sessions found</p>') |