|
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 google.appengine.api import users |
|
28 |
|
29 from soc.logic import document |
|
30 from soc.logic import out_of_band |
|
31 from soc.views import simple |
|
32 from soc.views.helpers import response_helpers |
|
33 from soc.views.helpers import template_helpers |
|
34 |
|
35 |
|
36 DEF_DOCS_PUBLIC_TMPL = 'soc/docs/public.html' |
|
37 |
|
38 def public(request, partial_path=None, linkname=None, |
|
39 template=DEF_DOCS_PUBLIC_TMPL): |
|
40 """How the "general public" sees a Document. |
|
41 |
|
42 Args: |
|
43 request: the standard django request object |
|
44 partial_path: the Document's site-unique "path" extracted from the URL, |
|
45 minus the trailing link_name |
|
46 link_name: the last portion of the Document's site-unique "path" |
|
47 extracted from the URL |
|
48 template: the "sibling" template (or a search list of such templates) |
|
49 from which to construct the public.html 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 # create default template context for use with any templates |
|
56 context = response_helpers.getUniversalContext(request) |
|
57 |
|
58 # try to fetch User entity corresponding to linkname if one exists |
|
59 try: |
|
60 doc = document.getDocumentIfPath(partial_path, link_name=linkname) |
|
61 except out_of_band.ErrorResponse, error: |
|
62 # show custom 404 page when Document path doesn't exist in Datastore |
|
63 return simple.errorResponse(request, error, template, context) |
|
64 |
|
65 doc.content = template_helpers.unescape(doc.content) |
|
66 context['document'] = doc |
|
67 |
|
68 return response_helpers.respond(request, template, context) |