app/soc/views/home.py
author Todd Larsen <tlarsen@google.com>
Sat, 15 Nov 2008 03:12:33 +0000
changeset 481 94834a1e6c01
parent 445 31927f21970d
child 482 839740b061ad
permissions -rw-r--r--
Attempt to rename User.id to User.account, in preparation for making User be derived from Linkable, which will have a property named 'id'. Patch by: Todd Larsen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
    42
def public(request, page=None, partial_path=None, link_name=None, 
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
    43
           entity_type='HomeSettings',
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 374
diff changeset
    44
           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
    45
  """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
    46
58001ec7720c Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
  Args:
58001ec7720c Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
    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
    49
    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
    50
      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
    51
    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
    52
      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
    53
    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
    54
58001ec7720c Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
  Returns:
58001ec7720c Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
    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
    57
  """
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
    58
  # 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
    59
  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
    60
  
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
    61
  settings = models.site_settings.logic.getFromFields(
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
    62
      partial_path=partial_path, link_name=link_name)
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
    63
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 374
diff changeset
    64
  if settings:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 374
diff changeset
    65
    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
    66
    
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
    # 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
    68
    try:
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 374
diff changeset
    69
      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
    70
    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
    71
      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
    72
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 374
diff changeset
    73
    if home_doc:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 374
diff changeset
    74
      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
    75
      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
    76
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 374
diff changeset
    77
  return helper.responses.respond(request, template, context=context)