req.py
changeset 4850 bd640b137f50
parent 4835 13b0b96d7982
child 4899 c666d265fb95
equal deleted inserted replaced
4849:3827b9ee77ac 4850:bd640b137f50
    74         rset = ResultSet([('A',)]*size, '%s X' % etype,
    74         rset = ResultSet([('A',)]*size, '%s X' % etype,
    75                          description=[(etype,)]*size)
    75                          description=[(etype,)]*size)
    76         def get_entity(row, col=0, etype=etype, req=self, rset=rset):
    76         def get_entity(row, col=0, etype=etype, req=self, rset=rset):
    77             return req.vreg.etype_class(etype)(req, rset, row, col)
    77             return req.vreg.etype_class(etype)(req, rset, row, col)
    78         rset.get_entity = get_entity
    78         rset.get_entity = get_entity
    79         return self.decorate_rset(rset)
    79         rset.req = self
       
    80         return rset
    80 
    81 
    81     def eid_rset(self, eid, etype=None):
    82     def eid_rset(self, eid, etype=None):
    82         """return a result set for the given eid without doing actual query
    83         """return a result set for the given eid without doing actual query
    83         (we have the eid, we can suppose it exists and user has access to the
    84         (we have the eid, we can suppose it exists and user has access to the
    84         entity)
    85         entity)
    86         eid = typed_eid(eid)
    87         eid = typed_eid(eid)
    87         if etype is None:
    88         if etype is None:
    88             etype = self.describe(eid)[0]
    89             etype = self.describe(eid)[0]
    89         rset = ResultSet([(eid,)], 'Any X WHERE X eid %(x)s', {'x': eid},
    90         rset = ResultSet([(eid,)], 'Any X WHERE X eid %(x)s', {'x': eid},
    90                          [(etype,)])
    91                          [(etype,)])
    91         return self.decorate_rset(rset)
    92         rset.req = self
       
    93         return rset
    92 
    94 
    93     def empty_rset(self):
    95     def empty_rset(self):
    94         """return a result set for the given eid without doing actual query
    96         """return a result set for the given eid without doing actual query
    95         (we have the eid, we can suppose it exists and user has access to the
    97         (we have the eid, we can suppose it exists and user has access to the
    96         entity)
    98         entity)
    97         """
    99         """
    98         return self.decorate_rset(ResultSet([], 'Any X WHERE X eid -1'))
   100         rset = ResultSet([], 'Any X WHERE X eid -1')
       
   101         rset.req = self
       
   102         return rset
    99 
   103 
   100     def entity_from_eid(self, eid, etype=None):
   104     def entity_from_eid(self, eid, etype=None):
   101         """return an entity instance for the given eid. No query is done"""
   105         """return an entity instance for the given eid. No query is done"""
   102         try:
   106         try:
   103             return self.entity_cache(eid)
   107             return self.entity_cache(eid)
   385 
   389 
   386     def base_url(self):
   390     def base_url(self):
   387         """return the root url of the instance"""
   391         """return the root url of the instance"""
   388         raise NotImplementedError
   392         raise NotImplementedError
   389 
   393 
   390     def decorate_rset(self, rset):
       
   391         """add vreg/req (at least) attributes to the given result set """
       
   392         raise NotImplementedError
       
   393 
       
   394     def describe(self, eid):
   394     def describe(self, eid):
   395         """return a tuple (type, sourceuri, extid) for the entity with id <eid>"""
   395         """return a tuple (type, sourceuri, extid) for the entity with id <eid>"""
   396         raise NotImplementedError
   396         raise NotImplementedError
   397 
   397 
   398     @property
   398     @property