Refactored part of getForFields into a getQueryForFields method.
authorLennard de Rijk <ljvderijk@gmail.com>
Fri, 06 Mar 2009 18:57:35 +0000
changeset 1694 d388ff2fbe90
parent 1693 c5691230da01
child 1695 d0f8d033cf3c
Refactored part of getForFields into a getQueryForFields method. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/logic/models/base.py
--- a/app/soc/logic/models/base.py	Fri Mar 06 18:11:09 2009 +0000
+++ b/app/soc/logic/models/base.py	Fri Mar 06 18:57:35 2009 +0000
@@ -281,10 +281,32 @@
       order: a list with the sort order
     """
 
+    if unique:
+      limit = 1
+
+    query = self.getQueryForFields(filter=filter, order=order)
+
+    result = query.fetch(limit, offset)
+
+    if unique:
+      return result[0] if result else None
+
+    return result
+
+  def getQueryForFields(self, filter=None, order=None):
+    """Returns a query with the specified properties.
+
+    Args:
+      filter: a dict for the properties that the entities should have
+      order: a list with the sort order
+
+    Returns:
+      - Query object instantiated with the given properties
+    """
+
     if not filter:
       filter = {}
-    if unique:
-      limit = 1
+
     if not order:
       order = []
 
@@ -304,12 +326,7 @@
     for key in order:
       query.order(key)
 
-    result = query.fetch(limit, offset)
-
-    if unique:
-      return result[0] if result else None
-
-    return result
+    return query
 
   def updateEntityProperties(self, entity, entity_properties, silent=False):
     """Update existing entity using supplied properties.