|
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) |
|
23 from yams.constraints import SizeConstraint, UniqueConstraint |
|
24 from cubicweb.schema import (WorkflowableEntityType, RQLConstraint, |
|
25 RQLVocabularyConstraint, |
|
26 ERQLExpression, RRQLExpression) |
|
27 |
|
28 class Affaire(EntityType): |
|
29 __permissions__ = { |
|
30 'read': ('managers', 'users', 'guests'), |
|
31 'add': ('managers', ERQLExpression('X concerne S, S owned_by U')), |
|
32 'update': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')), |
|
33 'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')), |
|
34 } |
|
35 |
|
36 ref = String(fulltextindexed=True, indexed=True, |
|
37 constraints=[SizeConstraint(16)]) |
|
38 sujet = String(fulltextindexed=True, |
|
39 constraints=[SizeConstraint(256)]) |
|
40 concerne = SubjectRelation('Societe') |
|
41 opt_attr = Bytes() |
|
42 |
|
43 class Societe(WorkflowableEntityType): |
|
44 __permissions__ = { |
|
45 'read': ('managers', 'users', 'guests'), |
|
46 'update': ('managers', 'owners'), |
|
47 'delete': ('managers', 'owners'), |
|
48 'add': ('managers', 'users',) |
|
49 } |
|
50 nom = String(maxsize=64, fulltextindexed=True) |
|
51 web = String(maxsize=128) |
|
52 tel = Int() |
|
53 fax = Int() |
|
54 rncs = String(maxsize=128) |
|
55 ad1 = String(maxsize=128) |
|
56 ad2 = String(maxsize=128) |
|
57 ad3 = String(maxsize=128) |
|
58 cp = String(maxsize=12) |
|
59 ville= String(maxsize=32) |
|
60 |
|
61 # Division and SubDivision are gone |
|
62 |
|
63 # New |
|
64 class Para(EntityType): |
|
65 para = String(maxsize=512) |
|
66 newattr = String() |
|
67 newinlined = SubjectRelation('Affaire', cardinality='?*', inlined=True) |
|
68 newnotinlined = SubjectRelation('Affaire', cardinality='?*') |
|
69 |
|
70 class Note(Para): |
|
71 __specializes_schema__ = True |
|
72 |
|
73 __permissions__ = {'read': ('managers', 'users', 'guests',), |
|
74 'update': ('managers', 'owners',), |
|
75 'delete': ('managers', ), |
|
76 'add': ('managers', |
|
77 ERQLExpression('X ecrit_part PE, U in_group G, ' |
|
78 'PE require_permission P, P name "add_note", ' |
|
79 'P require_group G'),)} |
|
80 |
|
81 whatever = Int(default=0) # keep it before `date` for unittest_migraction.test_add_attribute_int |
|
82 yesno = Boolean(default=False) |
|
83 date = Datetime() |
|
84 type = String(maxsize=1) |
|
85 unique_id = String(maxsize=1, required=True, unique=True) |
|
86 mydate = Date(default='TODAY') |
|
87 oldstyledefaultdate = Date(default='2013/01/01') |
|
88 newstyledefaultdate = Date(default=dt.date(2013, 1, 1)) |
|
89 shortpara = String(maxsize=64, default='hop') |
|
90 ecrit_par = SubjectRelation('Personne', constraints=[RQLConstraint('S concerne A, O concerne A')]) |
|
91 attachment = SubjectRelation('File') |
|
92 |
|
93 |
|
94 class Frozable(EntityType): |
|
95 __permissions__ = { |
|
96 'read': ('managers', 'users'), |
|
97 'add': ('managers', 'users'), |
|
98 'update': ('managers', ERQLExpression('X frozen False'),), |
|
99 'delete': ('managers', ERQLExpression('X frozen False'),) |
|
100 } |
|
101 name = String() |
|
102 frozen = Boolean(default=False, |
|
103 __permissions__ = { |
|
104 'read': ('managers', 'users'), |
|
105 'add': ('managers', 'users'), |
|
106 'update': ('managers', 'owners') |
|
107 }) |
|
108 |
|
109 |
|
110 class Personne(EntityType): |
|
111 __unique_together__ = [('nom', 'prenom', 'datenaiss')] |
|
112 nom = String(fulltextindexed=True, required=True, maxsize=64) |
|
113 prenom = String(fulltextindexed=True, maxsize=64) |
|
114 civility = String(maxsize=1, default='M', fulltextindexed=True) |
|
115 promo = String(vocabulary=('bon','pasbon')) |
|
116 titre = String(fulltextindexed=True, maxsize=128) |
|
117 adel = String(maxsize=128) |
|
118 ass = String(maxsize=128) |
|
119 web = String(maxsize=128) |
|
120 tel = Int() |
|
121 fax = Int() |
|
122 datenaiss = Datetime() |
|
123 test = Boolean() |
|
124 |
|
125 travaille = SubjectRelation('Societe') |
|
126 concerne = SubjectRelation('Affaire') |
|
127 concerne2 = SubjectRelation(('Affaire', 'Note'), cardinality='1*') |
|
128 connait = SubjectRelation('Personne', symmetric=True) |
|
129 |
|
130 class concerne(RelationType): |
|
131 __permissions__ = { |
|
132 'read': ('managers', 'users', 'guests'), |
|
133 'add': ('managers', RRQLExpression('U has_update_permission S')), |
|
134 'delete': ('managers', RRQLExpression('O owned_by U')), |
|
135 } |
|
136 |
|
137 # `Old` entity type is gonce |
|
138 # `comments` is gone |
|
139 # `fiche` is gone |
|
140 # `multisource_*` rdefs are gone |
|
141 # `see_also_*` rdefs are gone |
|
142 |
|
143 class evaluee(RelationDefinition): |
|
144 subject = ('Personne', 'CWUser', 'Societe') |
|
145 object = ('Note') |
|
146 constraints = [RQLVocabularyConstraint('S owned_by U')] |
|
147 |
|
148 class ecrit_par(RelationType): |
|
149 __permissions__ = {'read': ('managers', 'users', 'guests',), |
|
150 'delete': ('managers', ), |
|
151 'add': ('managers', |
|
152 RRQLExpression('O require_permission P, P name "add_note", ' |
|
153 'U in_group G, P require_group G'),) |
|
154 } |
|
155 inlined = True |
|
156 cardinality = '?*' |
|
157 |
|
158 # `copain` rdef is gone |
|
159 # `tags` rdef is gone |
|
160 # `filed_under` rdef is gone |
|
161 # `require_permission` rdef is gone |
|
162 # `require_state` rdef is gone |
|
163 # `personne_composite` rdef is gone |
|
164 # `personne_inlined` rdef is gone |
|
165 # `login_user` rdef is gone |
|
166 # `ambiguous_inlined` rdef is gone |
|
167 |
|
168 class Folder(EntityType): |
|
169 """folders are used to classify entities. They may be defined as a tree. |
|
170 """ |
|
171 name = String(required=True, indexed=True, internationalizable=True, |
|
172 maxsize=64) |
|
173 description = RichString(fulltextindexed=True) |
|
174 filed_under = SubjectRelation('Folder', description=_('parent folder')) |
|
175 |
|
176 |
|
177 # New |
|
178 class Text(Para): |
|
179 __specializes_schema__ = True |
|
180 summary = String(maxsize=512) |
|
181 |
|
182 |
|
183 # New |
|
184 class Folder2(EntityType): |
|
185 """folders are used to classify entities. They may be defined as a tree. |
|
186 When you include the Folder entity, all application specific entities |
|
187 may then be classified using the "filed_under" relation. |
|
188 """ |
|
189 name = String(required=True, indexed=True, internationalizable=True, |
|
190 constraints=[UniqueConstraint(), SizeConstraint(64)]) |
|
191 description = RichString(fulltextindexed=True) |
|
192 |
|
193 # New |
|
194 class filed_under2(RelationDefinition): |
|
195 subject ='*' |
|
196 object = 'Folder2' |
|
197 |
|
198 |
|
199 # New |
|
200 class New(EntityType): |
|
201 new_name = String() |
|
202 |
|
203 # New |
|
204 class same_as(RelationDefinition): |
|
205 subject = ('Societe',) |
|
206 object = 'ExternalUri' |