equal
deleted
inserted
replaced
76 @classmethod |
76 @classmethod |
77 def __initialize__(cls, schema): |
77 def __initialize__(cls, schema): |
78 """initialize a specific entity class by adding descriptors to access |
78 """initialize a specific entity class by adding descriptors to access |
79 entity type's attributes and relations |
79 entity type's attributes and relations |
80 """ |
80 """ |
81 etype = cls.__id__ |
81 etype = cls.__regid__ |
82 assert etype != 'Any', etype |
82 assert etype != 'Any', etype |
83 cls.e_schema = eschema = schema.eschema(etype) |
83 cls.e_schema = eschema = schema.eschema(etype) |
84 for rschema, _ in eschema.attribute_definitions(): |
84 for rschema, _ in eschema.attribute_definitions(): |
85 if rschema.type == 'eid': |
85 if rschema.type == 'eid': |
86 continue |
86 continue |
107 def fetch_rql(cls, user, restriction=None, fetchattrs=None, mainvar='X', |
107 def fetch_rql(cls, user, restriction=None, fetchattrs=None, mainvar='X', |
108 settype=True, ordermethod='fetch_order'): |
108 settype=True, ordermethod='fetch_order'): |
109 """return a rql to fetch all entities of the class type""" |
109 """return a rql to fetch all entities of the class type""" |
110 restrictions = restriction or [] |
110 restrictions = restriction or [] |
111 if settype: |
111 if settype: |
112 restrictions.append('%s is %s' % (mainvar, cls.__id__)) |
112 restrictions.append('%s is %s' % (mainvar, cls.__regid__)) |
113 if fetchattrs is None: |
113 if fetchattrs is None: |
114 fetchattrs = cls.fetch_attrs |
114 fetchattrs = cls.fetch_attrs |
115 selection = [mainvar] |
115 selection = [mainvar] |
116 orderby = [] |
116 orderby = [] |
117 # start from 26 to avoid possible conflicts with X |
117 # start from 26 to avoid possible conflicts with X |
140 for attr in fetchattrs: |
140 for attr in fetchattrs: |
141 try: |
141 try: |
142 rschema = eschema.subject_relation(attr) |
142 rschema = eschema.subject_relation(attr) |
143 except KeyError: |
143 except KeyError: |
144 cls.warning('skipping fetch_attr %s defined in %s (not found in schema)', |
144 cls.warning('skipping fetch_attr %s defined in %s (not found in schema)', |
145 attr, cls.__id__) |
145 attr, cls.__regid__) |
146 continue |
146 continue |
147 if not user.matching_groups(rschema.get_groups('read')): |
147 if not user.matching_groups(rschema.get_groups('read')): |
148 continue |
148 continue |
149 var = varmaker.next() |
149 var = varmaker.next() |
150 selection.append(var) |
150 selection.append(var) |
283 if method in (None, 'view'): |
283 if method in (None, 'view'): |
284 try: |
284 try: |
285 kwargs['_restpath'] = self.rest_path(kwargs.get('base_url')) |
285 kwargs['_restpath'] = self.rest_path(kwargs.get('base_url')) |
286 except TypeError: |
286 except TypeError: |
287 warn('%s: rest_path() now take use_ext_eid argument, ' |
287 warn('%s: rest_path() now take use_ext_eid argument, ' |
288 'please update' % self.__id__, DeprecationWarning) |
288 'please update' % self.__regid__, DeprecationWarning) |
289 kwargs['_restpath'] = self.rest_path() |
289 kwargs['_restpath'] = self.rest_path() |
290 else: |
290 else: |
291 kwargs['rql'] = 'Any X WHERE X eid %s' % self.eid |
291 kwargs['rql'] = 'Any X WHERE X eid %s' % self.eid |
292 return self.req.build_url(method, **kwargs) |
292 return self.req.build_url(method, **kwargs) |
293 |
293 |
419 |
419 |
420 @cached |
420 @cached |
421 def as_rset(self): |
421 def as_rset(self): |
422 """returns a resultset containing `self` information""" |
422 """returns a resultset containing `self` information""" |
423 rset = ResultSet([(self.eid,)], 'Any X WHERE X eid %(x)s', |
423 rset = ResultSet([(self.eid,)], 'Any X WHERE X eid %(x)s', |
424 {'x': self.eid}, [(self.__id__,)]) |
424 {'x': self.eid}, [(self.__regid__,)]) |
425 return self.req.decorate_rset(rset) |
425 return self.req.decorate_rset(rset) |
426 |
426 |
427 def to_complete_relations(self): |
427 def to_complete_relations(self): |
428 """by default complete final relations to when calling .complete()""" |
428 """by default complete final relations to when calling .complete()""" |
429 for rschema in self.e_schema.subject_relations(): |
429 for rschema in self.e_schema.subject_relations(): |