author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Sat, 09 Oct 2010 00:05:52 +0200 | |
changeset 6427 | c8a5ac2d1eaa |
parent 5556 | 9ab2b4c74baf |
child 6578 | 7abd07ff0471 |
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
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:
5030
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
18 |
"""schema definition related entities""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
22 |
import re |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
23 |
from socket import gethostname |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
24 |
|
0 | 25 |
from logilab.common.decorators import cached |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
26 |
from logilab.common.textutils import text_to_dict |
0 | 27 |
|
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4839
diff
changeset
|
28 |
from yams.schema import role_name |
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4839
diff
changeset
|
29 |
|
0 | 30 |
from cubicweb import ValidationError |
31 |
from cubicweb.schema import ERQLExpression, RRQLExpression |
|
32 |
||
33 |
from cubicweb.entities import AnyEntity, fetch_config |
|
34 |
||
35 |
||
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
36 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
37 |
class CWSource(AnyEntity): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
38 |
__regid__ = 'CWSource' |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
39 |
fetch_attrs, fetch_order = fetch_config(['name', 'type']) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
40 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
41 |
@property |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
42 |
def dictconfig(self): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
43 |
return self.config and text_to_dict(self.config) or {} |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
44 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
45 |
@property |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
46 |
def host_config(self): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
47 |
dictconfig = self.dictconfig |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
48 |
host = gethostname() |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
49 |
for hostcfg in self.host_configs: |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
50 |
if hostcfg.match(hostname): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
51 |
dictconfig.update(hostcfg.dictconfig) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
52 |
return dictconfig |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
53 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
54 |
@property |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
55 |
def host_configs(self): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
56 |
return self.reverse_cw_host_config_of |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
57 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
58 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
59 |
class CWSourceHostConfig(AnyEntity): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
60 |
__regid__ = 'CWSourceHostConfig' |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
61 |
fetch_attrs, fetch_order = fetch_config(['match_host', 'config']) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
62 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
63 |
@property |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
64 |
def dictconfig(self): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
65 |
return self.config and text_to_dict(self.config) or {} |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
66 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
67 |
def match(self, hostname): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
68 |
return re.match(self.match_host, hostname) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
69 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
70 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1154
diff
changeset
|
71 |
class CWEType(AnyEntity): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3353
diff
changeset
|
72 |
__regid__ = 'CWEType' |
0 | 73 |
fetch_attrs, fetch_order = fetch_config(['name']) |
1154 | 74 |
|
0 | 75 |
def dc_title(self): |
3432
12fe502e5044
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3377
diff
changeset
|
76 |
return u'%s (%s)' % (self.name, self._cw._(self.name)) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
77 |
|
0 | 78 |
def dc_long_title(self): |
79 |
stereotypes = [] |
|
3432
12fe502e5044
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3377
diff
changeset
|
80 |
_ = self._cw._ |
0 | 81 |
if self.final: |
82 |
stereotypes.append(_('final')) |
|
83 |
if stereotypes: |
|
84 |
return u'%s <<%s>>' % (self.dc_title(), ', '.join(stereotypes)) |
|
85 |
return self.dc_title() |
|
86 |
||
87 |
def db_key_name(self): |
|
88 |
"""XXX goa specific""" |
|
89 |
return self.get('name') |
|
90 |
||
91 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1154
diff
changeset
|
92 |
class CWRType(AnyEntity): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3353
diff
changeset
|
93 |
__regid__ = 'CWRType' |
0 | 94 |
fetch_attrs, fetch_order = fetch_config(['name']) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
95 |
|
0 | 96 |
def dc_title(self): |
3432
12fe502e5044
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3377
diff
changeset
|
97 |
return u'%s (%s)' % (self.name, self._cw._(self.name)) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
98 |
|
0 | 99 |
def dc_long_title(self): |
100 |
stereotypes = [] |
|
3432
12fe502e5044
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3377
diff
changeset
|
101 |
_ = self._cw._ |
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
102 |
if self.symmetric: |
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
103 |
stereotypes.append(_('symmetric')) |
0 | 104 |
if self.inlined: |
105 |
stereotypes.append(_('inlined')) |
|
106 |
if self.final: |
|
107 |
stereotypes.append(_('final')) |
|
108 |
if stereotypes: |
|
109 |
return u'%s <<%s>>' % (self.dc_title(), ', '.join(stereotypes)) |
|
110 |
return self.dc_title() |
|
111 |
||
4839
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
112 |
def check_inlined_allowed(self): |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
113 |
"""check inlining is possible, raise ValidationError if not possible |
0 | 114 |
""" |
4839
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
115 |
# don't use the persistent schema, we may miss cardinality changes |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
116 |
# in the same transaction |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
117 |
for rdef in self.reverse_relation_type: |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
118 |
card = rdef.cardinality[0] |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
119 |
if not card in '?1': |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4839
diff
changeset
|
120 |
qname = role_name('inlined', 'subject') |
4839
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
121 |
rtype = self.name |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
122 |
stype = rdef.stype |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
123 |
otype = rdef.otype |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
124 |
msg = self._cw._("can't set inlined=%(inlined)s, " |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
125 |
"%(stype)s %(rtype)s %(otype)s " |
f482dbdf2f8c
[schema hooks] properly check for changes of schema properties avoid useless costly operation (such as full-text reindexing all entities of a type). Refactor inlined handling and fix a bug trying to reindex a final entity type on the way.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
126 |
"has cardinality=%(card)s") |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4839
diff
changeset
|
127 |
raise ValidationError(self.eid, {qname: msg % locals()}) |
0 | 128 |
|
129 |
def db_key_name(self): |
|
130 |
"""XXX goa specific""" |
|
131 |
return self.get('name') |
|
132 |
||
133 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1154
diff
changeset
|
134 |
class CWRelation(AnyEntity): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3353
diff
changeset
|
135 |
__regid__ = 'CWRelation' |
0 | 136 |
fetch_attrs = fetch_config(['cardinality'])[0] |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
137 |
|
0 | 138 |
def dc_title(self): |
139 |
return u'%s %s %s' % ( |
|
140 |
self.from_entity[0].name, |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
141 |
self.relation_type[0].name, |
0 | 142 |
self.to_entity[0].name) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
143 |
|
0 | 144 |
def dc_long_title(self): |
145 |
card = self.cardinality |
|
146 |
scard, ocard = u'', u'' |
|
147 |
if card[0] != '1': |
|
148 |
scard = '[%s]' % card[0] |
|
149 |
if card[1] != '1': |
|
150 |
ocard = '[%s]' % card[1] |
|
151 |
return u'%s %s%s%s %s' % ( |
|
152 |
self.from_entity[0].name, |
|
153 |
scard, self.relation_type[0].name, ocard, |
|
154 |
self.to_entity[0].name) |
|
155 |
||
2594
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
156 |
@property |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
157 |
def rtype(self): |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
158 |
return self.relation_type[0] |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
159 |
|
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
160 |
@property |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
161 |
def stype(self): |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
162 |
return self.from_entity[0] |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
163 |
|
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
164 |
@property |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
165 |
def otype(self): |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
166 |
return self.to_entity[0] |
92aad5e18405
[R schemaobjs] property accessors for CWRelation/CWAttribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2299
diff
changeset
|
167 |
|
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5224
diff
changeset
|
168 |
def yams_schema(self): |
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5224
diff
changeset
|
169 |
rschema = self._cw.vreg.schema.rschema(self.rtype.name) |
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5224
diff
changeset
|
170 |
return rschema.rdefs[(self.stype.name, self.otype.name)] |
0 | 171 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
172 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1154
diff
changeset
|
173 |
class CWAttribute(CWRelation): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3353
diff
changeset
|
174 |
__regid__ = 'CWAttribute' |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
175 |
|
0 | 176 |
def dc_long_title(self): |
177 |
card = self.cardinality |
|
178 |
scard = u'' |
|
179 |
if card[0] == '1': |
|
180 |
scard = '+' |
|
181 |
return u'%s %s%s %s' % ( |
|
182 |
self.from_entity[0].name, |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
183 |
scard, self.relation_type[0].name, |
0 | 184 |
self.to_entity[0].name) |
185 |
||
186 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1154
diff
changeset
|
187 |
class CWConstraint(AnyEntity): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3353
diff
changeset
|
188 |
__regid__ = 'CWConstraint' |
0 | 189 |
fetch_attrs, fetch_order = fetch_config(['value']) |
190 |
||
191 |
def dc_title(self): |
|
192 |
return '%s(%s)' % (self.cstrtype[0].name, self.value or u'') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
193 |
|
0 | 194 |
@property |
195 |
def type(self): |
|
196 |
return self.cstrtype[0].name |
|
197 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
198 |
|
0 | 199 |
class RQLExpression(AnyEntity): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3353
diff
changeset
|
200 |
__regid__ = 'RQLExpression' |
0 | 201 |
fetch_attrs, fetch_order = fetch_config(['exprtype', 'mainvars', 'expression']) |
202 |
||
203 |
def dc_title(self): |
|
5224
34e669b6fd95
[mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
204 |
return self.expression or u'' |
34e669b6fd95
[mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
205 |
|
34e669b6fd95
[mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
206 |
def dc_long_title(self): |
0 | 207 |
return '%s(%s)' % (self.exprtype, self.expression or u'') |
208 |
||
209 |
@property |
|
210 |
def expression_of(self): |
|
211 |
for rel in ('read_permission', 'add_permission', 'delete_permission', |
|
212 |
'update_permission', 'condition'): |
|
213 |
values = getattr(self, 'reverse_%s' % rel) |
|
214 |
if values: |
|
215 |
return values[0] |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
216 |
|
0 | 217 |
@cached |
218 |
def _rqlexpr(self): |
|
219 |
if self.exprtype == 'ERQLExpression': |
|
220 |
return ERQLExpression(self.expression, self.mainvars, self.eid) |
|
221 |
#if self.exprtype == 'RRQLExpression': |
|
222 |
return RRQLExpression(self.expression, self.mainvars, self.eid) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
223 |
|
0 | 224 |
def check_expression(self, *args, **kwargs): |
225 |
return self._rqlexpr().check(*args, **kwargs) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
226 |
|
0 | 227 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1154
diff
changeset
|
228 |
class CWPermission(AnyEntity): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3353
diff
changeset
|
229 |
__regid__ = 'CWPermission' |
0 | 230 |
fetch_attrs, fetch_order = fetch_config(['name', 'label']) |
231 |
||
232 |
def dc_title(self): |
|
233 |
if self.label: |
|
3432
12fe502e5044
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3377
diff
changeset
|
234 |
return '%s (%s)' % (self._cw._(self.name), self.label) |
12fe502e5044
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3377
diff
changeset
|
235 |
return self._cw._(self.name) |