author | sylvain.thenault@logilab.fr |
Tue, 12 May 2009 11:56:12 +0200 | |
branch | tls-sprint |
changeset 1739 | 78b0819162a8 |
parent 1726 | 08918409815e |
child 1752 | 4b0b912ff5b7 |
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 |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
6 |
""" |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
7 |
__docformat__ = "restructuredtext en" |
1739 | 8 |
_ = unicode |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
9 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
10 |
from warnings import warn |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
11 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
12 |
from logilab.mtconverter import html_escape |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
13 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
14 |
from cubicweb import Unauthorized |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
15 |
from cubicweb.view import EntityView |
1739 | 16 |
from cubicweb.web import uicfg |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
17 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
18 |
|
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 |
class PrimaryView(EntityView): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
21 |
"""the full view of an non final entity""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
id = 'primary' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
title = _('primary') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
show_attr_label = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
show_rel_label = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
skip_none = True |
1739 | 27 |
rsection = uicfg.primaryview_section |
28 |
display_ctrl = uicfg.primaryview_display_ctrl |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
main_related_section = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
31 |
@classmethod |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
32 |
def vreg_initialization_completed(cls): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
33 |
"""set default category tags for relations where it's not yet defined in |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
34 |
the category relation tags |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
35 |
""" |
1739 | 36 |
cls.rsection.init(cls.schema) |
37 |
cls.display_ctrl.init(cls.schema) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
38 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
39 |
def html_headers(self): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
"""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
|
41 |
<head> and </head> of the returned page |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
42 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
by default primary views are indexed |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
44 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
45 |
return [] |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
46 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
47 |
def cell_call(self, row, col): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
self.row = row |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
# XXX move render_entity implementation here |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
self.render_entity(self.complete_entity(row, col)) |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
51 |
self.maxrelated = self.req.property_value('navigation.related-limit') |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
53 |
def render_entity(self, entity): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
"""return html to display the given entity""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
self.render_entity_title(entity) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
self.render_entity_metadata(entity) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
# entity's attributes and relations, excluding meta data |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
# 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
|
59 |
boxes = self._prepare_side_boxes(entity) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
self.w(u'<div>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
self.w(u'<div class="mainInfo">') |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
64 |
try: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
65 |
self.render_entity_attributes(entity) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
66 |
except TypeError: # XXX bw compat |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
67 |
warn('siderelations argument of render_entity_attributes is ' |
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
|
68 |
'deprecated (%s)' % self.__class__) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
69 |
self.render_entity_attributes(entity, []) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
self.w(u'</div>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
self.content_navigation_components('navcontenttop') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
72 |
if self.main_related_section: |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
73 |
try: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
74 |
self.render_entity_relations(entity) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
75 |
except TypeError: # XXX bw compat |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
76 |
warn('siderelations argument of render_entity_relations is ' |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
77 |
'deprecated') |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
78 |
self.render_entity_relations(entity, []) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
self.w(u'</div>') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
80 |
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
|
81 |
self.w(u'</td><td>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
# side boxes |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
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
|
84 |
if hasattr(self, 'render_side_related'): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
85 |
warn('render_side_related is deprecated') |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
86 |
self.render_side_related(entity, []) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
87 |
self.render_side_boxes(boxes) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
self.w(u'</div>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
self.w(u'</td></tr></table>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
self.content_navigation_components('navcontentbottom') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
92 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
def content_navigation_components(self, context): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
self.w(u'<div class="%s">' % context) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
95 |
for comp in self.vreg.possible_vobjects('contentnavigation', |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
96 |
self.req, self.rset, row=self.row, |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
97 |
view=self, context=context): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
98 |
try: |
1723 | 99 |
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
|
100 |
except NotImplementedError: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
101 |
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
|
102 |
% comp.__class__, DeprecationWarning) |
1723 | 103 |
comp.render(w=self.w, view=self) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
104 |
self.w(u'</div>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
105 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
106 |
def render_entity_title(self, entity): |
1720 | 107 |
"""default implementation return dc_title""" |
108 |
title = html_escape(entity.dc_title()) |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
109 |
if title: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
110 |
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
|
111 |
% (entity.dc_type().capitalize(), title)) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
112 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
113 |
def render_entity_metadata(self, entity): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
114 |
entity.view('metadata', w=self.w) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
115 |
summary = self.summary(entity) # deprecate summary? |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
116 |
if summary: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
117 |
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
|
118 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
119 |
def summary(self, entity): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
120 |
"""default implementation return an empty string""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
121 |
return u'' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
122 |
|
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
123 |
def render_entity_attributes(self, entity, siderelations=None): |
1739 | 124 |
for rschema, tschemas, role, dispctrl in self._section_def(entity, 'attributes'): |
125 |
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
|
126 |
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
|
127 |
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
|
128 |
else: |
1739 | 129 |
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
|
130 |
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
|
131 |
value = self.view(vid, rset) |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
132 |
else: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
133 |
value = None |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
134 |
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
|
135 |
continue |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
136 |
self._render_attribute(rschema, value) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
137 |
|
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
138 |
def render_entity_relations(self, entity, siderelations=None): |
1739 | 139 |
for rschema, tschemas, role, dispctrl in self._section_def(entity, 'relations'): |
140 |
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
|
141 |
if rset: |
1739 | 142 |
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
|
143 |
self.show_rel_label) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
144 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
145 |
def render_side_boxes(self, boxes): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
146 |
"""display side related relations: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
147 |
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
|
148 |
""" |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
149 |
for box in boxes: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
150 |
if isinstance(box, tuple): |
1739 | 151 |
label, rset, vid = box |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
152 |
self.w(u'<div class="sideRelated">') |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
153 |
self.wview(vid, rset, title=label) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
self.w(u'</div>') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
155 |
else: |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
156 |
try: |
1723 | 157 |
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
|
158 |
except NotImplementedError: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
159 |
# 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
|
160 |
# .call() and not cell_call() |
1723 | 161 |
box.render(w=self.w) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
162 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
163 |
def _prepare_side_boxes(self, entity): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
164 |
sideboxes = [] |
1739 | 165 |
for rschema, tschemas, role, dispctrl in self._section_def(entity, 'sideboxes'): |
166 |
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
|
167 |
if not rset: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
168 |
continue |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
169 |
label = display_name(self.req, rschema.type, role) |
1739 | 170 |
vid = dispctrl.get('vid', 'sidebox') |
171 |
sideboxes.append( (label, rset, vid) ) |
|
172 |
sideboxes += self.vreg.possible_vobjects('boxes', self.req, self.rset, |
|
173 |
row=self.row, view=self, |
|
174 |
context='incontext') |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
175 |
return sideboxes |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
176 |
|
1739 | 177 |
def _section_def(self, entity, where): |
178 |
rdefs = [] |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
179 |
eschema = entity.e_schema |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
180 |
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
|
181 |
matchtschemas = [] |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
182 |
for tschema in tschemas: |
1739 | 183 |
section = self.rsection.etype_get(eschema, rschema, role, |
184 |
tschema) |
|
185 |
if section == where: |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
186 |
matchtschemas.append(tschema) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
187 |
if matchtschemas: |
1739 | 188 |
# XXX pick the latest dispctrl |
189 |
dispctrl = self.display_ctrl.etype_get(eschema, rschema, role, |
|
190 |
matchtschemas[-1]) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
191 |
|
1739 | 192 |
rdefs.append( (rschema, matchtschemas, role, dispctrl) ) |
193 |
return sorted(rdefs, key=lambda x: x[-1]['order']) |
|
194 |
||
195 |
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
|
196 |
try: |
1739 | 197 |
if dispctrl.get('limit'): |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
198 |
rset = entity.related(rschema.type, role, |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
199 |
limit=self.maxrelated+1) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
200 |
else: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
201 |
rset = entity.related(rschema.type, role) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
202 |
except Unauthorized: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
203 |
return |
1739 | 204 |
if 'filter' in dispctrl: |
205 |
rset = dispctrl['filter'](rset) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
206 |
return rset |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
207 |
|
1739 | 208 |
def _render_relation(self, rset, dispctrl, defaultvid, showlabel): |
1583 | 209 |
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
|
210 |
if showlabel: |
1739 | 211 |
self.w(u'<h4>%s</h4>' % self.req._(dispctrl['label'])) |
212 |
self.wview(dispctrl.get('vid', defaultvid), rset) |
|
1583 | 213 |
self.w(u'</div>') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
214 |
|
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
215 |
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
|
216 |
if rschema.is_final(): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
217 |
show_label = self.show_attr_label |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
218 |
else: |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
219 |
show_label = self.show_rel_label |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
220 |
label = display_name(self.req, rschema.type, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
221 |
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
|
222 |
|
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
223 |
|
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
224 |
class RelatedView(EntityView): |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
225 |
id = 'autolimited' |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
226 |
def call(self, title=None, **kwargs): |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
227 |
# 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
|
228 |
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
|
229 |
if title: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
230 |
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
|
231 |
if self.rset.rowcount <= maxrelated: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
232 |
if self.rset.rowcount == 1: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
233 |
self.wview('incontext', self.rset, row=0) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
234 |
elif 1 < self.rset.rowcount <= 5: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
235 |
self.wview('csv', self.rset) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
236 |
else: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
237 |
self.w(u'<div>') |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
238 |
self.wview('simplelist', self.rset) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
239 |
self.w(u'</div>') |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
240 |
# else show links to display related entities |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
241 |
else: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
242 |
rql = self.rset.printable_rql() |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
243 |
self.rset.limit(maxrelated) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
244 |
self.w(u'<div>') |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
245 |
self.wview('simplelist', self.rset) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
246 |
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
|
247 |
self.req._('see them all'))) |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
248 |
self.w(u'</div>') |