author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 14 Apr 2010 08:49:23 +0200 | |
changeset 5239 | 471554b842d2 |
parent 5222 | ed6905d98a5e |
child 5423 | e15abfdcce38 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3976
diff
changeset
|
4 |
:copyright: 2001-2010 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 |
3971
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
16 |
from cubicweb.selectors import match_kwargs |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
17 |
from cubicweb.view import EntityView |
5065
01d85f3a3d9e
[primary view] skip virtual rtypes anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4742
diff
changeset
|
18 |
from cubicweb.schema import VIRTUAL_RTYPES, display_name |
1739 | 19 |
from cubicweb.web import uicfg |
1491
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 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
class PrimaryView(EntityView): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
"""the full view of an non final entity""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
24 |
__regid__ = 'primary' |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
title = _('primary') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
show_attr_label = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
27 |
show_rel_label = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
28 |
skip_none = True |
1739 | 29 |
rsection = uicfg.primaryview_section |
30 |
display_ctrl = uicfg.primaryview_display_ctrl |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
31 |
main_related_section = True |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
def html_headers(self): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
"""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
|
35 |
<head> and </head> of the returned page |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
by default primary views are indexed |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
39 |
return [] |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
def cell_call(self, row, col): |
2889
5b42222d3b88
should affect cw_row/cw_col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
42 |
self.cw_row = row |
5b42222d3b88
should affect cw_row/cw_col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
43 |
self.cw_col = col |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
44 |
self.maxrelated = self._cw.property_value('navigation.related-limit') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
45 |
entity = self.cw_rset.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
|
46 |
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
|
47 |
|
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
|
48 |
def render_entity(self, entity): |
4566
c49dba55c0a6
[views] toolbox must be rendered before the title to appear at top right
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4467
diff
changeset
|
49 |
self.render_entity_toolbox(entity) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
self.render_entity_title(entity) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
51 |
# entity's attributes and relations, excluding meta data |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
# if the entity isn't meta itself |
3974
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
53 |
if self.is_primary(): |
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
54 |
boxes = self._prepare_side_boxes(entity) |
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
55 |
else: |
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
56 |
boxes = None |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
57 |
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
|
58 |
self.w(u'<table width="100%"><tr><td style="width: 75%">') |
3064
3fbcdf220ce9
fix so that entity's summary appears in main content cell to avoid layout pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2655
diff
changeset
|
59 |
self.render_entity_summary(entity) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
self.w(u'<div class="mainInfo">') |
2132
d7ae060cd746
move navcontenttop on the top
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1977
diff
changeset
|
61 |
self.content_navigation_components('navcontenttop') |
2384
6220783caa4b
[primary] cleanup, render_entity -> cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
62 |
self.render_entity_attributes(entity) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
if self.main_related_section: |
2384
6220783caa4b
[primary] cleanup, render_entity -> cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
64 |
self.render_entity_relations(entity) |
4742
fac80328a6a3
[primary] navcontentbottom sections should be in the content table as navcontenttop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4572
diff
changeset
|
65 |
self.content_navigation_components('navcontentbottom') |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
66 |
self.w(u'</div>') |
2237
7e546c3d6ea5
[primary] fix #344249
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2217
diff
changeset
|
67 |
# side boxes |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
68 |
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
|
69 |
self.w(u'</td><td>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
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
|
71 |
if hasattr(self, 'render_side_related'): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
72 |
warn('render_side_related is deprecated') |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
73 |
self.render_side_related(entity, []) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
74 |
self.render_side_boxes(boxes) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
self.w(u'</div>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
self.w(u'</td></tr></table>') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
78 |
def content_navigation_components(self, context): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
self.w(u'<div class="%s">' % context) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
80 |
for comp in self._cw.vreg['contentnavigation'].poss_visible_objects( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
81 |
self._cw, rset=self.cw_rset, row=self.cw_row, view=self, context=context): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
try: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
83 |
comp.render(w=self.w, row=self.cw_row, view=self) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
except NotImplementedError: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
85 |
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
|
86 |
% comp.__class__, DeprecationWarning) |
1723 | 87 |
comp.render(w=self.w, view=self) |
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 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
def render_entity_title(self, entity): |
1720 | 91 |
"""default implementation return dc_title""" |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2237
diff
changeset
|
92 |
title = xml_escape(entity.dc_title()) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
if title: |
3974
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
94 |
if self.is_primary(): |
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
95 |
self.w(u'<h1>%s</h1>' % title) |
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
96 |
else: |
4104
7e478d7caf20
[mq]: small_api_changes_for_3.6
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
4074
diff
changeset
|
97 |
atitle = self._cw._('follow this link for more information on this %s') % entity.dc_type() |
3974
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
98 |
self.w(u'<h4><a href="%s" title="%s">%s</a></h4>' |
1d36d9904c41
slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3972
diff
changeset
|
99 |
% (entity.absolute_url(), atitle, title)) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
100 |
|
3845
596044fb7bc5
introduce render_entity_toolbox on default primary view to display components in the ctxtoolbar context, such as pdf icon, notification registration (nosylist)...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3844
diff
changeset
|
101 |
def render_entity_toolbox(self, entity): |
596044fb7bc5
introduce render_entity_toolbox on default primary view to display components in the ctxtoolbar context, such as pdf icon, notification registration (nosylist)...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3844
diff
changeset
|
102 |
self.content_navigation_components('ctxtoolbar') |
596044fb7bc5
introduce render_entity_toolbox on default primary view to display components in the ctxtoolbar context, such as pdf icon, notification registration (nosylist)...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3844
diff
changeset
|
103 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
104 |
def render_entity_metadata(self, entity): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
105 |
entity.view('metadata', w=self.w) |
3064
3fbcdf220ce9
fix so that entity's summary appears in main content cell to avoid layout pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2655
diff
changeset
|
106 |
|
3fbcdf220ce9
fix so that entity's summary appears in main content cell to avoid layout pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2655
diff
changeset
|
107 |
def render_entity_summary(self, entity): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
108 |
summary = self.summary(entity) # deprecate summary? |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
109 |
if summary: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
110 |
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
|
111 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
112 |
def summary(self, entity): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
113 |
"""default implementation return an empty string""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
114 |
return u'' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
115 |
|
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5222
diff
changeset
|
116 |
def render_entity_attributes(self, entity): |
5180
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
117 |
display_attributes = [] |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
118 |
for rschema, _, 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
|
119 |
vid = dispctrl.get('vid', 'reledit') |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3681
diff
changeset
|
120 |
if rschema.final or 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
|
121 |
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
|
122 |
else: |
1739 | 123 |
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
|
124 |
if rset: |
4382
6fb02edd05da
3.6 api update, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
125 |
value = self._cw.view(vid, rset) |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
126 |
else: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
127 |
value = None |
5180
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
128 |
if not self.skip_none or (value is not None and value != ''): |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
129 |
display_attributes.append( (rschema, role, dispctrl, value) ) |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
130 |
if display_attributes: |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
131 |
self.w(u'<table>') |
5182
3bc8250731fe
[primary] fix name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5180
diff
changeset
|
132 |
for rschema, role, dispctrl, value in display_attributes: |
5180
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
133 |
try: |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
134 |
self._render_attribute(dispctrl, rschema, value, |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
135 |
role=role, table=True) |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
136 |
except TypeError: |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
137 |
warn('[3.6] _render_attribute prototype has changed, please' |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
138 |
' update %s' % self.__class___, DeprecationWarning) |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
139 |
self._render_attribute(rschema, value, role=role, table=True) |
25c3269b2232
[xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5065
diff
changeset
|
140 |
self.w(u'</table>') |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
141 |
|
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5222
diff
changeset
|
142 |
def render_entity_relations(self, entity): |
1739 | 143 |
for rschema, tschemas, role, dispctrl in self._section_def(entity, 'relations'): |
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 rset: |
3970
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
146 |
try: |
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
147 |
self._render_relation(dispctrl, rset, 'autolimited') |
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
148 |
except TypeError: |
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
149 |
warn('[3.6] _render_relation prototype has changed, ' |
3972 | 150 |
'please update %s' % self.__class__, DeprecationWarning) |
3970
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
151 |
self._render_relation(rset, dispctrl, 'autolimited', |
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
152 |
self.show_rel_label) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
153 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
154 |
def render_side_boxes(self, boxes): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
155 |
"""display side related relations: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
156 |
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
|
157 |
""" |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
158 |
for box in boxes: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
159 |
if isinstance(box, tuple): |
3975
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
160 |
try: |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
161 |
label, rset, vid, dispctrl = box |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
162 |
except ValueError: |
4572
9e0a86d3ba62
add version info to deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4566
diff
changeset
|
163 |
warn('[3.5] box views should now be defined as a 4-uple (label, rset, vid, dispctrl), ' |
3975
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
164 |
'please update %s' % self.__class__.__name__, |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
165 |
DeprecationWarning) |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
166 |
label, rset, vid = box |
1885
c2011d238e98
replace sideRelated with sideBox
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1752
diff
changeset
|
167 |
self.w(u'<div class="sideBox">') |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
168 |
self.wview(vid, rset, title=label) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
169 |
self.w(u'</div>') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
170 |
else: |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
171 |
try: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
172 |
box.render(w=self.w, row=self.cw_row) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
173 |
except NotImplementedError: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
174 |
# 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
|
175 |
# .call() and not cell_call() |
1723 | 176 |
box.render(w=self.w) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
177 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
178 |
def _prepare_side_boxes(self, entity): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
179 |
sideboxes = [] |
1739 | 180 |
for rschema, tschemas, role, dispctrl in self._section_def(entity, 'sideboxes'): |
181 |
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
|
182 |
if not rset: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
183 |
continue |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
184 |
label = display_name(self._cw, rschema.type, role) |
1739 | 185 |
vid = dispctrl.get('vid', 'sidebox') |
3975
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
186 |
sideboxes.append( (label, rset, vid, dispctrl) ) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
187 |
sideboxes += self._cw.vreg['boxes'].poss_visible_objects( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
188 |
self._cw, rset=self.cw_rset, row=self.cw_row, view=self, |
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
|
189 |
context='incontext') |
3975
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
190 |
# XXX since we've two sorted list, it may be worth using bisect |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
191 |
def get_order(x): |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
192 |
if isinstance(x, tuple): |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
193 |
# x is a view box (label, rset, vid, dispctrl) |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
194 |
# default to 1000 so view boxes occurs after component boxes |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
195 |
return x[-1].get('order', 1000) |
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
196 |
# x is a component box |
4073
03681ba6da0b
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4004
diff
changeset
|
197 |
return x.cw_propval('order') |
3975
569771016abb
add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3974
diff
changeset
|
198 |
return sorted(sideboxes, key=get_order) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
199 |
|
1739 | 200 |
def _section_def(self, entity, where): |
201 |
rdefs = [] |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
202 |
eschema = entity.e_schema |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
203 |
for rschema, tschemas, role in eschema.relation_definitions(True): |
5065
01d85f3a3d9e
[primary view] skip virtual rtypes anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4742
diff
changeset
|
204 |
if rschema in VIRTUAL_RTYPES: |
01d85f3a3d9e
[primary view] skip virtual rtypes anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4742
diff
changeset
|
205 |
continue |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
206 |
matchtschemas = [] |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
207 |
for tschema in tschemas: |
1739 | 208 |
section = self.rsection.etype_get(eschema, rschema, role, |
209 |
tschema) |
|
210 |
if section == where: |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
211 |
matchtschemas.append(tschema) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
212 |
if matchtschemas: |
1739 | 213 |
# XXX pick the latest dispctrl |
214 |
dispctrl = self.display_ctrl.etype_get(eschema, rschema, role, |
|
215 |
matchtschemas[-1]) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
216 |
|
1739 | 217 |
rdefs.append( (rschema, matchtschemas, role, dispctrl) ) |
218 |
return sorted(rdefs, key=lambda x: x[-1]['order']) |
|
219 |
||
220 |
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
|
221 |
try: |
3681
cdbe4aac1198
fix max-related of related entities handling in primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
222 |
dispctrl.setdefault('limit', self.maxrelated) |
cdbe4aac1198
fix max-related of related entities handling in primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
223 |
rset = entity.related(rschema.type, role, limit=dispctrl['limit']+1) |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
224 |
except Unauthorized: |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
225 |
return |
1739 | 226 |
if 'filter' in dispctrl: |
227 |
rset = dispctrl['filter'](rset) |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
228 |
return rset |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
229 |
|
3976
d18b80fe6c82
oops, should have been updated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3975
diff
changeset
|
230 |
def _render_relation(self, dispctrl, rset, defaultvid): |
1583 | 231 |
self.w(u'<div class="section">') |
3970
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
232 |
if dispctrl.get('showlabel', self.show_rel_label): |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
233 |
self.w(u'<h4>%s</h4>' % self._cw._(dispctrl['label'])) |
3705
5cd35123866b
get dispctrl through extra_kwargs to avoid error when a custom view is specified (potentially not taking any argument)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
234 |
self.wview(dispctrl.get('vid', defaultvid), rset, |
5cd35123866b
get dispctrl through extra_kwargs to avoid error when a custom view is specified (potentially not taking any argument)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
235 |
initargs={'dispctrl': dispctrl}) |
1583 | 236 |
self.w(u'</div>') |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1516
diff
changeset
|
237 |
|
3970
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
238 |
def _render_attribute(self, dispctrl, rschema, value, |
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
239 |
role='subject', table=False): |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3681
diff
changeset
|
240 |
if rschema.final: |
3970
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
241 |
showlabel = dispctrl.get('showlabel', self.show_attr_label) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
242 |
else: |
3970
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
243 |
showlabel = dispctrl.get('showlabel', self.show_rel_label) |
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
244 |
if dispctrl.get('label'): |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
245 |
label = self._cw._(dispctrl.get('label')) |
3970
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
246 |
else: |
4104
7e478d7caf20
[mq]: small_api_changes_for_3.6
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
4074
diff
changeset
|
247 |
label = display_name(self._cw, rschema.type, role) |
3970
e4ad7663610b
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3875
diff
changeset
|
248 |
self.field(label, value, show_label=showlabel, tr=False, table=table) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
249 |
|
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
250 |
|
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
251 |
class RelatedView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
252 |
__regid__ = 'autolimited' |
3681
cdbe4aac1198
fix max-related of related entities handling in primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
253 |
|
3705
5cd35123866b
get dispctrl through extra_kwargs to avoid error when a custom view is specified (potentially not taking any argument)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
254 |
def call(self, **kwargs): |
3681
cdbe4aac1198
fix max-related of related entities handling in primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
255 |
# nb: rset retreived using entity.related with limit + 1 if any |
cdbe4aac1198
fix max-related of related entities handling in primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
256 |
# because of that, we known that rset.printable_rql() will return |
cdbe4aac1198
fix max-related of related entities handling in primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
257 |
# rql with no limit set anyway (since it's handled manually) |
4072
ead446e70c28
some api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4004
diff
changeset
|
258 |
if 'dispctrl' in self.cw_extra_kwargs: |
ead446e70c28
some api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4004
diff
changeset
|
259 |
limit = self.cw_extra_kwargs['dispctrl'].get('limit') |
3705
5cd35123866b
get dispctrl through extra_kwargs to avoid error when a custom view is specified (potentially not taking any argument)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
260 |
else: |
5cd35123866b
get dispctrl through extra_kwargs to avoid error when a custom view is specified (potentially not taking any argument)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
261 |
limit = None |
3720 | 262 |
if limit is None or self.cw_rset.rowcount <= limit: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
263 |
if self.cw_rset.rowcount == 1: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
264 |
self.wview('incontext', self.cw_rset, row=0) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
265 |
elif 1 < self.cw_rset.rowcount <= 5: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
266 |
self.wview('csv', self.cw_rset) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
267 |
else: |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
268 |
self.w(u'<div>') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
269 |
self.wview('simplelist', self.cw_rset) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
270 |
self.w(u'</div>') |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
271 |
# else show links to display related entities |
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
272 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
273 |
rql = self.cw_rset.printable_rql() |
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
274 |
self.cw_rset.limit(limit) # remove extra entity |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
275 |
self.w(u'<div>') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
276 |
self.wview('simplelist', self.cw_rset) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
277 |
self.w(u'[<a href="%s">%s</a>]' % (self._cw.build_url(rql=rql), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
278 |
self._cw._('see them all'))) |
1516
288d55a7c5e2
refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
279 |
self.w(u'</div>') |
2652
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
280 |
|
3971
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
281 |
|
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
282 |
class URLAttributeView(EntityView): |
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
283 |
"""use this view for attributes whose value is an url and that you want |
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
284 |
to display as clickable link |
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
285 |
""" |
4004
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3998
diff
changeset
|
286 |
__regid__ = 'urlattr' |
3971
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
287 |
__select__ = EntityView.__select__ & match_kwargs('rtype') |
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
288 |
|
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
289 |
def cell_call(self, row, col, rtype, **kwargs): |
4232
d9d031d68be2
more 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4104
diff
changeset
|
290 |
entity = self.cw_rset.get_entity(row, col) |
3971
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
291 |
url = entity.printable_value(rtype) |
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
292 |
if url: |
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
293 |
self.w(u'<a href="%s">%s</a>' % (url, url)) |
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
294 |
|
7cfbc35dce7e
new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3970
diff
changeset
|
295 |
|
2652
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
296 |
## default primary ui configuration ########################################### |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
297 |
|
3875
c2bd7922cdaf
use shorter notation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3849
diff
changeset
|
298 |
_pvs = uicfg.primaryview_section |
2652
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2402
diff
changeset
|
299 |
for rtype in ('eid', 'creation_date', 'modification_date', 'cwuri', |
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5222
diff
changeset
|
300 |
'is', 'is_instance_of', 'identity', 'owned_by', 'created_by', |
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5222
diff
changeset
|
301 |
'require_permission', 'see_also'): |
3875
c2bd7922cdaf
use shorter notation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3849
diff
changeset
|
302 |
_pvs.tag_subject_of(('*', rtype, '*'), 'hidden') |
c2bd7922cdaf
use shorter notation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3849
diff
changeset
|
303 |
_pvs.tag_object_of(('*', rtype, '*'), 'hidden') |