app/soc/views/helper/lists.py
changeset 2855 ec2ed1571e3a
parent 2363 9046c80a9137
child 3075 1e78db95e38a
equal deleted inserted replaced
2854:003a84e774e2 2855:ec2ed1571e3a
    17 """Helpers used to render lists.
    17 """Helpers used to render lists.
    18 """
    18 """
    19 
    19 
    20 __authors__ = [
    20 __authors__ = [
    21   '"Chen Lunpeng" <forever.clp@gmail.com>',
    21   '"Chen Lunpeng" <forever.clp@gmail.com>',
       
    22   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
    22   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    23   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    23   ]
    24   ]
    24 
    25 
    25 
    26 
    26 from soc.logic import dicts
    27 from soc.logic import dicts
   134   params.update(updated_params)
   135   params.update(updated_params)
   135   return generateLinkFromGetArgs(request, params)
   136   return generateLinkFromGetArgs(request, params)
   136 
   137 
   137 
   138 
   138 def getListContent(request, params, filter=None, order=None,
   139 def getListContent(request, params, filter=None, order=None,
   139                    idx=0, need_content=False):
   140                    idx=0, need_content=False, prefetch=None):
   140   """Returns a dict with fields used for rendering lists.
   141   """Returns a dict with fields used for rendering lists.
   141 
   142 
   142   TODO(dbentley): we need better terminology. List, in this context, can have
   143   TODO(dbentley): we need better terminology. List, in this context, can have
   143     one of two meanings.
   144     one of two meanings.
   144     Meaning 1:  the underlying list, which may be very large.
   145     Meaning 1:  the underlying list, which may be very large.
   149     params: a dict with params for the View this list belongs to
   150     params: a dict with params for the View this list belongs to
   150     filter: a filter for this list
   151     filter: a filter for this list
   151     order: the order which should be used for the list (in getForFields format)
   152     order: the order which should be used for the list (in getForFields format)
   152     idx: the index of this list
   153     idx: the index of this list
   153     need_content: iff True will return None if there is no data
   154     need_content: iff True will return None if there is no data
       
   155     prefetch: the fields of the data that should be pre-fetched
   154 
   156 
   155   Returns:
   157   Returns:
   156     A dictionary with the following values set:
   158     A dictionary with the following values set:
   157 
   159 
   158     {
   160     {
   180   pagination_form = makePaginationForm(request, list_params['limit'],
   182   pagination_form = makePaginationForm(request, list_params['limit'],
   181                                        limit_key)
   183                                        limit_key)
   182 
   184 
   183   # Fetch one more to see if there should be a 'next' link
   185   # Fetch one more to see if there should be a 'next' link
   184   data = logic.getForFields(filter=filter, limit=limit+1, offset=offset,
   186   data = logic.getForFields(filter=filter, limit=limit+1, offset=offset,
   185                             order=order)
   187                             order=order, prefetch=prefetch)
   186 
   188 
   187   if need_content and not data:
   189   if need_content and not data:
   188     return None
   190     return None
   189 
   191 
   190   more = len(data) > limit
   192   more = len(data) > limit