author | Todd Larsen <tlarsen@google.com> |
Wed, 01 Oct 2008 20:52:39 +0000 | |
changeset 251 | 8f23804302d0 |
parent 242 | 17984abf0c74 |
child 270 | 7dd6d8347b56 |
permissions | -rw-r--r-- |
238
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
"""Document viewers. |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
public: how the general public sees a Document |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
""" |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
22 |
__authors__ = [ |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
'"Todd Larsen" <tlarsen@google.com>', |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
] |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
26 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
27 |
from google.appengine.api import users |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
from soc.logic import document |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
from soc.logic import out_of_band |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
31 |
from soc.views import simple |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
from soc.views.helpers import response_helpers |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
33 |
from soc.views.helpers import template_helpers |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
DEF_DOCS_PUBLIC_TMPL = 'soc/docs/public.html' |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
37 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
38 |
def public(request, partial_path=None, linkname=None, |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
39 |
template=DEF_DOCS_PUBLIC_TMPL): |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
40 |
"""How the "general public" sees a Document. |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
Args: |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
request: the standard django request object |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
partial_path: the Document's site-unique "path" extracted from the URL, |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
minus the trailing link_name |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
46 |
link_name: the last portion of the Document's site-unique "path" |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
47 |
extracted from the URL |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
template: the "sibling" template (or a search list of such templates) |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
from which to construct the public.html template name (or names) |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
50 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
Returns: |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
A subclass of django.http.HttpResponse which either contains the form to |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
53 |
be filled out, or a redirect to the correct view in the interface. |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
""" |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
# create default template context for use with any templates |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
context = response_helpers.getUniversalContext(request) |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
|
242
17984abf0c74
Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents:
238
diff
changeset
|
58 |
# TODO: there eventually needs to be a call to some controller logic that |
17984abf0c74
Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents:
238
diff
changeset
|
59 |
# implements some sort of access controls, based on the currently |
17984abf0c74
Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents:
238
diff
changeset
|
60 |
# logged-in User's Roles, etc. |
17984abf0c74
Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents:
238
diff
changeset
|
61 |
|
17984abf0c74
Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents:
238
diff
changeset
|
62 |
# TODO: based on the User's Roles, Documents that the User can edit |
17984abf0c74
Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents:
238
diff
changeset
|
63 |
# should display a link to a document edit form |
17984abf0c74
Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents:
238
diff
changeset
|
64 |
|
238
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
# try to fetch User entity corresponding to linkname if one exists |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
try: |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
doc = document.getDocumentIfPath(partial_path, link_name=linkname) |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
except out_of_band.ErrorResponse, error: |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
# show custom 404 page when Document path doesn't exist in Datastore |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
70 |
return simple.errorResponse(request, error, template, context) |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
71 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
doc.content = template_helpers.unescape(doc.content) |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
73 |
context['document'] = doc |
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
74 |
|
d6b533f99a45
A very simplistic Document viewer.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
75 |
return response_helpers.respond(request, template, context) |