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 """Document viewers. |
|
18 |
|
19 public: how the general public sees a Document |
|
20 """ |
|
21 |
|
22 __authors__ = [ |
|
23 '"Todd Larsen" <tlarsen@google.com>', |
|
24 ] |
|
25 |
|
26 |
|
27 from soc.logic import out_of_band |
|
28 from soc.logic import path_link_name |
|
29 from soc.logic.models import document |
|
30 from soc.views import helper |
|
31 from soc.views import simple |
|
32 from soc.views.helper import decorators |
|
33 |
|
34 import soc.views.helper.responses |
|
35 import soc.views.helper.templates |
|
36 |
|
37 |
|
38 DEF_DOCS_PUBLIC_TMPL = 'soc/document/public.html' |
|
39 |
|
40 @decorators.view |
|
41 def public(request, page_name=None, scope_path=None, link_id=None, |
|
42 template=DEF_DOCS_PUBLIC_TMPL): |
|
43 """How the "general public" sees a Document. |
|
44 |
|
45 Args: |
|
46 request: the standard django request object |
|
47 page_name: the page name displayed in templates as page and header title |
|
48 scope_path: the Document's site-unique "path" extracted from the URL, |
|
49 minus the trailing link_id |
|
50 link_id: the last portion of the Document's site-unique "path" |
|
51 extracted from the URL |
|
52 template: the "sibling" template (or a search list of such templates) |
|
53 from which to construct the public.html template name (or names) |
|
54 |
|
55 Returns: |
|
56 A subclass of django.http.HttpResponse which either contains the form to |
|
57 be filled out, or a redirect to the correct view in the interface. |
|
58 """ |
|
59 # create default template context for use with any templates |
|
60 context = helper.responses.getUniversalContext(request) |
|
61 |
|
62 # TODO: there eventually needs to be a call to some controller logic that |
|
63 # implements some sort of access controls, based on the currently |
|
64 # logged-in User's Roles, etc. |
|
65 |
|
66 # TODO: based on the User's Roles, Documents that the User can edit |
|
67 # should display a link to a document edit form |
|
68 |
|
69 doc = None |
|
70 |
|
71 # try to fetch User entity corresponding to link_id if one exists |
|
72 path = path_link_name.combinePath([scope_path, link_id]) |
|
73 |
|
74 # try to fetch Document entity corresponding to path if one exists |
|
75 try: |
|
76 if path: |
|
77 doc = document.logic.getFromFields(scope_path=scope_path, |
|
78 link_id=link_id) |
|
79 except out_of_band.ErrorResponse, error: |
|
80 # show custom 404 page when Document path doesn't exist in Datastore |
|
81 return simple.errorResponse(request, page_name, error, template, context) |
|
82 |
|
83 doc.content = helper.templates.unescape(doc.content) |
|
84 context['entity'] = doc |
|
85 |
|
86 return helper.responses.respond(request, template, context) |
|