author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 07 Aug 2009 12:51:56 +0200 | |
changeset 2729 | d3dbd135f319 |
parent 2655 | 48cd71bdb5cd |
child 2813 | 0cf6c8005bf6 |
child 2920 | 64322aa83a1d |
child 3064 | 3fbcdf220ce9 |
permissions | -rw-r--r-- |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
"""The default primary view |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
3 |
:organization: Logilab |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1885
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
5 |
: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:
1885
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
7 |
""" |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
1739 | 9 |
_ = unicode |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
10 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
11 |
from warnings import warn |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
12 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2237
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
14 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
15 |
from cubicweb import Unauthorized |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
16 |
from cubicweb.view import EntityView |
2217
3a8cee8f8778
explicit display_name import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2190
diff
changeset
|
17 |
from cubicweb.schema import display_name |
1739 | 18 |
from cubicweb.web import uicfg |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
19 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
21 |
class PrimaryView(EntityView): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
"""the full view of an non final entity""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
id = 'primary' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
title = _('primary') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
show_attr_label = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
show_rel_label = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
27 |
skip_none = True |
1739 | 28 |
rsection = uicfg.primaryview_section |
29 |
display_ctrl = uicfg.primaryview_display_ctrl |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
main_related_section = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
31 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
def html_headers(self): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
"""return a list of html headers (eg something to be inserted between |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
<head> and </head> of the returned page |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
by default primary views are indexed |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
return [] |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
39 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
def cell_call(self, row, col): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
self.row = row |
2402
321a87654988
strange, how does it work by computing maxrelated once everything is done ?
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2400
diff
changeset
|
42 |
self.maxrelated = self.req.property_value('navigation.related-limit') |
2384
6220783caa4b
[primary] cleanup, render_entity -> cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
43 |
entity = self.complete_entity(row, col) |
2400
17b1f0b80fe8
[primary] restore render_entity, as it is a bit too much work to update everything accordingly
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2384
diff
changeset
|
44 |
self.render_entity(entity) |
17b1f0b80fe8
[primary] restore render_entity, as it is a bit too much work to update everything accordingly
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2384
diff
changeset
|
45 |
|
17b1f0b80fe8
[primary] restore render_entity, as it is a bit too much work to update everything accordingly
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2384
diff
changeset
|
46 |
def render_entity(self, entity): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
47 |
self.render_entity_title(entity) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
self.render_entity_metadata(entity) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
# entity's attributes and relations, excluding meta data |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
# if the entity isn't meta itself |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
51 |
boxes = self._prepare_side_boxes(entity) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
52 |
if boxes or hasattr(self, 'render_side_related'): |
1558
f63d090eb34a
some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents:
1554
diff
changeset
|
53 |
self.w(u'<table width="100%"><tr><td style="width: 75%">') |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
self.w(u'<div class="mainInfo">') |
2132
d7ae060cd746
move navcontenttop on the top
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1977
diff
changeset
|
55 |
self.content_navigation_components('navcontenttop') |
2384
6220783caa4b
[primary] cleanup, render_entity -> cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
56 |
self.render_entity_attributes(entity) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
if self.main_related_section: |
2384
6220783caa4b
[primary] cleanup, render_entity -> cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
58 |
self.render_entity_relations(entity) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
self.w(u'</div>') |
2237
7e546c3d6ea5
[primary] fix #344249
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2217
diff
changeset
|
60 |
# side boxes |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
61 |
if boxes or hasattr(self, 'render_side_related'): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
self.w(u'</td><td>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
self.w(u'<div class="primaryRight">') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
64 |
if hasattr(self, 'render_side_related'): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
65 |
warn('render_side_related is deprecated') |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
66 |
self.render_side_related(entity, []) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
67 |
self.render_side_boxes(boxes) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
68 |
self.w(u'</div>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
69 |
self.w(u'</td></tr></table>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
self.content_navigation_components('navcontentbottom') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
72 |
def content_navigation_components(self, context): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
73 |
self.w(u'<div class="%s">' % context) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2402
diff
changeset
|
74 |
for comp in self.vreg['contentnavigation'].possible_vobjects( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2402
diff
changeset
|
75 |
self.req, rset=self.rset, row=self.row, view=self, context=context): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
try: |
1723 | 77 |
comp.render(w=self.w, row=self.row, view=self) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
78 |
except NotImplementedError: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
warn('component %s doesnt implement cell_call, please update' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
80 |
% comp.__class__, DeprecationWarning) |
1723 | 81 |
comp.render(w=self.w, view=self) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
self.w(u'</div>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
def render_entity_title(self, entity): |
1720 | 85 |
"""default implementation return dc_title""" |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2237
diff
changeset
|
86 |
title = xml_escape(entity.dc_title()) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
87 |
if title: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
self.w(u'<h1><span class="etype">%s</span> %s</h1>' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
% (entity.dc_type().capitalize(), title)) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
def render_entity_metadata(self, entity): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
92 |
entity.view('metadata', w=self.w) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
summary = self.summary(entity) # deprecate summary? |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
if summary: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
95 |
self.w(u'<div class="summary">%s</div>' % summary) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
96 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
97 |
def summary(self, entity): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
98 |
"""default implementation return an empty string""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
99 |
return u'' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
100 |
|
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
101 |
def render_entity_attributes(self, entity, siderelations=None): |
1739 | 102 |
for rschema, tschemas, role, dispctrl in self._section_def(entity, 'attributes'): |
2361
8f00836580f1
[reledit] do NOT propose to edit composite-related entities (unlinking would destroy the other side)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2312
diff
changeset
|
103 |
vid = dispctrl.get('vid', 'reledit') |
1558
f63d090eb34a
some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents:
1554
diff
changeset
|
104 |
if rschema.is_final() or vid == 'reledit': |
f63d090eb34a
some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents:
1554
diff
changeset
|
105 |
value = entity.view(vid, rtype=rschema.type, role=role) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
106 |
else: |
1739 | 107 |
rset = self._relation_rset(entity, rschema, role, dispctrl) |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
108 |
if rset: |
1558
f63d090eb34a
some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents:
1554
diff
changeset
|
109 |
value = self.view(vid, rset) |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
110 |
else: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
111 |
value = None |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
112 |
if self.skip_none and (value is None or value == ''): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
113 |
continue |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
114 |
self._render_attribute(rschema, value) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
115 |
|
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
116 |
def render_entity_relations(self, entity, siderelations=None): |
1739 | 117 |
for rschema, tschemas, role, dispctrl in self._section_def(entity, 'relations'): |
118 |
rset = self._relation_rset(entity, rschema, role, dispctrl) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
119 |
if rset: |
1739 | 120 |
self._render_relation(rset, dispctrl, 'autolimited', |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
121 |
self.show_rel_label) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
122 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
123 |
def render_side_boxes(self, boxes): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
124 |
"""display side related relations: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
125 |
non-meta in a first step, meta in a second step |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
126 |
""" |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
127 |
for box in boxes: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
128 |
if isinstance(box, tuple): |
1739 | 129 |
label, rset, vid = box |
1885
c2011d238e98
replace sideRelated with sideBox
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1752
diff
changeset
|
130 |
self.w(u'<div class="sideBox">') |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
131 |
self.wview(vid, rset, title=label) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
132 |
self.w(u'</div>') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
133 |
else: |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
134 |
try: |
1723 | 135 |
box.render(w=self.w, row=self.row) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
136 |
except NotImplementedError: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
137 |
# much probably a context insensitive box, which only implements |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
138 |
# .call() and not cell_call() |
1723 | 139 |
box.render(w=self.w) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
140 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
141 |
def _prepare_side_boxes(self, entity): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
142 |
sideboxes = [] |
1739 | 143 |
for rschema, tschemas, role, dispctrl in self._section_def(entity, 'sideboxes'): |
144 |
rset = self._relation_rset(entity, rschema, role, dispctrl) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
145 |
if not rset: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
146 |
continue |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
147 |
label = display_name(self.req, rschema.type, role) |
1739 | 148 |
vid = dispctrl.get('vid', 'sidebox') |
149 |
sideboxes.append( (label, rset, vid) ) |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2402
diff
changeset
|
150 |
sideboxes += self.vreg['boxes'].possible_vobjects( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2402
diff
changeset
|
151 |
self.req, rset=self.rset, row=self.row, view=self, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2402
diff
changeset
|
152 |
context='incontext') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
153 |
return sideboxes |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
|
1739 | 155 |
def _section_def(self, entity, where): |
156 |
rdefs = [] |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
157 |
eschema = entity.e_schema |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
158 |
for rschema, tschemas, role in eschema.relation_definitions(True): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
159 |
matchtschemas = [] |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
160 |
for tschema in tschemas: |
1739 | 161 |
section = self.rsection.etype_get(eschema, rschema, role, |
162 |
tschema) |
|
163 |
if section == where: |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
164 |
matchtschemas.append(tschema) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
165 |
if matchtschemas: |
1739 | 166 |
# XXX pick the latest dispctrl |
167 |
dispctrl = self.display_ctrl.etype_get(eschema, rschema, role, |
|
168 |
matchtschemas[-1]) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
169 |
|
1739 | 170 |
rdefs.append( (rschema, matchtschemas, role, dispctrl) ) |
171 |
return sorted(rdefs, key=lambda x: x[-1]['order']) |
|
172 |
||
173 |
def _relation_rset(self, entity, rschema, role, dispctrl): |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
174 |
try: |
1739 | 175 |
if dispctrl.get('limit'): |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
176 |
rset = entity.related(rschema.type, role, |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
177 |
limit=self.maxrelated+1) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
178 |
else: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
179 |
rset = entity.related(rschema.type, role) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
180 |
except Unauthorized: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
181 |
return |
1739 | 182 |
if 'filter' in dispctrl: |
183 |
rset = dispctrl['filter'](rset) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
184 |
return rset |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
185 |
|
1739 | 186 |
def _render_relation(self, rset, dispctrl, defaultvid, showlabel): |
1583 | 187 |
self.w(u'<div class="section">') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
188 |
if showlabel: |
1739 | 189 |
self.w(u'<h4>%s</h4>' % self.req._(dispctrl['label'])) |
190 |
self.wview(dispctrl.get('vid', defaultvid), rset) |
|
1583 | 191 |
self.w(u'</div>') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
192 |
|
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
193 |
def _render_attribute(self, rschema, value, role='subject'): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
194 |
if rschema.is_final(): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
195 |
show_label = self.show_attr_label |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
196 |
else: |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
197 |
show_label = self.show_rel_label |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
198 |
label = display_name(self.req, rschema.type, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
199 |
self.field(label, value, show_label=show_label, tr=False) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
200 |
|
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
201 |
|
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
202 |
class RelatedView(EntityView): |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
203 |
id = 'autolimited' |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
204 |
def call(self, title=None, **kwargs): |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
205 |
# if not too many entities, show them all in a list |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
206 |
maxrelated = self.req.property_value('navigation.related-limit') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
207 |
if title: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
208 |
self.w(u'<div class="title"><span>%s</span></div>' % title) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
209 |
if self.rset.rowcount <= maxrelated: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
210 |
if self.rset.rowcount == 1: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
211 |
self.wview('incontext', self.rset, row=0) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
212 |
elif 1 < self.rset.rowcount <= 5: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
213 |
self.wview('csv', self.rset) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
214 |
else: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
215 |
self.w(u'<div>') |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
216 |
self.wview('simplelist', self.rset) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
217 |
self.w(u'</div>') |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
218 |
# else show links to display related entities |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
219 |
else: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
220 |
rql = self.rset.printable_rql() |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
221 |
self.rset.limit(maxrelated) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
222 |
self.w(u'<div>') |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
223 |
self.wview('simplelist', self.rset) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
224 |
self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql), |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
225 |
self.req._('see them all'))) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
226 |
self.w(u'</div>') |
2652
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
227 |
|
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
228 |
## default primary ui configuration ########################################### |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
229 |
|
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
230 |
for rtype in ('eid', 'creation_date', 'modification_date', 'cwuri', |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
231 |
'is', 'is_instance_of', 'identity', |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
232 |
'owned_by', 'created_by', |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
233 |
'in_state', 'wf_info_for', 'require_permission', |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
234 |
'from_entity', 'to_entity', |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
235 |
'see_also'): |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
236 |
uicfg.primaryview_section.tag_subject_of(('*', rtype, '*'), 'hidden') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
237 |
uicfg.primaryview_section.tag_object_of(('*', rtype, '*'), 'hidden') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
238 |
uicfg.primaryview_section.tag_subject_of(('*', 'use_email', '*'), 'attributes') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
239 |
uicfg.primaryview_section.tag_subject_of(('*', 'primary_email', '*'), 'hidden') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
240 |
|
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
241 |
for attr in ('name', 'final'): |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
242 |
uicfg.primaryview_section.tag_attribute(('CWEType', attr), 'hidden') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
243 |
for attr in ('name', 'final', 'symetric', 'inlined'): |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
244 |
uicfg.primaryview_section.tag_attribute(('CWRType', attr), 'hidden') |