Exemplo n.º 1
0
 def query(self, ETM, aq_fs, xtra_filter):
     if aq_fs or self.treshold == 0:
         q = ETM.query(*aq_fs)
         if xtra_filter is not None:
             q = q.filter(xtra_filter)
         return q.distinct()
     return TFL.Q_Result(())
Exemplo n.º 2
0
 def __call__ \
         ( self, scope, val_dict
         , ETM_R       = None
         , AQ          = None
         , xtra_filter = None
         ) :
     ETM = scope [self.etn]
     if ETM_R is None :
         ETM_R = ETM
     vd  = dict  ((k, v) for k, v in pyk.iteritems (val_dict) if v != "")
     fs  = tuple (ETM.ac_query_attrs (self.names, vd, AQ))
     if fs or self.treshold == 0 :
         q = ETM_R.query_s (* fs)
         if xtra_filter is not None :
             q = q.filter (xtra_filter)
         return q.distinct ()
     return TFL.Q_Result (())
Exemplo n.º 3
0
    def r_query(self, *filters, **kw):
        """Return all links matching the conditions in `filters` and `kw`.

           `r_query` behaves similar to `query` but provides the additional
           features:

           - if `kw` contains role names or other id-entity-attributes,

             * the name can be a generic or a specific role name (`query`
               only allows generic role names)

             * the values passed can be `epk` in cooked or raw form (for
               `query`, objects must be passed)

             * the returned links are restricted to those linking the
               specified objects
        """
        Type = self._etype
        map = getattr(Type, "role_map", None)
        rkw = {}
        if map:
            for k in list(kw):
                aie = None
                if k in map:
                    aie = Type.Roles[map[k]]
                elif k in Type.attributes:
                    a = Type.attributes[k]
                    if isinstance(a.attr, MOM.Attr.A_Id_Entity):
                        aie = a.attr
                if aie is not None:
                    try:
                        obj = self._cooked_role(aie, kw.pop(k))
                        if not isinstance(obj, aie.P_Type):
                            return []
                        rkw[aie.name] = obj
                    except MOM.Error.No_Such_Entity:
                        return TFL.Q_Result(())
        if rkw:
            kw = dict(kw, **rkw)
        result = self.query(*filters, **kw)
        return result
Exemplo n.º 4
0
 def query(self, *args, **kw):
     ### we need to define this function to hide the `query` attribute of
     ### the entities (which is a list of all attributes with the kind
     ### `Query`)
     return TFL.Q_Result(())