|
1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """cw.server.migraction test""" |
|
19 import datetime as dt |
|
20 from yams.buildobjs import (EntityType, RelationType, RelationDefinition, |
|
21 SubjectRelation, Bytes, |
|
22 RichString, String, Int, Boolean, Datetime, Date, Float) |
|
23 from yams.constraints import SizeConstraint, UniqueConstraint |
|
24 from cubicweb import _ |
|
25 from cubicweb.schema import (WorkflowableEntityType, RQLConstraint, |
|
26 RQLVocabularyConstraint, |
|
27 ERQLExpression, RRQLExpression) |
|
28 |
|
29 class Affaire(EntityType): |
|
30 __permissions__ = { |
|
31 'read': ('managers', 'users', 'guests'), |
|
32 'add': ('managers', ERQLExpression('X concerne S, S owned_by U')), |
|
33 'update': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')), |
|
34 'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')), |
|
35 } |
|
36 |
|
37 ref = String(fulltextindexed=True, indexed=True, |
|
38 constraints=[SizeConstraint(16)]) |
|
39 sujet = String(fulltextindexed=True, |
|
40 constraints=[SizeConstraint(256)]) |
|
41 concerne = SubjectRelation('Societe') |
|
42 opt_attr = Bytes() |
|
43 |
|
44 class Societe(WorkflowableEntityType): |
|
45 __permissions__ = { |
|
46 'read': ('managers', 'users', 'guests'), |
|
47 'update': ('managers', 'owners'), |
|
48 'delete': ('managers', 'owners'), |
|
49 'add': ('managers', 'users',) |
|
50 } |
|
51 nom = String(maxsize=64, fulltextindexed=True) |
|
52 web = String(maxsize=128) |
|
53 tel = Float() |
|
54 fax = Int() |
|
55 rncs = String(maxsize=128) |
|
56 ad1 = String(maxsize=128) |
|
57 ad2 = String(maxsize=128) |
|
58 ad3 = String(maxsize=128) |
|
59 cp = String(maxsize=12) |
|
60 ville= String(maxsize=32) |
|
61 |
|
62 # Division and SubDivision are gone |
|
63 |
|
64 # New |
|
65 class Para(EntityType): |
|
66 para = String(maxsize=512) |
|
67 newattr = String() |
|
68 newinlined = SubjectRelation('Affaire', cardinality='?*', inlined=True) |
|
69 newnotinlined = SubjectRelation('Affaire', cardinality='?*') |
|
70 |
|
71 class Note(Para): |
|
72 __specializes_schema__ = True |
|
73 |
|
74 __permissions__ = {'read': ('managers', 'users', 'guests',), |
|
75 'update': ('managers', 'owners',), |
|
76 'delete': ('managers', ), |
|
77 'add': ('managers', |
|
78 ERQLExpression('X ecrit_part PE, U in_group G, ' |
|
79 'PE require_permission P, P name "add_note", ' |
|
80 'P require_group G'),)} |
|
81 |
|
82 whatever = Int(default=0) # keep it before `date` for unittest_migraction.test_add_attribute_int |
|
83 yesno = Boolean(default=False) |
|
84 date = Datetime() |
|
85 type = String(maxsize=1) |
|
86 unique_id = String(maxsize=1, required=True, unique=True) |
|
87 mydate = Date(default='TODAY') |
|
88 oldstyledefaultdate = Date(default='2013/01/01') |
|
89 newstyledefaultdate = Date(default=dt.date(2013, 1, 1)) |
|
90 shortpara = String(maxsize=64, default='hop') |
|
91 ecrit_par = SubjectRelation('Personne', constraints=[RQLConstraint('S concerne A, O concerne A')]) |
|
92 attachment = SubjectRelation('File') |
|
93 |
|
94 |
|
95 class Frozable(EntityType): |
|
96 __permissions__ = { |
|
97 'read': ('managers', 'users'), |
|
98 'add': ('managers', 'users'), |
|
99 'update': ('managers', ERQLExpression('X frozen False'),), |
|
100 'delete': ('managers', ERQLExpression('X frozen False'),) |
|
101 } |
|
102 name = String() |
|
103 frozen = Boolean(default=False, |
|
104 __permissions__ = { |
|
105 'read': ('managers', 'users'), |
|
106 'add': ('managers', 'users'), |
|
107 'update': ('managers', 'owners') |
|
108 }) |
|
109 |
|
110 |
|
111 class Personne(EntityType): |
|
112 __permissions__ = { |
|
113 'read': ('managers', 'users'), # 'guests' was removed |
|
114 'add': ('managers', 'users'), |
|
115 'update': ('managers', 'owners'), |
|
116 'delete': ('managers', 'owners') |
|
117 } |
|
118 __unique_together__ = [('nom', 'prenom', 'datenaiss')] |
|
119 nom = String(fulltextindexed=True, required=True, maxsize=64) |
|
120 prenom = String(fulltextindexed=True, maxsize=64) |
|
121 civility = String(maxsize=1, default='M', fulltextindexed=True) |
|
122 promo = String(vocabulary=('bon','pasbon')) |
|
123 titre = String(fulltextindexed=True, maxsize=128) |
|
124 adel = String(maxsize=128) |
|
125 ass = String(maxsize=128) |
|
126 web = String(maxsize=128) |
|
127 tel = Int() |
|
128 fax = Int() |
|
129 datenaiss = Datetime() |
|
130 test = Boolean() |
|
131 |
|
132 travaille = SubjectRelation('Societe') |
|
133 concerne = SubjectRelation('Affaire') |
|
134 concerne2 = SubjectRelation(('Affaire', 'Note'), cardinality='1*') |
|
135 connait = SubjectRelation('Personne', symmetric=True) |
|
136 |
|
137 class concerne(RelationType): |
|
138 __permissions__ = { |
|
139 'read': ('managers', 'users', 'guests'), |
|
140 'add': ('managers', RRQLExpression('U has_update_permission S')), |
|
141 'delete': ('managers', RRQLExpression('O owned_by U')), |
|
142 } |
|
143 |
|
144 # `Old` entity type is gonce |
|
145 # `comments` is gone |
|
146 # `fiche` is gone |
|
147 # `multisource_*` rdefs are gone |
|
148 # `see_also_*` rdefs are gone |
|
149 |
|
150 class evaluee(RelationDefinition): |
|
151 subject = ('Personne', 'CWUser', 'Societe') |
|
152 object = ('Note') |
|
153 constraints = [RQLVocabularyConstraint('S owned_by U')] |
|
154 |
|
155 class ecrit_par(RelationType): |
|
156 __permissions__ = {'read': ('managers', 'users', 'guests',), |
|
157 'delete': ('managers', ), |
|
158 'add': ('managers', |
|
159 RRQLExpression('O require_permission P, P name "add_note", ' |
|
160 'U in_group G, P require_group G'),) |
|
161 } |
|
162 inlined = True |
|
163 cardinality = '?*' |
|
164 |
|
165 # `copain` rdef is gone |
|
166 # `tags` rdef is gone |
|
167 # `filed_under` rdef is gone |
|
168 # `require_permission` rdef is gone |
|
169 # `require_state` rdef is gone |
|
170 # `personne_composite` rdef is gone |
|
171 # `personne_inlined` rdef is gone |
|
172 # `login_user` rdef is gone |
|
173 # `ambiguous_inlined` rdef is gone |
|
174 |
|
175 class Folder(EntityType): |
|
176 """folders are used to classify entities. They may be defined as a tree. |
|
177 """ |
|
178 name = String(required=True, indexed=True, internationalizable=True, |
|
179 maxsize=64) |
|
180 description = RichString(fulltextindexed=True) |
|
181 filed_under = SubjectRelation('Folder', description=_('parent folder')) |
|
182 |
|
183 |
|
184 # New |
|
185 class Text(Para): |
|
186 __specializes_schema__ = True |
|
187 summary = String(maxsize=512) |
|
188 |
|
189 |
|
190 # New |
|
191 class Folder2(EntityType): |
|
192 """folders are used to classify entities. They may be defined as a tree. |
|
193 When you include the Folder entity, all application specific entities |
|
194 may then be classified using the "filed_under" relation. |
|
195 """ |
|
196 name = String(required=True, indexed=True, internationalizable=True, |
|
197 constraints=[UniqueConstraint(), SizeConstraint(64)]) |
|
198 description = RichString(fulltextindexed=True) |
|
199 |
|
200 # New |
|
201 class filed_under2(RelationDefinition): |
|
202 subject ='*' |
|
203 object = 'Folder2' |
|
204 |
|
205 |
|
206 # New |
|
207 class New(EntityType): |
|
208 new_name = String() |
|
209 |
|
210 # New |
|
211 class same_as(RelationDefinition): |
|
212 subject = ('Societe',) |
|
213 object = 'ExternalUri' |