app/soc/views/helper/lists.py
changeset 553 c0cc20b4afc9
parent 539 e30462354e26
child 555 3cdfb42d941b
equal deleted inserted replaced
552:cb23b3897e0c 553:c0cc20b4afc9
    76     limit = getPreferredListPagination()
    76     limit = getPreferredListPagination()
    77 
    77 
    78   return max(0, offset), max(1, min(limit, MAX_PAGINATION))
    78   return max(0, offset), max(1, min(limit, MAX_PAGINATION))
    79 
    79 
    80 
    80 
    81 def getList(request, list_data, list_templates, description, offset=0, limit=0):
    81 def getList(request, data, offset, limit):
    82   """Returns a dict with fields used for rendering lists.
    82   """Returns a dict with fields used for rendering lists.
    83 
    83 
    84   Args:
    84   Args:
    85     request: the Django HTTP request object
    85     request: the Django HTTP request object
    86     list_data: array of data to be displayed in the list
    86     data: array of data to be displayed in the list
    87     offset: offset in list which defines first item to return
    87     offset: offset in list which defines first item to return
    88     limit: max amount of items per page
    88     limit: max amount of items per page
    89     list_templates: templates that are used when rendering list
       
    90 
    89 
    91   Returns:
    90   Returns:
    92     A a dictionary with the following values set:
    91     A a dictionary with the following values set:
    93 
    92 
    94     {
    93     {
   104       'first': offset of the first item in the list
   103       'first': offset of the first item in the list
   105       'last': offest of the lst item in the list
   104       'last': offest of the lst item in the list
   106     }
   105     }
   107   """
   106   """
   108 
   107 
   109   if not list_data:
   108   if not data:
   110     list_data = []
   109     data = []
   111 
   110 
   112   more = bool(list_data[limit:])
   111   more = bool(data[limit:])
   113   if more:
   112   if more:
   114     del list_data[limit:]
   113     del data[limit:]
   115 
   114 
   116   newest = ''
   115   newest = ''
   117   next = ''
   116   next = ''
   118   prev = ''
   117   prev = ''
   119 
   118 
   125 
   124 
   126   if offset > limit:
   125   if offset > limit:
   127     newest = request.path + '?limit=%d' % limit
   126     newest = request.path + '?limit=%d' % limit
   128 
   127 
   129   content = {
   128   content = {
   130       'data': list_data,
   129       'data': data,
   131       'description': description,
   130       'first': offset+1,
   132      'main': list_templates['list_main'],
   131       'last': len(data) > 1 and offset+len(data) or None,
   133      'pagination': list_templates['list_pagination'],
   132       'limit': limit,
   134      'row': list_templates['list_row'],
   133       'newest': newest, 
   135      'heading': list_templates['list_heading'],
   134       'next': next,
   136      'limit': limit,
   135       'prev': prev, 
   137      'newest': newest, 
   136       }
   138      'prev': prev, 
       
   139      'next': next,
       
   140      'first': offset+1,
       
   141      'last': len(list_data) > 1 and offset+len(list_data) or None
       
   142      }
       
   143 
   137 
   144   return content
   138   return content
   145 
   139 
   146 
   140 
   147 def makePaginationForm(
   141 def makePaginationForm(