The list method in models/base.py can now use a filter to make a selection of entities to show.
authorLennard de Rijk <ljvderijk@gmail.com>
Thu, 20 Nov 2008 21:01:18 +0000
changeset 516 ec1dcd70b97e
parent 515 fa235f6759f3
child 517 661ab830e921
The list method in models/base.py can now use a filter to make a selection of entities to show. Patch by: Lennard de Rijk
app/soc/views/models/base.py
--- a/app/soc/views/models/base.py	Thu Nov 20 20:59:10 2008 +0000
+++ b/app/soc/views/models/base.py	Thu Nov 20 21:01:18 2008 +0000
@@ -19,6 +19,7 @@
 
 __authors__ = [
   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
   '"Pawel Solyga" <pawel.solyga@gmail.com>',
   ]
 
@@ -314,13 +315,14 @@
 
     return self._constructResponse(request, entity, context, form, params)
 
-  def list(self, request, page_name=None, params=None):
+  def list(self, request, page_name=None, params=None, filter=None):
     """Displays the list page for the entity type.
     
     Args:
       request: the standard Django HTTP request object
       page_name: the page name displayed in templates as page and header title
       params: a dict with params for this View
+      filter: a dict for the properties that the entities should have
     """
 
     params = dicts.merge(params, self._params)
@@ -337,8 +339,11 @@
       offset=request.GET.get('offset'), limit=request.GET.get('limit'))
 
     # Fetch one more to see if there should be a 'next' link
-    entities = self._logic.getForLimitAndOffset(limit + 1, offset=offset)
-
+    if not filter:
+      entities = self._logic.getForLimitAndOffset(limit + 1, offset=offset)
+    else:
+      entities = self._logic.getForFields(filter, limit=limit + 1, offset=offset)
+    
     context['pagination_form'] = helper.lists.makePaginationForm(request, limit)
 
     templates = params['lists_template']