Added tag cubicweb-debian-version-3.4.6-1 for changeset 52dba800ca4d
"""schema definition related entities:organization: Logilab:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses"""__docformat__="restructuredtext en"fromlogilab.common.decoratorsimportcachedfromcubicwebimportValidationErrorfromcubicweb.schemaimportERQLExpression,RRQLExpressionfromcubicweb.entitiesimportAnyEntity,fetch_configclassCWEType(AnyEntity):id='CWEType'fetch_attrs,fetch_order=fetch_config(['name'])defdc_title(self):returnu'%s (%s)'%(self.name,self.req._(self.name))defdc_long_title(self):stereotypes=[]_=self.req._ifself.final:stereotypes.append(_('final'))ifstereotypes:returnu'%s <<%s>>'%(self.dc_title(),', '.join(stereotypes))returnself.dc_title()defdb_key_name(self):"""XXX goa specific"""returnself.get('name')classCWRType(AnyEntity):id='CWRType'fetch_attrs,fetch_order=fetch_config(['name'])defdc_title(self):returnu'%s (%s)'%(self.name,self.req._(self.name))defdc_long_title(self):stereotypes=[]_=self.req._ifself.symetric:stereotypes.append(_('symetric'))ifself.inlined:stereotypes.append(_('inlined'))ifself.final:stereotypes.append(_('final'))ifstereotypes:returnu'%s <<%s>>'%(self.dc_title(),', '.join(stereotypes))returnself.dc_title()definlined_changed(self,inlined):"""check inlining is necessary and possible: * return False if nothing has changed * raise ValidationError if inlining is'nt possible * eventually return True """rtype=self.namerschema=self.schema.rschema(rtype)ifinlined==rschema.inlined:returnFalseifinlined:for(stype,otype)inrschema.iter_rdefs():card=rschema.rproperty(stype,otype,'cardinality')[0]ifnotcardin'?1':msg=self.req._("can't set inlined=%(inlined)s, ""%(stype)s%(rtype)s%(otype)s ""has cardinality=%(card)s")raiseValidationError(self.eid,{'inlined':msg%locals()})returnTruedefdb_key_name(self):"""XXX goa specific"""returnself.get('name')classCWRelation(AnyEntity):id='CWRelation'fetch_attrs=fetch_config(['cardinality'])[0]defdc_title(self):returnu'%s%s%s'%(self.from_entity[0].name,self.relation_type[0].name,self.to_entity[0].name)defdc_long_title(self):card=self.cardinalityscard,ocard=u'',u''ifcard[0]!='1':scard='[%s]'%card[0]ifcard[1]!='1':ocard='[%s]'%card[1]returnu'%s%s%s%s%s'%(self.from_entity[0].name,scard,self.relation_type[0].name,ocard,self.to_entity[0].name)defafter_deletion_path(self):"""return (path, parameters) which should be used as redirect information when this entity is being deleted """ifself.relation_type:returnself.relation_type[0].rest_path(),{}returnsuper(CWRelation,self).after_deletion_path()@propertydefrtype(self):returnself.relation_type[0]@propertydefstype(self):returnself.from_entity[0]@propertydefotype(self):returnself.to_entity[0]classCWAttribute(CWRelation):id='CWAttribute'defdc_long_title(self):card=self.cardinalityscard=u''ifcard[0]=='1':scard='+'returnu'%s%s%s%s'%(self.from_entity[0].name,scard,self.relation_type[0].name,self.to_entity[0].name)classCWConstraint(AnyEntity):id='CWConstraint'fetch_attrs,fetch_order=fetch_config(['value'])defdc_title(self):return'%s(%s)'%(self.cstrtype[0].name,self.valueoru'')defafter_deletion_path(self):"""return (path, parameters) which should be used as redirect information when this entity is being deleted """ifself.reverse_constrained_by:returnself.reverse_constrained_by[0].rest_path(),{}returnsuper(CWConstraint,self).after_deletion_path()@propertydeftype(self):returnself.cstrtype[0].nameclassRQLExpression(AnyEntity):id='RQLExpression'fetch_attrs,fetch_order=fetch_config(['exprtype','mainvars','expression'])defdc_title(self):return'%s(%s)'%(self.exprtype,self.expressionoru'')@propertydefexpression_of(self):forrelin('read_permission','add_permission','delete_permission','update_permission','condition'):values=getattr(self,'reverse_%s'%rel)ifvalues:returnvalues[0]@cacheddef_rqlexpr(self):ifself.exprtype=='ERQLExpression':returnERQLExpression(self.expression,self.mainvars,self.eid)#if self.exprtype == 'RRQLExpression':returnRRQLExpression(self.expression,self.mainvars,self.eid)defcheck_expression(self,*args,**kwargs):returnself._rqlexpr().check(*args,**kwargs)defafter_deletion_path(self):"""return (path, parameters) which should be used as redirect information when this entity is being deleted """ifself.expression_of:returnself.expression_of.rest_path(),{}returnsuper(RQLExpression,self).after_deletion_path()classCWPermission(AnyEntity):id='CWPermission'fetch_attrs,fetch_order=fetch_config(['name','label'])defdc_title(self):ifself.label:return'%s (%s)'%(self.req._(self.name),self.label)returnself.req._(self.name)defafter_deletion_path(self):"""return (path, parameters) which should be used as redirect information when this entity is being deleted """permissionof=getattr(self,'reverse_require_permission',())iflen(permissionof)==1:returnpermissionof[0].rest_path(),{}returnsuper(CWPermission,self).after_deletion_path()