author | Augie Fackler <durin42@gmail.com> |
Sun, 26 Oct 2008 21:36:29 +0000 | |
changeset 423 | 25665d645fa8 |
parent 377 | d94ec6f104cc |
child 445 | 31927f21970d |
permissions | -rw-r--r-- |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
2 |
# |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
4 |
# |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
8 |
# |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
10 |
# |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
16 |
|
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
17 |
"""Base for all (Site, Group, etc.) home page views. |
88
9a8180f0941a
Some additional __doc__ comments (with some ideas for future plans) and removal
Todd Larsen <tlarsen@google.com>
parents:
81
diff
changeset
|
18 |
|
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
19 |
public: how the general public sees a "home" page |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
20 |
""" |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
21 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
22 |
__authors__ = [ |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
23 |
'"Todd Larsen" <tlarsen@google.com>', |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
24 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
25 |
] |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
26 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
27 |
|
314
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
311
diff
changeset
|
28 |
from google.appengine.ext import db |
141
e120c24b89e2
Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
88
diff
changeset
|
29 |
|
309
7190b224c701
Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
305
diff
changeset
|
30 |
from soc.logic import models |
270
7dd6d8347b56
Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents:
249
diff
changeset
|
31 |
from soc.views import helper |
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
32 |
from soc.views.helper import decorators |
314
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
311
diff
changeset
|
33 |
|
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
34 |
import soc.logic.models.home_settings |
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
35 |
import soc.views.helper.responses |
270
7dd6d8347b56
Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents:
249
diff
changeset
|
36 |
import soc.views.helper.templates |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
37 |
|
88
9a8180f0941a
Some additional __doc__ comments (with some ideas for future plans) and removal
Todd Larsen <tlarsen@google.com>
parents:
81
diff
changeset
|
38 |
|
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
39 |
DEF_HOME_PUBLIC_TMPL = 'soc/home/public.html' |
141
e120c24b89e2
Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
88
diff
changeset
|
40 |
|
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
41 |
@decorators.view |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
42 |
def public(request, page=None, path=None, entity_type='HomeSettings', |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
43 |
template=DEF_HOME_PUBLIC_TMPL): |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
44 |
"""How the "general public" sees a "home" page. |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
45 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
46 |
Args: |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
47 |
request: the standard django request object. |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
48 |
page: a soc.logic.site.page.Page object which is abstraction that |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
49 |
combines a Django view with sidebar menu info |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
50 |
path: path (entire "scoped" portion combined with the link_name) |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
51 |
used to retrieve the Group's "home" settings |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
52 |
template: the template path to use for rendering the template. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
53 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
54 |
Returns: |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
55 |
A subclass of django.http.HttpResponse with generated template. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
56 |
""" |
141
e120c24b89e2
Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
88
diff
changeset
|
57 |
# create default template context for use with any templates |
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
58 |
context = helper.responses.getUniversalContext(request) |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
59 |
|
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
60 |
settings = models.home_settings.logic.getFromFields( |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
61 |
path=path, entity_type=entity_type) |
374
9363b9dc2983
Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents:
365
diff
changeset
|
62 |
|
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
63 |
if settings: |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
64 |
context['home_settings'] = settings |
314
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
311
diff
changeset
|
65 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
311
diff
changeset
|
66 |
# check if ReferenceProperty to home Document is valid |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
311
diff
changeset
|
67 |
try: |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
68 |
home_doc = settings.home |
314
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
311
diff
changeset
|
69 |
except db.Error: |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
70 |
home_doc = None |
206
832335761384
Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents:
164
diff
changeset
|
71 |
|
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
72 |
if home_doc: |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
73 |
home_doc.content = helper.templates.unescape(home_doc.content) |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
74 |
context['home_document'] = home_doc |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
75 |
|
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
76 |
return helper.responses.respond(request, template, context=context) |