entity.py
changeset 2650 18aec79ec3a3
parent 2647 b0a2e779845c
child 2656 a93ae0f6c0ad
equal deleted inserted replaced
2649:5d4a943695d1 2650:18aec79ec3a3
   263                     selection.pop()
   263                     selection.pop()
   264                     restrictions.pop()
   264                     restrictions.pop()
   265                     continue
   265                     continue
   266                 if card == '?':
   266                 if card == '?':
   267                     restrictions[-1] += '?' # left outer join if not mandatory
   267                     restrictions[-1] += '?' # left outer join if not mandatory
   268                 destcls = cls.vreg.etype_class(desttype)
   268                 destcls = cls.vreg['etypes'].etype_class(desttype)
   269                 destcls._fetch_restrictions(var, varmaker, destcls.fetch_attrs,
   269                 destcls._fetch_restrictions(var, varmaker, destcls.fetch_attrs,
   270                                             selection, orderby, restrictions,
   270                                             selection, orderby, restrictions,
   271                                             user, ordermethod, visited=visited)
   271                                             user, ordermethod, visited=visited)
   272             orderterm = getattr(cls, ordermethod)(attr, var)
   272             orderterm = getattr(cls, ordermethod)(attr, var)
   273             if orderterm:
   273             if orderterm:
   275         return selection, orderby, restrictions
   275         return selection, orderby, restrictions
   276 
   276 
   277     @classmethod
   277     @classmethod
   278     @cached
   278     @cached
   279     def parent_classes(cls):
   279     def parent_classes(cls):
   280         parents = [cls.vreg.etype_class(e.type) for e in cls.e_schema.ancestors()]
   280         parents = [cls.vreg['etypes'].etype_class(e.type)
   281         parents.append(cls.vreg.etype_class('Any'))
   281                    for e in cls.e_schema.ancestors()]
       
   282         parents.append(cls.vreg['etypes'].etype_class('Any'))
   282         return parents
   283         return parents
   283 
   284 
   284     @classmethod
   285     @classmethod
   285     @cached
   286     @cached
   286     def _rest_attr_info(cls):
   287     def _rest_attr_info(cls):
   362         self.e_schema.check_perm(self.req, action, self.eid)
   363         self.e_schema.check_perm(self.req, action, self.eid)
   363 
   364 
   364     def has_perm(self, action):
   365     def has_perm(self, action):
   365         return self.e_schema.has_perm(self.req, action, self.eid)
   366         return self.e_schema.has_perm(self.req, action, self.eid)
   366 
   367 
   367     def view(self, vid, **kwargs):
   368     def view(self, vid, __registry='views', **kwargs):
   368         """shortcut to apply a view on this entity"""
   369         """shortcut to apply a view on this entity"""
   369         return self.vreg.render(vid, self.req, rset=self.rset,
   370         return self.vreg[__registry].render(vid, self.req, rset=self.rset,
   370                                 row=self.row, col=self.col, **kwargs)
   371                                             row=self.row, col=self.col, **kwargs)
   371 
   372 
   372     def absolute_url(self, *args, **kwargs):
   373     def absolute_url(self, *args, **kwargs):
   373         """return an absolute url to view this entity"""
   374         """return an absolute url to view this entity"""
   374         # use *args since we don't want first argument to be "anonymous" to
   375         # use *args since we don't want first argument to be "anonymous" to
   375         # avoid potential clash with kwargs
   376         # avoid potential clash with kwargs
   700             restriction = 'E eid %%(x)s, X %s E' % rtype
   701             restriction = 'E eid %%(x)s, X %s E' % rtype
   701             card = greater_card(rschema, targettypes, (self.e_schema,), 1)
   702             card = greater_card(rschema, targettypes, (self.e_schema,), 1)
   702         if len(targettypes) > 1:
   703         if len(targettypes) > 1:
   703             fetchattrs_list = []
   704             fetchattrs_list = []
   704             for ttype in targettypes:
   705             for ttype in targettypes:
   705                 etypecls = self.vreg.etype_class(ttype)
   706                 etypecls = self.vreg['etypes'].etype_class(ttype)
   706                 fetchattrs_list.append(set(etypecls.fetch_attrs))
   707                 fetchattrs_list.append(set(etypecls.fetch_attrs))
   707             fetchattrs = reduce(set.intersection, fetchattrs_list)
   708             fetchattrs = reduce(set.intersection, fetchattrs_list)
   708             rql = etypecls.fetch_rql(self.req.user, [restriction], fetchattrs,
   709             rql = etypecls.fetch_rql(self.req.user, [restriction], fetchattrs,
   709                                      settype=False)
   710                                      settype=False)
   710         else:
   711         else:
   711             etypecls = self.vreg.etype_class(targettypes[0])
   712             etypecls = self.vreg['etypes'].etype_class(targettypes[0])
   712             rql = etypecls.fetch_rql(self.req.user, [restriction], settype=False)
   713             rql = etypecls.fetch_rql(self.req.user, [restriction], settype=False)
   713         # optimisation: remove ORDERBY if cardinality is 1 or ? (though
   714         # optimisation: remove ORDERBY if cardinality is 1 or ? (though
   714         # greater_card return 1 for those both cases)
   715         # greater_card return 1 for those both cases)
   715         if card == '1':
   716         if card == '1':
   716             if ' ORDERBY ' in rql:
   717             if ' ORDERBY ' in rql:
   762             restriction += [cstr.restriction for cstr in constraints
   763             restriction += [cstr.restriction for cstr in constraints
   763                             if isinstance(cstr, RQLVocabularyConstraint)]
   764                             if isinstance(cstr, RQLVocabularyConstraint)]
   764         else:
   765         else:
   765             restriction += [cstr.restriction for cstr in constraints
   766             restriction += [cstr.restriction for cstr in constraints
   766                             if isinstance(cstr, RQLConstraint)]
   767                             if isinstance(cstr, RQLConstraint)]
   767         etypecls = self.vreg.etype_class(targettype)
   768         etypecls = self.vreg['etypes'].etype_class(targettype)
   768         rql = etypecls.fetch_rql(self.req.user, restriction,
   769         rql = etypecls.fetch_rql(self.req.user, restriction,
   769                                  mainvar=searchedvar, ordermethod=ordermethod)
   770                                  mainvar=searchedvar, ordermethod=ordermethod)
   770         # ensure we have an order defined
   771         # ensure we have an order defined
   771         if not ' ORDERBY ' in rql:
   772         if not ' ORDERBY ' in rql:
   772             before, after = rql.split(' WHERE ', 1)
   773             before, after = rql.split(' WHERE ', 1)