app/soc/views/settings.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Sun, 19 Oct 2008 16:17:32 +0000
changeset 390 d12c95ade374
parent 377 d94ec6f104cc
child 405 f3525c1288ed
permissions -rw-r--r--
Remove unused imports, fix too long lines and indentions. Patch by: Pawel Solyga Review 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
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
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
    30
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
    31
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
    32
309
7190b224c701 Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 305
diff changeset
    33
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
    34
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
    35
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
    36
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
    37
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
    38
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
    39
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    40
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
    41
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
    42
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
    43
import soc.models.work
274
56e1c1721299 Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents: 272
diff changeset
    44
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
    45
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
    46
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
    47
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
    48
import soc.views.out_of_band
79
58001ec7720c Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
88
9a8180f0941a Some additional __doc__ comments (with some ideas for future plans) and removal
Todd Larsen <tlarsen@google.com>
parents: 81
diff changeset
    50
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    51
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
    52
  """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
    53
  """
271
01e90bb21b7e Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents: 270
diff changeset
    54
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
    55
  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
    56
    """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
    57
    """
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
    #: 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
    59
    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
    60
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
    61
    #: 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
    62
    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
    63
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
    64
  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
    65
    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
    66
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
    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
    68
      # 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
    69
      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
    70
    
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
    71
    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
    72
      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
    73
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
    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
    75
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
    76
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    77
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
    78
  """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
    79
  """
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
  # 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
    82
  #   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
    83
  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
    84
      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
    85
      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
    86
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    87
  # 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
    88
  #   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
    89
  #   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
    90
  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
    91
      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
    92
      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
    93
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    94
  class Meta:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    95
    model = None
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
    96
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
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
    99
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
   100
@decorators.view
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   101
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
   102
         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
   103
  """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
   104
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
  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
   106
    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
   107
    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
   108
      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
   109
    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
   110
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
  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
   112
    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
   113
  """
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   114
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   115
  try:
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   116
    access.checkIsDeveloper(request)
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
   117
  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
   118
    # 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
   119
    #   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
   120
    return alt_response.response()
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   121
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
   122
  # 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
   123
  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
   124
  context['page'] = page
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   125
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
   126
  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
   127
  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
   128
  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
   129
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
  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
   131
    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
   132
    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
   133
    
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   134
    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
   135
      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
   136
      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
   137
      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
   138
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   139
      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
   140
          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
   141
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   142
      if home_doc:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   143
        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
   144
        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
   145
      else:
390
d12c95ade374 Remove unused imports, fix too long lines and indentions.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 377
diff changeset
   146
        context['notice'] = ugettext_lazy(
d12c95ade374 Remove unused imports, fix too long lines and indentions.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 377
diff changeset
   147
            'Document not specified or could not be found; ' \
d12c95ade374 Remove unused imports, fix too long lines and indentions.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 377
diff changeset
   148
            '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
   149
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   150
      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
   151
      
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   152
      if settings.home:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   153
        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
   154
  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
   155
    # 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
   156
    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
   157
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   158
    if settings:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   159
      # 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
   160
      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
   161
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
   162
      # 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
   163
      try:
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   164
        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
   165
      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
   166
        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
   167
    
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   168
      if home_doc:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   169
        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
   170
            '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
   171
            '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
   172
      else:
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   173
        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
   174
    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
   175
      # 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
   176
      settings_form = SettingsForm()
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   177
      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
   178
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   179
  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
   180
                  '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
   181
                  '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
   182
  
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 370
diff changeset
   183
  return helper.responses.respond(request, template, context)