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 { |
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( |