author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 10 Jan 2011 12:28:09 +0100 | |
branch | stable |
changeset 6796 | e70ca9abfc51 |
parent 6497 | 84fbd09f8c6b |
child 6924 | b88221afe491 |
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/>. |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
18 |
"""Set of views allowing edition of entities/relations using ajax""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
1622
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
22 |
from cubicweb import role |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
23 |
from cubicweb.view import View |
1132 | 24 |
from cubicweb.selectors import match_form_params, match_kwargs |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
25 |
from cubicweb.web.component import EditRelationMixIn |
0 | 26 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
27 |
class AddRelationView(EditRelationMixIn, View): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
28 |
"""base class for view which let add entities linked by a given relation |
0 | 29 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
30 |
subclasses should define at least id, rtype and target class attributes. |
0 | 31 |
""" |
32 |
__registry__ = 'views' |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2867
diff
changeset
|
33 |
__regid__ = 'xaddrelation' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
34 |
__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
|
35 |
| match_kwargs('rtype', 'target')) |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
36 |
cw_property_defs = {} # don't want to inherit this from Box |
0 | 37 |
expected_kwargs = form_params = ('rtype', 'target') |
38 |
||
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
39 |
build_js = EditRelationMixIn.build_reload_js_call |
1622
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
40 |
|
0 | 41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
rschema = self._cw.vreg.schema.rschema(self.rtype) |
0 | 47 |
if not self.etype: |
48 |
if self.target == 'object': |
|
49 |
etypes = rschema.objects(entity.e_schema) |
|
50 |
else: |
|
51 |
etypes = rschema.subjects(entity.e_schema) |
|
52 |
if len(etypes) == 1: |
|
53 |
self.etype = etypes[0] |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
54 |
self.w(u'<div id="%s">' % self.domid) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
55 |
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
|
56 |
% {'relname': rschema.display_name(self._cw, role(self)), |
0 | 57 |
'ent': entity.view('incontext')}) |
58 |
self.w(u'<ul>') |
|
2866 | 59 |
for boxitem in self.unrelated_boxitems(entity): |
6497 | 60 |
self.w('<li class="invisible">%s</li>' % boxitem) |
0 | 61 |
self.w(u'</ul></div>') |
62 |
||
63 |
def unrelated_entities(self, entity): |
|
64 |
"""returns the list of unrelated entities |
|
65 |
||
66 |
if etype is not defined on the Box's class, the default |
|
67 |
behaviour is to use the entity's appropraite vocabulary function |
|
68 |
""" |
|
69 |
# use entity.unrelated if we've been asked for a particular etype |
|
70 |
if getattr(self, 'etype', None): |
|
1622
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
71 |
rset = entity.unrelated(self.rtype, self.etype, role(self), |
1a1c494b88e2
xtarget doesn't exists anymore
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
72 |
ordermethod='fetch_order') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
73 |
self.pagination(self._cw, rset, w=self.w) |
0 | 74 |
return rset.entities() |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
75 |
super(AddRelationView, self).unrelated_entities(self) |