author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 21 Aug 2009 15:03:00 +0200 | |
branch | stable |
changeset 2960 | 1c6eafc68586 |
parent 2780 | ad1dfc3855b0 |
child 2920 | 64322aa83a1d |
permissions | -rw-r--r-- |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
"""The automatic entity form. |
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:
1969
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:
1969
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 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
1702 | 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 logilab.common.decorators import iclassmethod |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
12 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
13 |
from cubicweb import typed_eid |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
14 |
from cubicweb.web import stdmsgs, uicfg |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1982
diff
changeset
|
15 |
from cubicweb.web.form import FieldNotFound |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1491
diff
changeset
|
16 |
from cubicweb.web.formfields import guess_field |
2652
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
17 |
from cubicweb.web import formwidgets |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1982
diff
changeset
|
18 |
from cubicweb.web.views import forms, editforms |
1528
864ae7c15ef5
other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1498
diff
changeset
|
19 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
|
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1982
diff
changeset
|
21 |
class AutomaticEntityForm(forms.EntityFieldsForm): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
"""base automatic form to edit any entity. |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
|
1560
7dd2a81b8bc8
[basecontrollers] add edit_relation next to edit_field, misc notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1540
diff
changeset
|
24 |
Designed to be fully generated from schema but highly configurable through: |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
* rtags (rcategories, rfields, rwidgets, inlined, rpermissions) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
* various standard form parameters |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
27 |
|
2780
ad1dfc3855b0
B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2652
diff
changeset
|
28 |
XXX s/rtags/uicfg/ ? |
ad1dfc3855b0
B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2652
diff
changeset
|
29 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
You can also easily customise it by adding/removing fields in |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
31 |
AutomaticEntityForm instances. |
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 |
id = 'edition' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
cwtarget = 'eformframe' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
cssclass = 'entityForm' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
copy_nav_params = True |
2652
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
38 |
form_buttons = [formwidgets.SubmitButton(), |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
39 |
formwidgets.Button(stdmsgs.BUTTON_APPLY, cwaction='apply'), |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
40 |
formwidgets.Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')] |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
attrcategories = ('primary', 'secondary') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
42 |
# class attributes below are actually stored in the uicfg module since we |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
# don't want them to be reloaded |
1739 | 44 |
rcategories = uicfg.autoform_section |
45 |
rfields = uicfg.autoform_field |
|
1754
c9c7618a90de
autoform_widget superseeded by autoform_field_kwargs (api change addiction :-/)
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
46 |
rfields_kwargs = uicfg.autoform_field_kwargs |
1739 | 47 |
rinlined = uicfg.autoform_is_inlined |
48 |
rpermissions_overrides = uicfg.autoform_permissions_overrides |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
@classmethod |
1739 | 51 |
def erelations_by_category(cls, entity, categories=None, permission=None, |
52 |
rtags=None): |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
53 |
"""return a list of (relation schema, target schemas, role) matching |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
categories and permission |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
if categories is not None: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
if not isinstance(categories, (list, tuple, set, frozenset)): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
categories = (categories,) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
if not isinstance(categories, (set, frozenset)): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
categories = frozenset(categories) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
eschema = entity.e_schema |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
if rtags is None: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
rtags = cls.rcategories |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
permsoverrides = cls.rpermissions_overrides |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
65 |
if entity.has_eid(): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
66 |
eid = entity.eid |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
67 |
else: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
68 |
eid = None |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
69 |
for rschema, targetschemas, role in eschema.relation_definitions(True): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
# check category first, potentially lower cost than checking |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
# permission which may imply rql queries |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
72 |
if categories is not None: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
73 |
targetschemas = [tschema for tschema in targetschemas |
1540
996355824825
more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1539
diff
changeset
|
74 |
if rtags.etype_get(eschema, rschema, role, tschema) in categories] |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
if not targetschemas: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
if permission is not None: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
78 |
# tag allowing to hijack the permission machinery when |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
# permission is not verifiable until the entity is actually |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
80 |
# created... |
1540
996355824825
more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1539
diff
changeset
|
81 |
if eid is None and '%s_on_new' % permission in permsoverrides.etype_get(eschema, rschema, role): |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
yield (rschema, targetschemas, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
if rschema.is_final(): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
85 |
if not rschema.has_perm(entity.req, permission, eid): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
86 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
87 |
elif role == 'subject': |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
if not ((eid is None and rschema.has_local_role(permission)) or |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
rschema.has_perm(entity.req, permission, fromeid=eid)): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
# on relation with cardinality 1 or ?, we need delete perm as well |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
92 |
# if the relation is already set |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
if (permission == 'add' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
and rschema.cardinality(eschema, targetschemas[0], role) in '1?' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
95 |
and eid and entity.related(rschema.type, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
96 |
and not rschema.has_perm(entity.req, 'delete', fromeid=eid, |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
97 |
toeid=entity.related(rschema.type, role)[0][0])): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
98 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
99 |
elif role == 'object': |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
100 |
if not ((eid is None and rschema.has_local_role(permission)) or |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
101 |
rschema.has_perm(entity.req, permission, toeid=eid)): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
102 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
103 |
# on relation with cardinality 1 or ?, we need delete perm as well |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
104 |
# if the relation is already set |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
105 |
if (permission == 'add' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
106 |
and rschema.cardinality(targetschemas[0], eschema, role) in '1?' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
107 |
and eid and entity.related(rschema.type, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
108 |
and not rschema.has_perm(entity.req, 'delete', toeid=eid, |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
109 |
fromeid=entity.related(rschema.type, role)[0][0])): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
110 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
111 |
yield (rschema, targetschemas, role) |
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 |
@classmethod |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
114 |
def esrelations_by_category(cls, entity, categories=None, permission=None): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
115 |
"""filter out result of relations_by_category(categories, permission) by |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
116 |
removing final relations |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
117 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
118 |
return a sorted list of (relation's label, relation'schema, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
119 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
120 |
result = [] |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
121 |
for rschema, ttypes, role in cls.erelations_by_category( |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
122 |
entity, categories, permission): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
123 |
if rschema.is_final(): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
124 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
125 |
result.append((rschema.display_name(entity.req, role), rschema, role)) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
126 |
return sorted(result) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
127 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
128 |
@iclassmethod |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
129 |
def field_by_name(cls_or_self, name, role='subject', eschema=None): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
130 |
"""return field with the given name and role. If field is not explicitly |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
131 |
defined for the form but `eclass` is specified, guess_field will be |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
132 |
called. |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
133 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
134 |
try: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
135 |
return super(AutomaticEntityForm, cls_or_self).field_by_name(name, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
136 |
except FieldNotFound: # XXX should raise more explicit exception |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
137 |
if eschema is None or not name in cls_or_self.schema: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
138 |
raise |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
139 |
rschema = cls_or_self.schema.rschema(name) |
1743
591cff8f0701
take a sample target type instead of '*' else we may miss some expected values (we may still miss some...)
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
140 |
# XXX use a sample target type. Document this. |
591cff8f0701
take a sample target type instead of '*' else we may miss some expected values (we may still miss some...)
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
141 |
tschemas = rschema.targets(eschema, role) |
2096 | 142 |
fieldcls = cls_or_self.rfields.etype_get(eschema, rschema, role, |
143 |
tschemas[0]) |
|
144 |
kwargs = cls_or_self.rfields_kwargs.etype_get(eschema, rschema, |
|
145 |
role, tschemas[0]) |
|
1782
aa7136519c19
consider fields_kwargs even when field specified
sylvain.thenault@logilab.fr
parents:
1754
diff
changeset
|
146 |
if kwargs is None: |
aa7136519c19
consider fields_kwargs even when field specified
sylvain.thenault@logilab.fr
parents:
1754
diff
changeset
|
147 |
kwargs = {} |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
148 |
if fieldcls: |
1788
d6e6ad70e50a
check field isn't already instantiated
sylvain.thenault@logilab.fr
parents:
1782
diff
changeset
|
149 |
if not isinstance(fieldcls, type): |
d6e6ad70e50a
check field isn't already instantiated
sylvain.thenault@logilab.fr
parents:
1782
diff
changeset
|
150 |
return fieldcls # already and instance |
1782
aa7136519c19
consider fields_kwargs even when field specified
sylvain.thenault@logilab.fr
parents:
1754
diff
changeset
|
151 |
return fieldcls(name=name, role=role, eidparam=True, **kwargs) |
aa7136519c19
consider fields_kwargs even when field specified
sylvain.thenault@logilab.fr
parents:
1754
diff
changeset
|
152 |
field = guess_field(eschema, rschema, role, eidparam=True, **kwargs) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
153 |
if field is None: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
raise |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
155 |
return field |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
156 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
157 |
def __init__(self, *args, **kwargs): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
158 |
super(AutomaticEntityForm, self).__init__(*args, **kwargs) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
159 |
entity = self.edited_entity |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
160 |
if entity.has_eid(): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
161 |
entity.complete() |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
162 |
for rschema, role in self.editable_attributes(): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
163 |
try: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
164 |
self.field_by_name(rschema.type, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
165 |
continue # explicitly specified |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
166 |
except FieldNotFound: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
167 |
# has to be guessed |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
168 |
try: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
169 |
field = self.field_by_name(rschema.type, role, |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
170 |
eschema=entity.e_schema) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
171 |
self.fields.append(field) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
172 |
except FieldNotFound: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
173 |
# meta attribute such as <attr>_format |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
174 |
continue |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
175 |
self.maxrelitems = self.req.property_value('navigation.related-limit') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
176 |
self.force_display = bool(self.req.form.get('__force_display')) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
177 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
178 |
@property |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
179 |
def related_limit(self): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
180 |
if self.force_display: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
181 |
return None |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
182 |
return self.maxrelitems + 1 |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
183 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
184 |
def relations_by_category(self, categories=None, permission=None): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
185 |
"""return a list of (relation schema, target schemas, role) matching |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
186 |
given category(ies) and permission |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
187 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
188 |
return self.erelations_by_category(self.edited_entity, categories, |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
189 |
permission) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
190 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
191 |
def inlined_relations(self): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
192 |
"""return a list of (relation schema, target schemas, role) matching |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
193 |
given category(ies) and permission |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
194 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
195 |
# we'll need an initialized varmaker if there are some inlined relation |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
196 |
self.initialize_varmaker() |
1969 | 197 |
return self.erelations_by_category(self.edited_entity, True, 'add', |
198 |
self.rinlined) |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
199 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
200 |
def srelations_by_category(self, categories=None, permission=None): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
201 |
"""filter out result of relations_by_category(categories, permission) by |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
202 |
removing final relations |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
203 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
204 |
return a sorted list of (relation's label, relation'schema, role) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
205 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
206 |
return self.esrelations_by_category(self.edited_entity, categories, |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
207 |
permission) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
208 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
209 |
def action(self): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
210 |
"""return the form's action attribute. Default to validateform if not |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
211 |
explicitly overriden. |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
212 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
213 |
try: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
214 |
return self._action |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
215 |
except AttributeError: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
216 |
return self.build_url('validateform') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
217 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
218 |
def set_action(self, value): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
219 |
"""override default action""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
220 |
self._action = value |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
221 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
222 |
action = property(action, set_action) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
223 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
224 |
def editable_attributes(self): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
225 |
"""return a list of (relation schema, role) to edit for the entity""" |
1702 | 226 |
return [(rschema, role) for rschema, _, role in self.relations_by_category( |
1528
864ae7c15ef5
other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1498
diff
changeset
|
227 |
self.attrcategories, 'add') if rschema != 'eid'] |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
228 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
229 |
def relations_table(self): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
230 |
"""yiels 3-tuples (rtype, target, related_list) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
231 |
where <related_list> itself a list of : |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
232 |
- node_id (will be the entity element's DOM id) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
233 |
- appropriate javascript's togglePendingDelete() function call |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
234 |
- status 'pendingdelete' or '' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
235 |
- oneline view of related entity |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
236 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
237 |
entity = self.edited_entity |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
238 |
pending_deletes = self.req.get_pending_deletes(entity.eid) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
239 |
for label, rschema, role in self.srelations_by_category('generic', 'add'): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
240 |
relatedrset = entity.related(rschema, role, limit=self.related_limit) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
241 |
if rschema.has_perm(self.req, 'delete'): |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1982
diff
changeset
|
242 |
toggleable_rel_link_func = editforms.toggleable_relation_link |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
243 |
else: |
1528
864ae7c15ef5
other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1498
diff
changeset
|
244 |
toggleable_rel_link_func = lambda x, y, z: u'' |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
245 |
related = [] |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
246 |
for row in xrange(relatedrset.rowcount): |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1982
diff
changeset
|
247 |
nodeid = editforms.relation_id(entity.eid, rschema, role, |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1982
diff
changeset
|
248 |
relatedrset[row][0]) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
249 |
if nodeid in pending_deletes: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
250 |
status = u'pendingDelete' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
251 |
label = '+' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
252 |
else: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
253 |
status = u'' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
254 |
label = 'x' |
1528
864ae7c15ef5
other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1498
diff
changeset
|
255 |
dellink = toggleable_rel_link_func(entity.eid, nodeid, label) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
256 |
eview = self.view('oneline', relatedrset, row=row) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
257 |
related.append((nodeid, dellink, status, eview)) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
258 |
yield (rschema, role, related) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
259 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
260 |
def restore_pending_inserts(self, cell=False): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
261 |
"""used to restore edition page as it was before clicking on |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
262 |
'search for <some entity type>' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
263 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
264 |
eid = self.edited_entity.eid |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
265 |
cell = cell and "div_insert_" or "tr" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
266 |
pending_inserts = set(self.req.get_pending_inserts(eid)) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
267 |
for pendingid in pending_inserts: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
268 |
eidfrom, rtype, eidto = pendingid.split(':') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
269 |
if typed_eid(eidfrom) == eid: # subject |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
270 |
label = display_name(self.req, rtype, 'subject') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
271 |
reid = eidto |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
272 |
else: |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
273 |
label = display_name(self.req, rtype, 'object') |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
274 |
reid = eidfrom |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
275 |
jscall = "javascript: cancelPendingInsert('%s', '%s', null, %s);" \ |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
276 |
% (pendingid, cell, eid) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
277 |
rset = self.req.eid_rset(reid) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
278 |
eview = self.view('text', rset, row=0) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
279 |
# XXX find a clean way to handle baskets |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
280 |
if rset.description[0][0] == 'Basket': |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
281 |
eview = '%s (%s)' % (eview, display_name(self.req, 'Basket')) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
282 |
yield rtype, pendingid, jscall, label, reid, eview |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
283 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
284 |
# should_* method extracted to allow overriding |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
285 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
286 |
def should_inline_relation_form(self, rschema, targettype, role): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
287 |
"""return true if the given relation with entity has role and a |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
288 |
targettype target should be inlined |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
289 |
""" |
1540
996355824825
more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1539
diff
changeset
|
290 |
return self.rinlined.etype_get(self.edited_entity.id, rschema, role, targettype) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
291 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
292 |
def should_display_inline_creation_form(self, rschema, existant, card): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
293 |
"""return true if a creation form should be inlined |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
294 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
295 |
by default true if there is no related entity and we need at least one |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
296 |
""" |
2143
d4c2fb633062
add form parameter to control display of inlined relation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2096
diff
changeset
|
297 |
return not existant and card in '1+' or self.req.form.has_key('force_%s_display' % rschema) |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
298 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
299 |
def should_display_add_new_relation_link(self, rschema, existant, card): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
300 |
"""return true if we should add a link to add a new creation form |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
301 |
(through ajax call) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
302 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
303 |
by default true if there is no related entity or if the relation has |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
304 |
multiple cardinality |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
305 |
""" |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
306 |
return not existant or card in '+*' |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
307 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
308 |
|
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
309 |
def etype_relation_field(etype, rtype, role='subject'): |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
310 |
eschema = AutomaticEntityForm.schema.eschema(etype) |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
311 |
return AutomaticEntityForm.field_by_name(rtype, role, eschema) |
2652
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
312 |
|
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
313 |
|
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
314 |
## default form ui configuration ############################################## |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
315 |
|
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
316 |
# use primary and not generated for eid since it has to be an hidden |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
317 |
uicfg.autoform_section.tag_attribute(('*', 'eid'), 'primary') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
318 |
uicfg.autoform_section.tag_attribute(('*', 'description'), 'secondary') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
319 |
uicfg.autoform_section.tag_attribute(('*', 'creation_date'), 'metadata') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
320 |
uicfg.autoform_section.tag_attribute(('*', 'modification_date'), 'metadata') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
321 |
uicfg.autoform_section.tag_attribute(('*', 'cwuri'), 'metadata') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
322 |
uicfg.autoform_section.tag_attribute(('*', 'has_text'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
323 |
uicfg.autoform_section.tag_subject_of(('*', 'in_state', '*'), 'primary') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
324 |
uicfg.autoform_section.tag_subject_of(('*', 'owned_by', '*'), 'metadata') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
325 |
uicfg.autoform_section.tag_subject_of(('*', 'created_by', '*'), 'metadata') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
326 |
uicfg.autoform_section.tag_subject_of(('*', 'is', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
327 |
uicfg.autoform_section.tag_object_of(('*', 'is', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
328 |
uicfg.autoform_section.tag_subject_of(('*', 'is_instance_of', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
329 |
uicfg.autoform_section.tag_object_of(('*', 'is_instance_of', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
330 |
uicfg.autoform_section.tag_subject_of(('*', 'identity', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
331 |
uicfg.autoform_section.tag_object_of(('*', 'identity', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
332 |
uicfg.autoform_section.tag_subject_of(('*', 'require_permission', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
333 |
uicfg.autoform_section.tag_subject_of(('*', 'wf_info_for', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
334 |
uicfg.autoform_section.tag_object_of(('*', 'wf_info_for', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
335 |
uicfg.autoform_section.tag_subject_of(('*', 'for_user', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
336 |
uicfg.autoform_section.tag_object_of(('*', 'for_user', '*'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
337 |
uicfg.autoform_section.tag_subject_of(('CWPermission', 'require_group', '*'), 'primary') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
338 |
uicfg.autoform_section.tag_attribute(('CWEType', 'final'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
339 |
uicfg.autoform_section.tag_attribute(('CWRType', 'final'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
340 |
uicfg.autoform_section.tag_attribute(('CWUser', 'firstname'), 'secondary') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
341 |
uicfg.autoform_section.tag_attribute(('CWUser', 'surname'), 'secondary') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
342 |
uicfg.autoform_section.tag_attribute(('CWUser', 'last_login_time'), 'metadata') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
343 |
uicfg.autoform_section.tag_subject_of(('CWUser', 'in_group', '*'), 'primary') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
344 |
uicfg.autoform_section.tag_object_of(('*', 'owned_by', 'CWUser'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
345 |
uicfg.autoform_section.tag_object_of(('*', 'created_by', 'CWUser'), 'generated') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
346 |
uicfg.autoform_section.tag_object_of(('*', 'bookmarked_by', 'CWUser'), 'metadata') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
347 |
uicfg.autoform_section.tag_attribute(('Bookmark', 'path'), 'primary') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
348 |
uicfg.autoform_section.tag_subject_of(('*', 'use_email', '*'), 'generated') # inlined actually |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
349 |
uicfg.autoform_section.tag_subject_of(('*', 'primary_email', '*'), 'generic') |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
350 |
|
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
351 |
uicfg.autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'), |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
352 |
{'widget': formwidgets.TextInput}) |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
353 |
uicfg.autoform_field_kwargs.tag_attribute(('Bookmark', 'path'), |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
354 |
{'widget': formwidgets.TextInput}) |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
355 |
|
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
356 |
uicfg.autoform_is_inlined.tag_subject_of(('*', 'use_email', '*'), True) |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
357 |
uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'relation_type', '*'), True) |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
358 |
uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'from_entity', '*'), True) |
3753f3a07ca1
[refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2143
diff
changeset
|
359 |
uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'to_entity', '*'), True) |