app/soc/views/settings.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 19 Oct 2008 00:34:33 +0000
changeset 387 c55195361cb6
parent 377 d94ec6f104cc
child 390 d12c95ade374
permissions -rw-r--r--
Addressed comments by Todd on r822 Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed
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: 370
diff changeset
    17
"""Home page settings 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: 370
diff changeset
    19
edit: settings view for authorized Developers, Administrators, etc.
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__ = [
58001ec7720c Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    24
  '"Todd Larsen" <tlarsen@google.com>',
79
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
370
36d367e741e2 Replace missing:
Todd Larsen <tlarsen@google.com>
parents: 365
diff changeset
    28
from google.appengine.api import users
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
    29
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
    30
324
05e21c089be6 Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 321
diff changeset
    31
from django import forms
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    32
from django.utils.translation import ugettext_lazy
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
    33
309
7190b224c701 Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 305
diff changeset
    34
from soc.logic import models
249
325fb70c61a9 Replace common module with validate module. Move validation function from feed module to validate module and remove feed.py. Correct any usage of validation functions from common and feed modules into validate module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 225
diff changeset
    35
from soc.logic import validate
309
7190b224c701 Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 305
diff changeset
    36
from soc.logic.models import document
270
7dd6d8347b56 Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents: 249
diff changeset
    37
from soc.views import helper
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
    38
from soc.views.helper import access
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
    39
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
    40
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    41
import soc.logic.models.home_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
    42
import soc.models.document
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    43
import soc.models.home_settings
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    44
import soc.models.work
274
56e1c1721299 Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents: 272
diff changeset
    45
import soc.views.helper.forms
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 271
diff changeset
    46
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
    47
import soc.views.helper.templates
271
01e90bb21b7e Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents: 270
diff changeset
    48
import soc.views.helper.widgets
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
    49
import soc.views.out_of_band
79
58001ec7720c Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
88
9a8180f0941a Some additional __doc__ comments (with some ideas for future plans) and removal
Todd Larsen <tlarsen@google.com>
parents: 81
diff changeset
    51
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    52
class SettingsForm(helper.forms.DbModelForm):
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    53
  """Django form displayed when creating or editing Settings.
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    54
  """
271
01e90bb21b7e Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents: 270
diff changeset
    55
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
    56
  class Meta:
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
    """Inner Meta class that defines some behavior for the form.
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
    """
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
    59
    #: db.Model subclass for which the form will gather information
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    60
    model = soc.models.home_settings.HomeSettings
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
    61
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
    62
    #: list of model fields which will *not* be gathered by the form
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 164
diff changeset
    63
    exclude = ['inheritance_line', 'home']
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 164
diff changeset
    64
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
    65
  def clean_feed_url(self):
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
    66
    feed_url = self.cleaned_data.get('feed_url')
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
    67
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
    68
    if feed_url == '':
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
    69
      # feed url not supplied (which is OK), so do not try to validate it
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
    70
      return None
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
    71
    
249
325fb70c61a9 Replace common module with validate module. Move validation function from feed module to validate module and remove feed.py. Correct any usage of validation functions from common and feed modules into validate module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 225
diff changeset
    72
    if not validate.isFeedURLValid(feed_url):
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
    73
      raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
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
    74
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
    75
    return feed_url
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
    76
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
    77
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    78
class DocSelectForm(helper.forms.DbModelForm):
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    79
  """Django form displayed to select a Document.
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    80
  """
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    81
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    82
  # TODO(tlarsen): partial_path will be a hard-coded read-only
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    83
  #   field for some (most?) User Roles
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    84
  partial_path = forms.CharField(required=False,
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    85
      label=soc.models.work.Work.partial_path.verbose_name,
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    86
      help_text=soc.models.work.Work.partial_path.help_text)
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    87
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    88
  # TODO(tlarsen): actually, using these two text fields to specify
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    89
  #   the Document is pretty cheesy; this needs to be some much better
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    90
  #   Role-scoped Document selector that we don't have yet
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    91
  link_name = forms.CharField(required=False,
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    92
      label=soc.models.work.Work.link_name.verbose_name,
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    93
      help_text=soc.models.work.Work.link_name.help_text)
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    94
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    95
  class Meta:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    96
    model = None
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    97
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    98
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    99
DEF_HOME_EDIT_TMPL = 'soc/settings/edit.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
   100
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
   101
@decorators.view
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   102
def edit(request, page=None, path=None, logic=models.home_settings.logic,
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   103
         template=DEF_HOME_EDIT_TMPL):
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   104
  """View for authorized User to edit contents of a home page.
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
   105
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
   106
  Args:
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
   107
    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: 370
diff changeset
   108
    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: 370
diff changeset
   109
      combines a Django view with sidebar menu info
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
   110
    template: the template path to use for rendering the template.
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
   111
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
   112
  Returns:
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
   113
    A subclass of django.http.HttpResponse with generated template.
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
   114
  """
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   115
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   116
  try:
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   117
    access.checkIsDeveloper(request)
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
   118
  except  soc.views.out_of_band.AccessViolationResponse, alt_response:
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   119
    # TODO(tlarsen): change this to just limit Settings paths that can be
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   120
    #   viewed or modified by the User in their current Role
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   121
    return alt_response.response()
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   122
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
   123
  # 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
   124
  context = helper.responses.getUniversalContext(request)
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   125
  context['page'] = page
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   126
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
   127
  settings_form = None
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   128
  doc_select_form = None
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   129
  home_doc = None
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
   130
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
   131
  if request.method == 'POST':
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   132
    settings_form = SettingsForm(request.POST)
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   133
    doc_select_form = DocSelectForm(request.POST)
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   134
    
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   135
    if doc_select_form.is_valid() and settings_form.is_valid():
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   136
      fields = {'feed_url': settings_form.cleaned_data.get('feed_url')}
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   137
      partial_path = doc_select_form.cleaned_data.get('partial_path')
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   138
      link_name = doc_select_form.cleaned_data.get('link_name')
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   139
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   140
      home_doc = document.logic.getFromFields(
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   141
          partial_path=partial_path, link_name=link_name)
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 294
diff changeset
   142
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   143
      if home_doc:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   144
        fields['home'] = home_doc
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   145
        context['notice'] = ugettext_lazy('Settings saved.')
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   146
      else:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   147
        context['notice'] = ugettext_lazy('Document not specified or could not be found; other Settings saved.')
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
   148
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   149
      settings = logic.updateOrCreateFromFields(fields, path=path)
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
   150
      
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   151
      if settings.home:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   152
        home_doc = settings.home
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
   153
  else: # request.method == 'GET'
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   154
    # try to fetch HomeSettings entity by unique key_name
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   155
    settings = logic.getFromFields(path=path)
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
   156
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   157
    if settings:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   158
      # populate form with the existing HomeSettings entity
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   159
      settings_form = SettingsForm(instance=settings)
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   160
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
   161
      # 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
   162
      try:
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   163
        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
   164
      except db.Error:
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   165
        pass
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
   166
    
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   167
      if home_doc:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   168
        doc_select_form = DocSelectForm(initial={
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   169
            'partial_path': home_doc.partial_path,
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   170
            'link_name': home_doc.link_name})
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   171
      else:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   172
        doc_select_form = DocSelectForm()
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
   173
    else:
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 164
diff changeset
   174
      # no SiteSettings entity exists for this key_name, so show a blank form
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   175
      settings_form = SettingsForm()
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   176
      doc_select_form = DocSelectForm()
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
   177
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   178
  context.update({'settings_form': settings_form,
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   179
                  'doc_select_form': doc_select_form,
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   180
                  'home_doc': home_doc})
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
   181
  
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   182
  return helper.responses.respond(request, template, context)