author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Wed, 01 Oct 2008 22:19:22 +0000 | |
changeset 259 | 74eb6b01c82c |
parent 228 | 2204287da374 |
child 265 | 3c2994f3b85f |
permissions | -rw-r--r-- |
185
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
2 |
# |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
4 |
# |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
8 |
# |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
10 |
# |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
16 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
17 |
"""Helpers used to render lists. |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
18 |
""" |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
19 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
21 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
22 |
] |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
23 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
24 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
25 |
DEF_LIMIT = 10 |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
26 |
|
228
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
27 |
|
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
28 |
def getPreferredListPagination(user=None): |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
29 |
"""Returns User's preferred list pagination limit. |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
30 |
|
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
31 |
Args: |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
32 |
user: User entity containing the list pagination preference; |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
33 |
default is None, to use the current logged-in User |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
34 |
""" |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
35 |
# TODO: eventually this limit should be a User profile preference |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
36 |
# (stored in the site-wide User Model) preference |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
37 |
return DEF_LIMIT |
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
38 |
|
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
39 |
|
185
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
40 |
def getListParemeters(offset=None, limit=None): |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
41 |
"""Updates and validates offset and limit values of the list. |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
42 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
43 |
Args: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
44 |
offset: offset in list which defines first item to return |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
45 |
limit: max amount of items per page |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
46 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
47 |
Returns: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
48 |
updated offset and limit values |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
49 |
""" |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
50 |
# update offset value |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
51 |
if offset: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
52 |
try: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
53 |
offset = int(offset) |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
54 |
except: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
55 |
offset = 0 |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
56 |
else: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
57 |
offset = max(0, offset) |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
58 |
else: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
59 |
offset = 0 |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
60 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
61 |
# update limit value |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
62 |
if limit: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
63 |
try: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
64 |
limit = int(limit) |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
65 |
except: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
66 |
limit = DEF_LIMIT |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
67 |
else: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
68 |
limit = max(1, min(limit, 100)) |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
69 |
else: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
70 |
limit = DEF_LIMIT |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
71 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
72 |
return offset, limit |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
73 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
74 |
DEF_LIST_TEMPLATES = {'list_main': 'soc/list/list_main.html', |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
75 |
'list_pagination': 'soc/list/list_pagination.html', |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
76 |
'list_row': 'soc/list/list_row.html', |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
77 |
'list_heading': 'soc/list/list_heading.html'} |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
78 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
79 |
def setList(request, context, list_data, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
80 |
offset=0, limit=0, list_templates=DEF_LIST_TEMPLATES): |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
81 |
"""Updates template context dict with variables used for rendering lists. |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
82 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
83 |
Args: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
84 |
request: the Django HTTP request object |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
85 |
context: the template context dict to be updated in-place (pass in a copy |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
86 |
if the original must not be modified), or None if a new one is to be |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
87 |
created; any existing fields already present in the context dict passed |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
88 |
in by the caller are left unaltered |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
89 |
list_data: array of data to be displayed in the list |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
90 |
offset: offset in list which defines first item to return |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
91 |
limit: max amount of items per page |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
92 |
list_templates: templates that are used when rendering list |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
93 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
94 |
Returns: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
95 |
updated template context dict supplied by the caller or a new context |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
96 |
dict if the caller supplied None |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
97 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
98 |
{ |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
99 |
'list_data': list data to be displayed |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
100 |
'list_main': url to list main template |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
101 |
'list_pagination': url to list pagination template |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
102 |
'list_row': url to list row template |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
103 |
'list_heading': url to list heading template |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
104 |
'limit': max amount of items per page, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
105 |
'newest': url to first page of the list |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
106 |
'prev': url to previous page |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
107 |
'next': url to next page |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
108 |
'first': offset of the first item in the list |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
109 |
'last': offest of the lst item in the list |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
110 |
} |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
111 |
""" |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
112 |
if not list_data: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
113 |
list_data = [] |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
114 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
115 |
more = bool(list_data[limit:]) |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
116 |
if more: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
117 |
del list_data[limit:] |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
118 |
if more: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
119 |
next = request.path + '?offset=%d&limit=%d' % (offset+limit, limit) |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
120 |
else: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
121 |
next = '' |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
122 |
if offset > 0: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
123 |
prev = request.path + '?offset=%d&limit=%d' % (max(0, offset-limit), limit) |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
124 |
else: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
125 |
prev = '' |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
126 |
newest = '' |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
127 |
if offset > limit: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
128 |
newest = request.path + '?limit=%d' % limit |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
129 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
130 |
if not context: |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
131 |
context = {} |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
132 |
|
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
133 |
context.update( |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
134 |
{'list_data': list_data, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
135 |
'list_main': list_templates['list_main'], |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
136 |
'list_pagination': list_templates['list_pagination'], |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
137 |
'list_row': list_templates['list_row'], |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
138 |
'list_heading': list_templates['list_heading'], |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
139 |
'limit': limit, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
140 |
'newest': newest, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
141 |
'prev': prev, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
142 |
'next': next, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
143 |
'first': offset+1, |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
144 |
'last': len(list_data) > 1 and offset+len(list_data) or None}) |
2f3bd84bb106
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
145 |
|
228
2204287da374
Add placeholder for future (to-be-implemented) getPreferredListPagination()
Todd Larsen <tlarsen@google.com>
parents:
185
diff
changeset
|
146 |
return context |