Beispiel #1
0
 def find(cls, **params):
     if params.has_key("manager"):
         manager = params["manager"]
         del params["manager"]
     else:
         manager = cls._manager
     keys = params.keys()
     if len(keys) > 4:
         raise SDBPersistenceError("Too many fields, max is 4")
     parts = ["['__type__'='%s'] union ['__lineage__'starts-with'%s']" % (cls.__name__, cls.get_lineage())]
     properties = cls.properties()
     for key in keys:
         found = False
         for property in properties:
             if property.name == key:
                 found = True
                 if isinstance(property, ScalarProperty):
                     checker = property.checker
                     parts.append("['%s' = '%s']" % (key, checker.to_string(params[key])))
                 else:
                     raise SDBPersistenceError("%s is not a searchable field" % key)
         if not found:
             raise SDBPersistenceError("%s is not a valid field" % key)
     query = " intersection ".join(parts)
     if manager.domain:
         rs = manager.domain.query(query)
     else:
         rs = []
     return object_lister(None, rs, manager)
Beispiel #2
0
 def find(cls, **params):
     if params.has_key('manager'):
         manager = params['manager']
         del params['manager']
     else:
         manager = cls._manager
     keys = params.keys()
     if len(keys) > 4:
         raise SDBPersistenceError('Too many fields, max is 4')
     parts = ["['__type__'='%s'] union ['__lineage__'starts-with'%s']" % (cls.__name__, cls.get_lineage())]
     properties = cls.properties()
     for key in keys:
         found = False
         for property in properties:
             if property.name == key:
                 found = True
                 if isinstance(property, ScalarProperty):
                     checker = property.checker
                     parts.append("['%s' = '%s']" % (key, checker.to_string(params[key])))
                 else:
                     raise SDBPersistenceError('%s is not a searchable field' % key)
         if not found:
             raise SDBPersistenceError('%s is not a valid field' % key)
     query = ' intersection '.join(parts)
     if manager.domain:
         rs = manager.domain.query(query)
     else:
         rs = []
     return object_lister(None, rs, manager)
Beispiel #3
0
 def find(cls, **params):
     keys = params.keys()
     if len(keys) > 4:
         raise SDBPersistanceError('Too many fields, max is 4')
     parts = ["['__type__'='%s'] union ['__lineage__'starts-with'%s']" % (cls.__name__, cls.get_lineage())]
     properties = cls.find_properties()
     for key in keys:
         found = False
         for property in properties:
             if property.name == key:
                 found = True
                 if isinstance(property, ScalarProperty):
                     checker = property.checker
                     parts.append("['%s' = '%s']" % (key, checker.to_string(params[key])))
                 else:
                     raise SDBPersistanceError('%s is not a searchable field' % key)
         if not found:
             raise SDBPersistanceError('%s is not a valid field' % key)
     query = ' intersection '.join(parts)
     domain = get_domain()
     if domain:
         rs = domain.query(query)
     else:
         rs = []
     return object_lister(None, rs)
Beispiel #4
0
 def list(cls, max_items=None):
     domain = get_domain()
     if domain:
         rs = domain.query("['__type__' = '%s']" % cls.__name__, max_items=max_items)
     else:
         rs = []
     return object_lister(cls, rs)
Beispiel #5
0
 def list(cls, max_items=None, manager=None):
     if not manager:
         manager = cls._manager
     if manager.domain:
         rs = manager.domain.query("['__type__' = '%s']" % cls.__name__, max_items=max_items)
     else:
         rs = []
     return object_lister(cls, rs, manager)
Beispiel #6
0
 def list(cls, max_items=None, manager=None):
     if not manager:
         manager = cls._manager
     if manager.domain:
         rs = manager.domain.query("['__type__' = '%s']" % cls.__name__, max_items=max_items)
     else:
         rs = []
     return object_lister(cls, rs, manager)
Beispiel #7
0
 def get_related_objects(self, ref_name, ref_cls=None):
     if self._manager.domain:
         query = "['%s' = '%s']" % (ref_name, self.id)
         if ref_cls:
             query += " intersection ['__type__'='%s']" % ref_cls.__name__
         rs = self._manager.domain.query(query)
     else:
         rs = []
     return object_lister(ref_cls, rs, self._manager)
Beispiel #8
0
 def get_related_objects(self, ref_name, ref_cls=None):
     if self._manager.domain:
         query = "['%s' = '%s']" % (ref_name, self.id)
         if ref_cls:
             query += " intersection ['__type__'='%s']" % ref_cls.__name__
         rs = self._manager.domain.query(query)
     else:
         rs = []
     return object_lister(ref_cls, rs, self._manager)