author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Mon, 23 Aug 2010 09:07:20 +0200 | |
branch | stable |
changeset 6134 | 272cfcc10a28 |
parent 5424 | 8ecbcbff9777 |
child 6140 | 65a619eb31c4 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""Set of views allowing edition of entities/relations using ajax |
19 |
||
20 |
""" |
|
21 |
__docformat__ = "restructuredtext en" |
|
22 |
||
1622
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
23 |
from cubicweb import role |
1132 | 24 |
from cubicweb.selectors import match_form_params, match_kwargs |
0 | 25 |
from cubicweb.web.box import EditRelationBoxTemplate |
26 |
||
27 |
class AddRelationView(EditRelationBoxTemplate): |
|
28 |
"""base class for view which let add entities linked |
|
29 |
by a given relation |
|
30 |
||
31 |
subclasses should define at least id, rtype and target |
|
32 |
class attributes. |
|
33 |
""" |
|
34 |
__registry__ = 'views' |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2867
diff
changeset
|
35 |
__regid__ = 'xaddrelation' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
36 |
__select__ = (match_form_params('rtype', 'target') |
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
37 |
| match_kwargs('rtype', 'target')) |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
38 |
cw_property_defs = {} # don't want to inherit this from Box |
0 | 39 |
expected_kwargs = form_params = ('rtype', 'target') |
40 |
||
41 |
build_js = EditRelationBoxTemplate.build_reload_js_call |
|
1622
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
42 |
|
0 | 43 |
def cell_call(self, row, col, rtype=None, target=None, etype=None): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
44 |
self.rtype = rtype or self._cw.form['rtype'] |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
45 |
self.target = target or self._cw.form['target'] |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
46 |
self.etype = etype or self._cw.form.get('etype') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
47 |
entity = self.cw_rset.get_entity(row, col) |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3451
diff
changeset
|
48 |
rschema = self._cw.vreg.schema.rschema(self.rtype) |
0 | 49 |
if not self.etype: |
50 |
if self.target == 'object': |
|
51 |
etypes = rschema.objects(entity.e_schema) |
|
52 |
else: |
|
53 |
etypes = rschema.subjects(entity.e_schema) |
|
54 |
if len(etypes) == 1: |
|
55 |
self.etype = etypes[0] |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
56 |
self.w(u'<div id="%s">' % self.__regid__) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
57 |
self.w(u'<h1>%s</h1>' % self._cw._('relation %(relname)s of %(ent)s') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
58 |
% {'relname': rschema.display_name(self._cw, role(self)), |
0 | 59 |
'ent': entity.view('incontext')}) |
60 |
self.w(u'<ul>') |
|
2866 | 61 |
for boxitem in self.unrelated_boxitems(entity): |
0 | 62 |
boxitem.render(self.w) |
63 |
self.w(u'</ul></div>') |
|
64 |
||
65 |
def unrelated_entities(self, entity): |
|
66 |
"""returns the list of unrelated entities |
|
67 |
||
68 |
if etype is not defined on the Box's class, the default |
|
69 |
behaviour is to use the entity's appropraite vocabulary function |
|
70 |
""" |
|
71 |
# use entity.unrelated if we've been asked for a particular etype |
|
72 |
if getattr(self, 'etype', None): |
|
1622
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
73 |
rset = entity.unrelated(self.rtype, self.etype, role(self), |
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
74 |
ordermethod='fetch_order') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
75 |
self.pagination(self._cw, rset, w=self.w) |
0 | 76 |
return rset.entities() |
77 |
# in other cases, use vocabulary functions |
|
78 |
entities = [] |
|
1622
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
79 |
# XXX to update for 3.2 |
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
80 |
for _, eid in entity.vocabulary(self.rtype, role(self)): |
0 | 81 |
if eid is not None: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
82 |
rset = self._cw.eid_rset(eid) |
0 | 83 |
entities.append(rset.get_entity(0, 0)) |
84 |
return entities |