entities/schemaobjs.py
branchtls-sprint
changeset 1398 5fe84a5f7035
parent 1154 9b23a6836c32
child 1802 d628defebc17
equal deleted inserted replaced
1397:6cbc7bc8ea6d 1398:5fe84a5f7035
    12 from cubicweb.schema import ERQLExpression, RRQLExpression
    12 from cubicweb.schema import ERQLExpression, RRQLExpression
    13 
    13 
    14 from cubicweb.entities import AnyEntity, fetch_config
    14 from cubicweb.entities import AnyEntity, fetch_config
    15 
    15 
    16 
    16 
    17 class EEType(AnyEntity):
    17 class CWEType(AnyEntity):
    18     id = 'EEType'
    18     id = 'CWEType'
    19     fetch_attrs, fetch_order = fetch_config(['name'])
    19     fetch_attrs, fetch_order = fetch_config(['name'])
    20 
    20 
    21     def dc_title(self):
    21     def dc_title(self):
    22         return self.req._(self.name)
    22         return self.req._(self.name)
    23     
    23     
    35     def db_key_name(self):
    35     def db_key_name(self):
    36         """XXX goa specific"""
    36         """XXX goa specific"""
    37         return self.get('name')
    37         return self.get('name')
    38 
    38 
    39 
    39 
    40 class ERType(AnyEntity):
    40 class CWRType(AnyEntity):
    41     id = 'ERType'
    41     id = 'CWRType'
    42     fetch_attrs, fetch_order = fetch_config(['name'])
    42     fetch_attrs, fetch_order = fetch_config(['name'])
    43     
    43     
    44     def dc_title(self):
    44     def dc_title(self):
    45         return self.req._(self.name)
    45         return self.req._(self.name)
    46     
    46     
    83     def db_key_name(self):
    83     def db_key_name(self):
    84         """XXX goa specific"""
    84         """XXX goa specific"""
    85         return self.get('name')
    85         return self.get('name')
    86 
    86 
    87 
    87 
    88 class ENFRDef(AnyEntity):
    88 class CWRelation(AnyEntity):
    89     id = 'ENFRDef'
    89     id = 'CWRelation'
    90     fetch_attrs = fetch_config(['cardinality'])[0]
    90     fetch_attrs = fetch_config(['cardinality'])[0]
    91     
    91     
    92     def dc_title(self):
    92     def dc_title(self):
    93         return u'%s %s %s' % (
    93         return u'%s %s %s' % (
    94             self.from_entity[0].name,
    94             self.from_entity[0].name,
   111         """return (path, parameters) which should be used as redirect
   111         """return (path, parameters) which should be used as redirect
   112         information when this entity is being deleted
   112         information when this entity is being deleted
   113         """
   113         """
   114         if self.relation_type:
   114         if self.relation_type:
   115             return self.relation_type[0].rest_path(), {}
   115             return self.relation_type[0].rest_path(), {}
   116         return super(ENFRDef, self).after_deletion_path()
   116         return super(CWRelation, self).after_deletion_path()
   117 
   117 
   118 
   118 
   119 class EFRDef(ENFRDef):
   119 class CWAttribute(CWRelation):
   120     id = 'EFRDef'
   120     id = 'CWAttribute'
   121     
   121     
   122     def dc_long_title(self):
   122     def dc_long_title(self):
   123         card = self.cardinality
   123         card = self.cardinality
   124         scard = u''
   124         scard = u''
   125         if card[0] == '1':
   125         if card[0] == '1':
   128             self.from_entity[0].name,
   128             self.from_entity[0].name,
   129             scard, self.relation_type[0].name, 
   129             scard, self.relation_type[0].name, 
   130             self.to_entity[0].name)
   130             self.to_entity[0].name)
   131 
   131 
   132 
   132 
   133 class EConstraint(AnyEntity):
   133 class CWConstraint(AnyEntity):
   134     id = 'EConstraint'
   134     id = 'CWConstraint'
   135     fetch_attrs, fetch_order = fetch_config(['value'])
   135     fetch_attrs, fetch_order = fetch_config(['value'])
   136 
   136 
   137     def dc_title(self):
   137     def dc_title(self):
   138         return '%s(%s)' % (self.cstrtype[0].name, self.value or u'')
   138         return '%s(%s)' % (self.cstrtype[0].name, self.value or u'')
   139         
   139         
   141         """return (path, parameters) which should be used as redirect
   141         """return (path, parameters) which should be used as redirect
   142         information when this entity is being deleted
   142         information when this entity is being deleted
   143         """
   143         """
   144         if self.reverse_constrained_by:
   144         if self.reverse_constrained_by:
   145             return self.reverse_constrained_by[0].rest_path(), {}
   145             return self.reverse_constrained_by[0].rest_path(), {}
   146         return super(EConstraint, self).after_deletion_path()
   146         return super(CWConstraint, self).after_deletion_path()
   147 
   147 
   148     @property
   148     @property
   149     def type(self):
   149     def type(self):
   150         return self.cstrtype[0].name
   150         return self.cstrtype[0].name
   151 
   151 
   182         if self.expression_of:
   182         if self.expression_of:
   183             return self.expression_of.rest_path(), {}
   183             return self.expression_of.rest_path(), {}
   184         return super(RQLExpression, self).after_deletion_path()
   184         return super(RQLExpression, self).after_deletion_path()
   185 
   185 
   186 
   186 
   187 class EPermission(AnyEntity):
   187 class CWPermission(AnyEntity):
   188     id = 'EPermission'
   188     id = 'CWPermission'
   189     fetch_attrs, fetch_order = fetch_config(['name', 'label'])
   189     fetch_attrs, fetch_order = fetch_config(['name', 'label'])
   190 
   190 
   191     def dc_title(self):
   191     def dc_title(self):
   192         if self.label:
   192         if self.label:
   193             return '%s (%s)' % (self.req._(self.name), self.label)
   193             return '%s (%s)' % (self.req._(self.name), self.label)
   198         information when this entity is being deleted
   198         information when this entity is being deleted
   199         """
   199         """
   200         permissionof = getattr(self, 'reverse_require_permission', ())
   200         permissionof = getattr(self, 'reverse_require_permission', ())
   201         if len(permissionof) == 1:
   201         if len(permissionof) == 1:
   202             return permissionof[0].rest_path(), {}
   202             return permissionof[0].rest_path(), {}
   203         return super(EPermission, self).after_deletion_path()
   203         return super(CWPermission, self).after_deletion_path()