app/soc/views/models/presence.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 22 Nov 2008 13:59:34 +0000
changeset 553 c0cc20b4afc9
parent 550 577dbfbeef97
child 554 68c7a1dd3c52
permissions -rw-r--r--
Make redirect generic using the new Lists object This makes it possible (and easier) to have the list view redirect to any page specially tailored to the current item. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
    17
"""Views for Models with a "presence" on a Melange site.
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from google.appengine.ext import db
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from google.appengine.api import users
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from django import forms
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from django.utils.translation import ugettext_lazy
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic import dicts
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from soc.logic import validate
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
    33
from soc.logic.models import document as document_logic
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
from soc.views import helper
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.views.helper import widgets
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
from soc.views.models import base
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
    38
import soc.models.presence
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
    39
import soc.logic.models.presence
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
import soc.logic.dicts
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
import soc.views.helper
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
import soc.views.helper.widgets
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
class SettingsValidationForm(helper.forms.BaseForm):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
  """Django form displayed when creating or editing Settings.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
  
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  This form includes validation functions for Settings fields.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
  """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
513
3c1e16637ad7 Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents: 512
diff changeset
    51
    # TODO(tlarsen): scope_path will be a hard-coded read-only
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    #   field for some (most?) User Roles
513
3c1e16637ad7 Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents: 512
diff changeset
    53
  doc_scope_path = forms.CharField(required=False,
3c1e16637ad7 Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents: 512
diff changeset
    54
      label=ugettext_lazy('Document scope path'),
3c1e16637ad7 Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents: 512
diff changeset
    55
      help_text=soc.models.work.Work.scope_path.help_text)
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
  # TODO(tlarsen): actually, using these two text fields to specify
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
  #   the Document is pretty cheesy; this needs to be some much better
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
  #   Role-scoped Document selector that we don't have yet
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    60
  doc_link_id = forms.CharField(required=False,
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    61
      label=ugettext_lazy('Document link ID'),
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    62
      help_text=soc.models.work.Work.link_id.help_text)
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
  def clean_feed_url(self):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    feed_url = self.cleaned_data.get('feed_url')
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
    if feed_url == '':
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
      # feed url not supplied (which is OK), so do not try to validate it
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
      return None
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
    
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
    if not validate.isFeedURLValid(feed_url):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
      raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
    return feed_url
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
class CreateForm(SettingsValidationForm):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
  """Django form displayed when creating or editing Settings.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
  """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
  class Meta:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
    """Inner Meta class that defines some behavior for the form.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
    #: db.Model subclass for which the form will gather information
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
    85
    model = soc.models.presence.Presence
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
    #: list of model fields which will *not* be gathered by the form
550
577dbfbeef97 Hide the 'scope' property from forms for now, since this is really supposed
Todd Larsen <tlarsen@google.com>
parents: 534
diff changeset
    88
    exclude = ['inheritance_line', 'home', 'scope']
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
class EditForm(CreateForm):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
  """Django form displayed a Document is edited.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    93
  """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
  pass
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
class View(base.View):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 494
diff changeset
    99
  """View methods for the Document model.
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
  """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   102
  def __init__(self, original_params=None):
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
    """Defines the fields and methods required for the base View class
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
    to provide the user with list, public, create, edit and delete views.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
    Params:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
      original_params: a dict with params for this View
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
    params = {}
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
466
ad2908f1646a Fix names typos in home_settings and site_settings modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 452
diff changeset
   112
    params['name'] = "Home Settings"
502
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   113
    params['name_short'] = "Home Settings"
466
ad2908f1646a Fix names typos in home_settings and site_settings modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 452
diff changeset
   114
    params['name_plural'] = "Home Settings"
502
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   115
    params['url_name'] = "home/settings"
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
   116
    params['module_name'] = "presence"
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   117
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
    params['edit_form'] = EditForm
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
    params['create_form'] = CreateForm
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
    # TODO(tlarsen) Add support for Django style template lookup
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
   122
    params['public_template'] = 'soc/presence/public.html'
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
553
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 550
diff changeset
   124
    params['list_row'] = 'soc/presence/list/home_row.html'
c0cc20b4afc9 Make redirect generic using the new Lists object
Sverre Rabbelier <srabbelier@gmail.com>
parents: 550
diff changeset
   125
    params['list_heading'] = 'soc/presence/list/home_heading.html'
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
502
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   127
    params['delete_redirect'] = '/' + params['url_name'] + '/list'
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   129
    params = dicts.merge(original_params, params)
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   131
    base.View.__init__(self, params=params)
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   132
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
   133
    self._logic = soc.logic.models.presence.logic
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
  def _public(self, request, entity, context):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   137
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   138
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   139
    if not entity:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   140
      return
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   141
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   142
    try:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   143
      home_doc = entity.home
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   144
    except db.Error:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   145
      home_doc = None
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   146
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   147
    if home_doc:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   148
      home_doc.content = helper.templates.unescape(home_doc.content)
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   149
      context['home_document'] = home_doc
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   150
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   151
  def _editGet(self, request, entity, form):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   152
    """See base.View._editGet().
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   153
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   154
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   155
    try:
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   156
      if entity.home:
513
3c1e16637ad7 Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents: 512
diff changeset
   157
        form.fields['doc_scope_path'].initial = entity.home.scope_path
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
   158
        form.fields['doc_link_id'].initial = entity.home.link_id
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   159
    except db.Error:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   160
      pass
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   161
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   162
  def _editPost(self, request, entity, fields):
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   163
    """See base.View._editPost().
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   164
    """
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   165
513
3c1e16637ad7 Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents: 512
diff changeset
   166
    doc_scope_path = fields['doc_scope_path']
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
   167
    doc_link_id = fields['doc_link_id']
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   168
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   169
    # TODO notify the user if home_doc is not found
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   170
    home_doc = document_logic.logic.getFromFields(
513
3c1e16637ad7 Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents: 512
diff changeset
   171
    scope_path=doc_scope_path, link_id=doc_link_id)
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   172
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   173
    fields['home'] = home_doc
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   174
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   175
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   176
view = View()
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   177
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   178
create = view.create
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   179
edit = view.edit
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   180
delete = view.delete
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   181
list = view.list
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   182
public = view.public