author | sylvain.thenault@logilab.fr |
Wed, 22 Apr 2009 16:50:46 +0200 | |
branch | tls-sprint |
changeset 1419 | 7ff24154351d |
parent 1398 | 5fe84a5f7035 |
child 1451 | 982e8616d9a2 |
permissions | -rw-r--r-- |
0 | 1 |
"""core CubicWeb schema necessary for bootstrapping the actual application's schema |
2 |
||
3 |
:organization: Logilab |
|
628
3a6f28a1ea21
extract workflow related schema definitions in its own file
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
627
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
||
8 |
from cubicweb.schema import format_constraint |
|
9 |
||
10 |
||
11 |
# not restricted since as "is" is handled as other relations, guests need |
|
12 |
# access to this |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
13 |
class CWEType(MetaEntityType): |
0 | 14 |
"""define an entity type, used to build the application schema""" |
15 |
name = String(required=True, indexed=True, internationalizable=True, |
|
16 |
unique=True, maxsize=64) |
|
627
36ade1128af7
use RichString wherever possible in the stdlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
17 |
description = RichString(internationalizable=True, |
36ade1128af7
use RichString wherever possible in the stdlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
18 |
description=_('semantic description of this entity type')) |
0 | 19 |
meta = Boolean(description=_('is it an application entity type or not ?')) |
20 |
# necessary to filter using RQL |
|
21 |
final = Boolean(description=_('automatic')) |
|
22 |
||
23 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
24 |
class CWRType(MetaEntityType): |
0 | 25 |
"""define a relation type, used to build the application schema""" |
26 |
name = String(required=True, indexed=True, internationalizable=True, |
|
27 |
unique=True, maxsize=64) |
|
28 |
description_format = String(meta=True, internationalizable=True, maxsize=50, |
|
29 |
default='text/plain', constraints=[format_constraint]) |
|
30 |
description = String(internationalizable=True, |
|
31 |
description=_('semantic description of this relation type')) |
|
32 |
meta = Boolean(description=_('is it an application relation type or not ?')) |
|
33 |
symetric = Boolean(description=_('is this relation equivalent in both direction ?')) |
|
34 |
inlined = Boolean(description=_('is this relation physically inlined? you should know what you\'re doing if you are changing this!')) |
|
35 |
fulltext_container = String(description=_('if full text content of subject/object entity ' |
|
36 |
'should be added to other side entity (the container).'), |
|
37 |
vocabulary=('', _('subject'), _('object')), |
|
38 |
maxsize=8, default=None) |
|
39 |
final = Boolean(description=_('automatic')) |
|
40 |
||
41 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
42 |
class CWAttribute(MetaEntityType): |
0 | 43 |
"""define a final relation: link a final relation type from a non final |
44 |
entity to a final entity type. |
|
45 |
||
46 |
used to build the application schema |
|
47 |
""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
48 |
relation_type = SubjectRelation('CWRType', cardinality='1*', |
0 | 49 |
constraints=[RQLConstraint('O final TRUE')], |
50 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
51 |
from_entity = SubjectRelation('CWEType', cardinality='1*', |
0 | 52 |
constraints=[RQLConstraint('O final FALSE')], |
53 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
54 |
to_entity = SubjectRelation('CWEType', cardinality='1*', |
0 | 55 |
constraints=[RQLConstraint('O final TRUE')], |
56 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
57 |
constrained_by = SubjectRelation('CWConstraint', cardinality='*1', composite='subject') |
0 | 58 |
|
59 |
cardinality = String(maxsize=2, internationalizable=True, |
|
60 |
vocabulary=[_('?1'), _('11'), _('??'), _('1?')], |
|
61 |
description=_('subject/object cardinality')) |
|
62 |
ordernum = Int(description=('control subject entity\'s relations order'), default=0) |
|
63 |
||
64 |
indexed = Boolean(description=_('create an index for quick search on this attribute')) |
|
65 |
fulltextindexed = Boolean(description=_('index this attribute\'s value in the plain text index')) |
|
66 |
internationalizable = Boolean(description=_('is this attribute\'s value translatable')) |
|
67 |
defaultval = String(maxsize=256) |
|
68 |
||
69 |
description_format = String(meta=True, internationalizable=True, maxsize=50, |
|
70 |
default='text/plain', constraints=[format_constraint]) |
|
71 |
description = String(internationalizable=True, |
|
72 |
description=_('semantic description of this attribute')) |
|
73 |
||
74 |
||
75 |
CARDINALITY_VOCAB = [_('?*'), _('1*'), _('+*'), _('**'), |
|
76 |
_('?+'), _('1+'), _('++'), _('*+'), |
|
77 |
_('?1'), _('11'), _('+1'), _('*1'), |
|
78 |
_('??'), _('1?'), _('+?'), _('*?')] |
|
79 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
80 |
class CWRelation(MetaEntityType): |
0 | 81 |
"""define a non final relation: link a non final relation type from a non |
82 |
final entity to a non final entity type. |
|
83 |
||
84 |
used to build the application schema |
|
85 |
""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
86 |
relation_type = SubjectRelation('CWRType', cardinality='1*', |
0 | 87 |
constraints=[RQLConstraint('O final FALSE')], |
88 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
89 |
from_entity = SubjectRelation('CWEType', cardinality='1*', |
0 | 90 |
constraints=[RQLConstraint('O final FALSE')], |
91 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
92 |
to_entity = SubjectRelation('CWEType', cardinality='1*', |
0 | 93 |
constraints=[RQLConstraint('O final FALSE')], |
94 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
95 |
constrained_by = SubjectRelation('CWConstraint', cardinality='*1', composite='subject') |
0 | 96 |
|
97 |
cardinality = String(maxsize=2, internationalizable=True, |
|
98 |
vocabulary=CARDINALITY_VOCAB, |
|
99 |
description=_('subject/object cardinality')) |
|
100 |
ordernum = Int(description=_('control subject entity\'s relations order'), |
|
101 |
default=0) |
|
102 |
composite = String(description=_('is the subject/object entity of the relation ' |
|
103 |
'composed of the other ? This implies that when ' |
|
104 |
'the composite is deleted, composants are also ' |
|
105 |
'deleted.'), |
|
106 |
vocabulary=('', _('subject'), _('object')), |
|
107 |
maxsize=8, default=None) |
|
108 |
||
109 |
description_format = String(meta=True, internationalizable=True, maxsize=50, |
|
110 |
default='text/plain', constraints=[format_constraint]) |
|
111 |
description = String(internationalizable=True, |
|
112 |
description=_('semantic description of this relation')) |
|
113 |
||
114 |
||
115 |
# not restricted since it has to be read when checking allowed transitions |
|
116 |
class RQLExpression(MetaEntityType): |
|
117 |
"""define a rql expression used to define permissions""" |
|
118 |
exprtype = String(required=True, vocabulary=['ERQLExpression', 'RRQLExpression']) |
|
119 |
mainvars = String(maxsize=8, |
|
120 |
description=_('name of the main variables which should be ' |
|
121 |
'used in the selection if necessary (comma ' |
|
122 |
'separated)')) |
|
123 |
expression = String(required=True, |
|
124 |
description=_('restriction part of a rql query. ' |
|
125 |
'For entity rql expression, X and U are ' |
|
126 |
'predefined respectivly to the current object and to ' |
|
127 |
'the request user. For relation rql expression, ' |
|
128 |
'S, O and U are predefined respectivly to the current ' |
|
129 |
'relation\'subject, object and to ' |
|
130 |
'the request user. ')) |
|
131 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
132 |
read_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='+?', composite='subject', |
0 | 133 |
description=_('rql expression allowing to read entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
134 |
add_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='*?', composite='subject', |
0 | 135 |
description=_('rql expression allowing to add entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
136 |
delete_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='*?', composite='subject', |
0 | 137 |
description=_('rql expression allowing to delete entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
138 |
update_permission = ObjectRelation('CWEType', cardinality='*?', composite='subject', |
0 | 139 |
description=_('rql expression allowing to update entities of this type')) |
140 |
||
141 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
142 |
class CWConstraint(MetaEntityType): |
0 | 143 |
"""define a schema constraint""" |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
144 |
cstrtype = SubjectRelation('CWConstraintType', cardinality='1*') |
0 | 145 |
value = String(description=_('depends on the constraint type')) |
146 |
||
147 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
148 |
class CWConstraintType(MetaEntityType): |
0 | 149 |
"""define a schema constraint type""" |
150 |
name = String(required=True, indexed=True, internationalizable=True, |
|
151 |
unique=True, maxsize=64) |
|
152 |
||
153 |
||
154 |
# not restricted since it has to be read when checking allowed transitions |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
155 |
class CWGroup(MetaEntityType): |
0 | 156 |
"""define a CubicWeb users group""" |
157 |
name = String(required=True, indexed=True, internationalizable=True, |
|
158 |
unique=True, maxsize=64) |
|
159 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
160 |
read_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='+*', |
0 | 161 |
description=_('groups allowed to read entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
162 |
add_permission = ObjectRelation(('CWEType', 'CWRType'), |
0 | 163 |
description=_('groups allowed to add entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
164 |
delete_permission = ObjectRelation(('CWEType', 'CWRType'), |
0 | 165 |
description=_('groups allowed to delete entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
166 |
update_permission = ObjectRelation('CWEType', |
0 | 167 |
description=_('groups allowed to update entities of this type')) |
168 |
||
169 |
||
170 |
||
171 |
class relation_type(MetaRelationType): |
|
172 |
"""link a relation definition to its relation type""" |
|
173 |
inlined = True |
|
174 |
class from_entity(MetaRelationType): |
|
175 |
"""link a relation definition to its subject entity type""" |
|
176 |
inlined = True |
|
177 |
class to_entity(MetaRelationType): |
|
178 |
"""link a relation definition to its object entity type""" |
|
179 |
inlined = True |
|
180 |
class constrained_by(MetaRelationType): |
|
181 |
"""constraints applying on this relation""" |
|
182 |
||
183 |
class cstrtype(MetaRelationType): |
|
184 |
"""constraint factory""" |
|
185 |
inlined = True |
|
186 |
||
187 |
class read_permission(MetaRelationType): |
|
188 |
"""core relation giving to a group the permission to read an entity or |
|
189 |
relation type |
|
190 |
""" |
|
191 |
class add_permission(MetaRelationType): |
|
192 |
"""core relation giving to a group the permission to add an entity or |
|
193 |
relation type |
|
194 |
""" |
|
195 |
class delete_permission(MetaRelationType): |
|
196 |
"""core relation giving to a group the permission to delete an entity or |
|
197 |
relation type |
|
198 |
""" |
|
199 |
class update_permission(MetaRelationType): |
|
200 |
"""core relation giving to a group the permission to update an entity type |
|
201 |
""" |
|
202 |
||
203 |
||
204 |
class is_(MetaRelationType): |
|
205 |
"""core relation indicating the type of an entity |
|
206 |
""" |
|
207 |
name = 'is' |
|
208 |
# don't explicitly set composite here, this is handled anyway |
|
209 |
#composite = 'object' |
|
210 |
permissions = { |
|
211 |
'read': ('managers', 'users', 'guests'), |
|
212 |
'add': (), |
|
213 |
'delete': (), |
|
214 |
} |
|
215 |
cardinality = '1*' |
|
216 |
subject = '**' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
217 |
object = 'CWEType' |
0 | 218 |
|
219 |
class is_instance_of(MetaRelationType): |
|
220 |
"""core relation indicating the types (including specialized types) |
|
221 |
of an entity |
|
222 |
""" |
|
223 |
# don't explicitly set composite here, this is handled anyway |
|
224 |
#composite = 'object' |
|
225 |
permissions = { |
|
226 |
'read': ('managers', 'users', 'guests'), |
|
227 |
'add': (), |
|
228 |
'delete': (), |
|
229 |
} |
|
230 |
cardinality = '+*' |
|
231 |
subject = '**' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
232 |
object = 'CWEType' |
0 | 233 |
|
234 |
class specializes(MetaRelationType): |
|
235 |
name = 'specializes' |
|
236 |
permissions = { |
|
237 |
'read': ('managers', 'users', 'guests'), |
|
238 |
'add': ('managers',), |
|
239 |
'delete': ('managers',), |
|
240 |
} |
|
241 |
cardinality = '?*' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
242 |
subject = 'CWEType' |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
243 |
object = 'CWEType' |