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 """Base for all (Site, Group, etc.) home page views. |
|
18 |
|
19 public: how the general public sees a "home" page |
|
20 """ |
|
21 |
|
22 __authors__ = [ |
|
23 '"Todd Larsen" <tlarsen@google.com>', |
|
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.home_settings |
|
35 import soc.views.helper.responses |
|
36 import soc.views.helper.templates |
|
37 |
|
38 |
|
39 DEF_HOME_PUBLIC_TMPL = 'soc/home/public.html' |
|
40 |
|
41 @decorators.view |
|
42 def public(request, page_name=None, scope_path=None, link_id=None, |
|
43 entity_type='HomeSettings', |
|
44 template=DEF_HOME_PUBLIC_TMPL): |
|
45 """How the "general public" sees a "home" page. |
|
46 |
|
47 Args: |
|
48 request: the standard django request object. |
|
49 page_name: the page name displayed in templates as page and header title |
|
50 path: path (entire "scoped" portion combined with the link_id) |
|
51 used to retrieve the Group's "home" settings |
|
52 template: the template path to use for rendering the template |
|
53 |
|
54 Returns: |
|
55 A subclass of django.http.HttpResponse with generated template. |
|
56 """ |
|
57 # create default template context for use with any templates |
|
58 context = helper.responses.getUniversalContext(request) |
|
59 |
|
60 settings = models.site_settings.logic.getFromFields( |
|
61 scope_path=scope_path, link_id=link_id) |
|
62 |
|
63 if settings: |
|
64 context['home_settings'] = settings |
|
65 |
|
66 # check if ReferenceProperty to home Document is valid |
|
67 try: |
|
68 home_doc = settings.home |
|
69 except db.Error: |
|
70 home_doc = None |
|
71 |
|
72 if home_doc: |
|
73 home_doc.content = helper.templates.unescape(home_doc.content) |
|
74 context['home_document'] = home_doc |
|
75 |
|
76 return helper.responses.respond(request, template, context=context) |
|