|
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 """Views for listing Documents. |
|
18 """ |
|
19 |
|
20 __authors__ = [ |
|
21 '"Todd Larsen" <tlarsen@google.com>', |
|
22 ] |
|
23 |
|
24 |
|
25 from soc.logic.models import work |
|
26 from soc.views import helper |
|
27 from soc.views.helper import access |
|
28 from soc.views.helper import decorators |
|
29 |
|
30 import soc.logic |
|
31 import soc.models.document |
|
32 import soc.views.helper.lists |
|
33 import soc.views.helper.responses |
|
34 import soc.views.out_of_band |
|
35 |
|
36 |
|
37 DEF_DOCS_LIST_ALL_TMPL = 'soc/docs/list/all.html' |
|
38 |
|
39 |
|
40 @decorators.view |
|
41 def all(request, page=None, templates={}): |
|
42 """Show a list of all Documents (limit rows per page). |
|
43 |
|
44 Args: |
|
45 request: the standard Django HTTP request object |
|
46 page: a soc.logic.site.page.Page object which is abstraction that combines |
|
47 a Django view with sidebar menu info |
|
48 template: the "sibling" template (or a search list of such templates) |
|
49 from which to construct an alternate template name (or names) |
|
50 |
|
51 Returns: |
|
52 A subclass of django.http.HttpResponse which either contains the form to |
|
53 be filled out, or a redirect to the correct view in the interface. |
|
54 """ |
|
55 |
|
56 try: |
|
57 access.checkIsDeveloper(request) |
|
58 except soc.views.out_of_band.AccessViolationResponse, alt_response: |
|
59 return alt_response.response() |
|
60 |
|
61 # create default template context for use with any templates |
|
62 context = helper.responses.getUniversalContext(request) |
|
63 context['page'] = page |
|
64 |
|
65 offset, limit = helper.lists.cleanListParameters( |
|
66 offset=request.GET.get('offset'), limit=request.GET.get('limit')) |
|
67 |
|
68 # Fetch one more to see if there should be a 'next' link |
|
69 docs = work.logic.getForLimitAndOffset(limit + 1, offset=offset) |
|
70 |
|
71 context['pagination_form'] = helper.lists.makePaginationForm(request, limit) |
|
72 |
|
73 list_templates = { |
|
74 'list_main': templates.get('list_main', |
|
75 'soc/list/list_main.html'), |
|
76 'list_pagination': templates.get('list_pagination', |
|
77 'soc/list/list_pagination.html'), |
|
78 'list_row': templates.get('list_row', |
|
79 'soc/docs/list/docs_row.html'), |
|
80 'list_heading': templates.get('list_heading', |
|
81 'soc/docs/list/docs_heading.html'), |
|
82 } |
|
83 |
|
84 context = helper.lists.setList( |
|
85 request, context, docs, |
|
86 offset=offset, limit=limit, list_templates=list_templates) |
|
87 |
|
88 template = templates.get('all', DEF_DOCS_LIST_ALL_TMPL) |
|
89 return helper.responses.respond(request, template, context) |