|
1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2008 the Melange authors. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 |
|
17 """Developer views for listing Documents. |
|
18 """ |
|
19 |
|
20 __authors__ = [ |
|
21 '"Todd Larsen" <tlarsen@google.com>', |
|
22 ] |
|
23 |
|
24 |
|
25 from soc.logic import document |
|
26 from soc.views import simple |
|
27 from soc.views.helpers import list_helpers |
|
28 from soc.views.helpers import response_helpers |
|
29 |
|
30 import soc.models.document |
|
31 |
|
32 |
|
33 DEF_SITE_DOCS_LIST_ALL_TMPL = 'soc/site/docs/list/all.html' |
|
34 |
|
35 def all(request, template=DEF_SITE_DOCS_LIST_ALL_TMPL): |
|
36 """Show a list of all Documents (limit rows per page). |
|
37 |
|
38 Args: |
|
39 request: the standard Django HTTP request object |
|
40 template: the "sibling" template (or a search list of such templates) |
|
41 from which to construct an alternate template name (or names) |
|
42 |
|
43 Returns: |
|
44 A subclass of django.http.HttpResponse which either contains the form to |
|
45 be filled out, or a redirect to the correct view in the interface. |
|
46 """ |
|
47 # create default template context for use with any templates |
|
48 context = response_helpers.getUniversalContext(request) |
|
49 |
|
50 alt_response = simple.getAltResponseIfNotDeveloper(request, |
|
51 context=context) |
|
52 if alt_response: |
|
53 return alt_response |
|
54 |
|
55 offset = request.GET.get('offset') |
|
56 limit = request.GET.get('limit') |
|
57 |
|
58 offset, limit = list_helpers.getListParemeters(offset=offset, limit=limit) |
|
59 |
|
60 docs = document.getWorksForOffsetAndLimit( |
|
61 offset=offset, limit=limit, cls=soc.models.document.Document) |
|
62 |
|
63 list_templates = {'list_main': 'soc/list/list_main.html', |
|
64 'list_pagination': 'soc/list/list_pagination.html', |
|
65 'list_row': 'soc/site/docs/list/docs_row.html', |
|
66 'list_heading': 'soc/site/docs/list/docs_heading.html'} |
|
67 |
|
68 context = list_helpers.setList( |
|
69 request, context, docs, |
|
70 offset=offset, limit=limit, list_templates=list_templates) |
|
71 |
|
72 return response_helpers.respond(request, template, context) |