14 |
14 |
15 from cubicweb.entities import AnyEntity, fetch_config |
15 from cubicweb.entities import AnyEntity, fetch_config |
16 |
16 |
17 |
17 |
18 class CWEType(AnyEntity): |
18 class CWEType(AnyEntity): |
19 id = 'CWEType' |
19 __regid__ = 'CWEType' |
20 fetch_attrs, fetch_order = fetch_config(['name']) |
20 fetch_attrs, fetch_order = fetch_config(['name']) |
21 |
21 |
22 def dc_title(self): |
22 def dc_title(self): |
23 return u'%s (%s)' % (self.name, self.req._(self.name)) |
23 return u'%s (%s)' % (self.name, self._cw._(self.name)) |
24 |
24 |
25 def dc_long_title(self): |
25 def dc_long_title(self): |
26 stereotypes = [] |
26 stereotypes = [] |
27 _ = self.req._ |
27 _ = self._cw._ |
28 if self.final: |
28 if self.final: |
29 stereotypes.append(_('final')) |
29 stereotypes.append(_('final')) |
30 if stereotypes: |
30 if stereotypes: |
31 return u'%s <<%s>>' % (self.dc_title(), ', '.join(stereotypes)) |
31 return u'%s <<%s>>' % (self.dc_title(), ', '.join(stereotypes)) |
32 return self.dc_title() |
32 return self.dc_title() |
35 """XXX goa specific""" |
35 """XXX goa specific""" |
36 return self.get('name') |
36 return self.get('name') |
37 |
37 |
38 |
38 |
39 class CWRType(AnyEntity): |
39 class CWRType(AnyEntity): |
40 id = 'CWRType' |
40 __regid__ = 'CWRType' |
41 fetch_attrs, fetch_order = fetch_config(['name']) |
41 fetch_attrs, fetch_order = fetch_config(['name']) |
42 |
42 |
43 def dc_title(self): |
43 def dc_title(self): |
44 return u'%s (%s)' % (self.name, self.req._(self.name)) |
44 return u'%s (%s)' % (self.name, self._cw._(self.name)) |
45 |
45 |
46 def dc_long_title(self): |
46 def dc_long_title(self): |
47 stereotypes = [] |
47 stereotypes = [] |
48 _ = self.req._ |
48 _ = self._cw._ |
49 if self.symetric: |
49 if self.symmetric: |
50 stereotypes.append(_('symetric')) |
50 stereotypes.append(_('symmetric')) |
51 if self.inlined: |
51 if self.inlined: |
52 stereotypes.append(_('inlined')) |
52 stereotypes.append(_('inlined')) |
53 if self.final: |
53 if self.final: |
54 stereotypes.append(_('final')) |
54 stereotypes.append(_('final')) |
55 if stereotypes: |
55 if stereotypes: |
56 return u'%s <<%s>>' % (self.dc_title(), ', '.join(stereotypes)) |
56 return u'%s <<%s>>' % (self.dc_title(), ', '.join(stereotypes)) |
57 return self.dc_title() |
57 return self.dc_title() |
58 |
58 |
59 def inlined_changed(self, inlined): |
59 def check_inlined_allowed(self): |
60 """check inlining is necessary and possible: |
60 """check inlining is possible, raise ValidationError if not possible |
61 |
61 """ |
62 * return False if nothing has changed |
62 # don't use the persistent schema, we may miss cardinality changes |
63 * raise ValidationError if inlining is'nt possible |
63 # in the same transaction |
64 * eventually return True |
64 for rdef in self.reverse_relation_type: |
65 """ |
65 card = rdef.cardinality[0] |
66 rschema = self.schema.rschema(self.name) |
66 if not card in '?1': |
67 if inlined == rschema.inlined: |
67 rtype = self.name |
68 return False |
68 stype = rdef.stype |
69 if inlined: |
69 otype = rdef.otype |
70 # don't use the persistent schema, we may miss cardinality changes |
70 msg = self._cw._("can't set inlined=%(inlined)s, " |
71 # in the same transaction |
71 "%(stype)s %(rtype)s %(otype)s " |
72 for rdef in self.reverse_relation_type: |
72 "has cardinality=%(card)s") |
73 card = rdef.cardinality[0] |
73 raise ValidationError(self.eid, {'inlined': msg % locals()}) |
74 if not card in '?1': |
|
75 rtype = self.name |
|
76 stype = rdef.stype |
|
77 otype = rdef.otype |
|
78 msg = self.req._("can't set inlined=%(inlined)s, " |
|
79 "%(stype)s %(rtype)s %(otype)s " |
|
80 "has cardinality=%(card)s") |
|
81 raise ValidationError(self.eid, {'inlined': msg % locals()}) |
|
82 return True |
|
83 |
74 |
84 def db_key_name(self): |
75 def db_key_name(self): |
85 """XXX goa specific""" |
76 """XXX goa specific""" |
86 return self.get('name') |
77 return self.get('name') |
87 |
78 |
88 |
79 |
89 class CWRelation(AnyEntity): |
80 class CWRelation(AnyEntity): |
90 id = 'CWRelation' |
81 __regid__ = 'CWRelation' |
91 fetch_attrs = fetch_config(['cardinality'])[0] |
82 fetch_attrs = fetch_config(['cardinality'])[0] |
92 |
83 |
93 def dc_title(self): |
84 def dc_title(self): |
94 return u'%s %s %s' % ( |
85 return u'%s %s %s' % ( |
95 self.from_entity[0].name, |
86 self.from_entity[0].name, |
196 return self.expression_of.rest_path(), {} |
187 return self.expression_of.rest_path(), {} |
197 return super(RQLExpression, self).after_deletion_path() |
188 return super(RQLExpression, self).after_deletion_path() |
198 |
189 |
199 |
190 |
200 class CWPermission(AnyEntity): |
191 class CWPermission(AnyEntity): |
201 id = 'CWPermission' |
192 __regid__ = 'CWPermission' |
202 fetch_attrs, fetch_order = fetch_config(['name', 'label']) |
193 fetch_attrs, fetch_order = fetch_config(['name', 'label']) |
203 |
194 |
204 def dc_title(self): |
195 def dc_title(self): |
205 if self.label: |
196 if self.label: |
206 return '%s (%s)' % (self.req._(self.name), self.label) |
197 return '%s (%s)' % (self._cw._(self.name), self.label) |
207 return self.req._(self.name) |
198 return self._cw._(self.name) |
208 |
199 |
209 def after_deletion_path(self): |
200 def after_deletion_path(self): |
210 """return (path, parameters) which should be used as redirect |
201 """return (path, parameters) which should be used as redirect |
211 information when this entity is being deleted |
202 information when this entity is being deleted |
212 """ |
203 """ |