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 """Site-wide Melange home page views. |
|
18 |
|
19 public: how the general public sees the site home page of a Melange |
|
20 site |
|
21 """ |
|
22 |
|
23 __authors__ = [ |
|
24 '"Pawel Solyga" <pawel.solyga@gmail.com>', |
|
25 ] |
|
26 |
|
27 |
|
28 from google.appengine.ext import db |
|
29 |
|
30 from soc.logic import models |
|
31 from soc.views import helper |
|
32 from soc.views.helper import decorators |
|
33 |
|
34 import soc.logic.models.site_settings |
|
35 import soc.views.helper.responses |
|
36 import soc.views.helper.templates |
|
37 |
|
38 |
|
39 DEF_SITE_HOME_PUBLIC_TMPL = 'soc/site/home/public.html' |
|
40 |
|
41 @decorators.view |
|
42 def public(request, page=None, template=DEF_SITE_HOME_PUBLIC_TMPL): |
|
43 """How the "general public" sees the Melange site home page. |
|
44 |
|
45 Args: |
|
46 request: the standard django request object. |
|
47 page: a soc.logic.site.page.Page object which is abstraction that combines |
|
48 a Django view with sidebar menu info |
|
49 template: the template path to use for rendering the template. |
|
50 |
|
51 Returns: |
|
52 A subclass of django.http.HttpResponse with generated template. |
|
53 """ |
|
54 # create default template context for use with any templates |
|
55 context = helper.responses.getUniversalContext(request) |
|
56 context['page'] = page |
|
57 |
|
58 site_settings = models.site_settings.logic.getFromFields( |
|
59 path=models.site_settings.logic.DEF_SITE_SETTINGS_PATH) |
|
60 |
|
61 if site_settings: |
|
62 context['site_settings'] = site_settings |
|
63 |
|
64 # check if ReferenceProperty to home Document is valid |
|
65 try: |
|
66 site_doc = site_settings.home |
|
67 except db.Error: |
|
68 site_doc = None |
|
69 |
|
70 if site_doc: |
|
71 site_doc.content = helper.templates.unescape(site_doc.content) |
|
72 context['site_document'] = site_doc |
|
73 |
|
74 return helper.responses.respond(request, template, context=context) |
|