app/soc/views/models/presence_with_tos.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 22 Mar 2009 22:54:14 +0000
changeset 1991 3aeda3007467
parent 1700 599a5ff8f422
child 2076 1cd180cc56c9
permissions -rw-r--r--
Make _public return True iff public page should be shown If the public page should not be shown, and 'public_redirect' is set, a redirect to 'public_redirect' will be returned. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1307
091a21cf3627 Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1303
diff changeset
     3
# Copyright 2009 the Melange authors.
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    17
"""Views for PresenceWithToS.
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from google.appengine.ext import db
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import forms
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from django.utils.translation import ugettext
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    30
from soc.logic import cleaning
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic import dicts
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from soc.logic.models import document as document_logic
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.views.models import presence
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    34
from soc.views.helper import widgets
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    36
import soc.logic.models.presence_with_tos
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
import soc.models.work
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
class View(presence.View):
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    41
  """View methods for the PresenceWithToS model.
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
  """
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    44
  def __init__(self, params):
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
    """Defines the fields and methods required for the base View class
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    to provide the user with list, public, create, edit and delete views.
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
    Params:
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
      params: a dict with params for this View
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
    """
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    new_params = {}
1256
375632e7ec21 Put the tos extra_dynaexclude in presence_with_tos.py where it belongs.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
    53
    new_params['extra_dynaexclude'] = ['tos']
375632e7ec21 Put the tos extra_dynaexclude in presence_with_tos.py where it belongs.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
    54
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
    55
    new_params['edit_extra_dynaproperties'] = {
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    56
        'tos_link_id': widgets.ReferenceField(
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    57
            reference_url='document', filter=['scope_path'], required=False,
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    58
            filter_fields={'prefix': params['document_prefix']},
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    59
            label=ugettext('Terms of Service Document link ID'),
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
            help_text=soc.models.work.Work.link_id.help_text),
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    61
        'clean': cleaning.clean_refs(params,
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    62
                                     ['home_link_id', 'tos_link_id']),
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
        }
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    params = dicts.merge(params, new_params, sub_merge=True)
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
    super(View, self).__init__(params=params)
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
  def _editGet(self, request, entity, form):
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
    """See base.View._editGet().
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
    """
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
    try:
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
      if entity.tos:
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
        form.fields['tos_link_id'].initial = entity.tos.link_id
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
    except db.Error:
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
      pass
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
    super(View, self)._editGet(request, entity, form)
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
  def _editPost(self, request, entity, fields):
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
    """See base.View._editPost().
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    """
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    85
    if 'tos_link_id' not in fields:
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    86
      return super(View, self)._editPost(request, entity, fields)
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    87
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    88
    tos_doc = fields.get('resolved_tos_link_id')
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
    fields['tos'] = tos_doc
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
    super(View, self)._editPost(request, entity, fields)