author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 24 Sep 2009 00:24:21 +0200 | |
changeset 3460 | e4843535db25 |
parent 3457 | 0924d0d08d60 |
child 3503 | 06bced8edddf |
permissions | -rw-r--r-- |
0 | 1 |
"""Set of HTML startup views. A startup view is global, e.g. doesn't |
2 |
apply to a result set. |
|
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
10 |
_ = unicode |
0 | 11 |
|
1132 | 12 |
from logilab.common.textutils import unormalize |
2387
ea1defea9636
[views] fix some crashers (schema still does not render properly, might be yams side)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
0 | 14 |
|
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
15 |
from cubicweb.view import StartupView |
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
16 |
from cubicweb.selectors import match_user_groups, implements |
2436
44b2eea35efa
move all schema related views where they belong (eg not startup), fix schema graph views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2387
diff
changeset
|
17 |
from cubicweb.schema import display_name |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1631
diff
changeset
|
18 |
from cubicweb.web import ajax_replace_url, uicfg, httpcache |
0 | 19 |
|
20 |
class ManageView(StartupView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
21 |
__regid__ = 'manage' |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
22 |
title = _('manage') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
23 |
http_cache_manager = httpcache.EtagHTTPCacheManager |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
24 |
|
0 | 25 |
def display_folders(self): |
26 |
return False |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
27 |
|
0 | 28 |
def call(self, **kwargs): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2436
diff
changeset
|
29 |
"""The default view representing the instance's management""" |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
30 |
self._cw.add_css('cubicweb.manageview.css') |
0 | 31 |
self.w(u'<div>\n') |
32 |
if not self.display_folders(): |
|
33 |
self._main_index() |
|
34 |
else: |
|
35 |
self.w(u'<table><tr>\n') |
|
36 |
self.w(u'<td style="width:40%">') |
|
37 |
self._main_index() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
38 |
self.w(u'</td><td style="width:60%">') |
0 | 39 |
self.folders() |
40 |
self.w(u'</td>') |
|
41 |
self.w(u'</tr></table>\n') |
|
42 |
self.w(u'</div>\n') |
|
43 |
||
44 |
def _main_index(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
45 |
req = self._cw |
0 | 46 |
manager = req.user.matching_groups('managers') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
47 |
if not manager and 'Card' in self._cw.schema: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
48 |
rset = self._cw.execute('Card X WHERE X wikiid "index"') |
0 | 49 |
else: |
50 |
rset = None |
|
51 |
if rset: |
|
52 |
self.wview('inlined', rset, row=0) |
|
53 |
else: |
|
54 |
self.entities() |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2780
diff
changeset
|
55 |
self.w(u'<div class="hr"> </div>') |
0 | 56 |
self.startup_views() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
57 |
if manager and 'Card' in self._cw.schema: |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2780
diff
changeset
|
58 |
self.w(u'<div class="hr"> </div>') |
0 | 59 |
if rset: |
60 |
href = rset.get_entity(0, 0).absolute_url(vid='edition') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
61 |
label = self._cw._('edit the index page') |
0 | 62 |
else: |
63 |
href = req.build_url('view', vid='creation', etype='Card', wikiid='index') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
64 |
label = self._cw._('create an index page') |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
65 |
self.w(u'<br/><a href="%s">%s</a>\n' % (xml_escape(href), label)) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
66 |
|
0 | 67 |
def folders(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
68 |
self.w(u'<h4>%s</h4>\n' % self._cw._('Browse by category')) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
69 |
self._cw.vreg['views'].select('tree', self._cw).render(w=self.w) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
70 |
|
0 | 71 |
def startup_views(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
72 |
self.w(u'<h4>%s</h4>\n' % self._cw._('Startup views')) |
0 | 73 |
self.startupviews_table() |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
74 |
|
0 | 75 |
def startupviews_table(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
76 |
for v in self._cw.vreg['views'].possible_views(self._cw, None): |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
77 |
if v.category != 'startupview' or v.__regid__ in ('index', 'tree', 'manage'): |
0 | 78 |
continue |
79 |
self.w('<p><a href="%s">%s</a></p>' % ( |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
80 |
xml_escape(v.url()), xml_escape(self._cw._(v.title).capitalize()))) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
81 |
|
0 | 82 |
def entities(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
83 |
schema = self._cw.schema |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
84 |
self.w(u'<h4>%s</h4>\n' % self._cw._('The repository holds the following entities')) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
85 |
manager = self._cw.user.matching_groups('managers') |
0 | 86 |
self.w(u'<table class="startup">') |
87 |
if manager: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
88 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self._cw._('application entities')) |
0 | 89 |
self.entity_types_table(eschema for eschema in schema.entities() |
1739 | 90 |
if uicfg.indexview_etype_section.get(eschema) == 'application') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
91 |
if manager: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
92 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self._cw._('system entities')) |
0 | 93 |
self.entity_types_table(eschema for eschema in schema.entities() |
1739 | 94 |
if uicfg.indexview_etype_section.get(eschema) == 'system') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
95 |
if 'CWAttribute' in schema: # check schema support |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
96 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self._cw._('schema entities')) |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
97 |
self.entity_types_table(eschema for eschema in schema.entities() |
1739 | 98 |
if uicfg.indexview_etype_section.get(eschema) == 'schema') |
0 | 99 |
self.w(u'</table>') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
100 |
|
0 | 101 |
def entity_types_table(self, eschemas): |
102 |
newline = 0 |
|
103 |
infos = sorted(self.entity_types(eschemas), |
|
104 |
key=lambda (l,a,e):unormalize(l)) |
|
105 |
q, r = divmod(len(infos), 2) |
|
106 |
if r: |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2780
diff
changeset
|
107 |
infos.append( (None, ' ', ' ') ) |
0 | 108 |
infos = zip(infos[:q+r], infos[q+r:]) |
109 |
for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos: |
|
110 |
self.w(u'<tr>\n') |
|
111 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink, etypelink)) |
|
112 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink2, etypelink2)) |
|
113 |
self.w(u'</tr>\n') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
114 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
115 |
|
0 | 116 |
def entity_types(self, eschemas): |
117 |
"""return a list of formatted links to get a list of entities of |
|
118 |
a each entity's types |
|
119 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
120 |
req = self._cw |
0 | 121 |
for eschema in eschemas: |
122 |
if eschema.is_final() or (not eschema.has_perm(req, 'read') and |
|
123 |
not eschema.has_local_role('read')): |
|
124 |
continue |
|
125 |
etype = eschema.type |
|
126 |
label = display_name(req, etype, 'plural') |
|
127 |
nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0] |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
128 |
url = self._cw.build_url(etype) |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2780
diff
changeset
|
129 |
etypelink = u' <a href="%s">%s</a> (%d)' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
130 |
xml_escape(url), label, nb) |
0 | 131 |
yield (label, etypelink, self.add_entity_link(eschema, req)) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
132 |
|
0 | 133 |
def add_entity_link(self, eschema, req): |
134 |
"""creates a [+] link for adding an entity if user has permission to do so""" |
|
135 |
if not eschema.has_perm(req, 'add'): |
|
136 |
return u'' |
|
137 |
return u'[<a href="%s" title="%s">+</a>]' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
138 |
xml_escape(self.create_url(eschema.type)), |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
139 |
self._cw.__('add a %s' % eschema)) |
0 | 140 |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
141 |
|
0 | 142 |
class IndexView(ManageView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
143 |
__regid__ = 'index' |
2368
b41aef0e63a7
use msgid, update i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
144 |
title = _('view_index') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
145 |
|
0 | 146 |
def display_folders(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
147 |
return 'Folder' in self._cw.schema and self._cw.execute('Any COUNT(X) WHERE X is Folder')[0][0] |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
148 |