app/soc/views/models/presence_with_tos.py
author Mario Ferraro <fadinlight@gmail.com>
Sun, 15 Nov 2009 22:12:20 +0100
changeset 3093 d1be59b6b627
parent 2076 1cd180cc56c9
permissions -rw-r--r--
GMaps related JS changed to use new google namespace. Google is going to change permanently in the future the way to load its services, so better stay safe. Also this commit shows uses of the new melange.js module. Fixes Issue 634.
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.utils.translation import ugettext
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    29
from soc.logic import cleaning
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
from soc.logic import dicts
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
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
    32
from soc.views.helper import widgets
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    34
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
    35
import soc.models.work
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
class View(presence.View):
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    39
  """View methods for the PresenceWithToS model.
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
  """
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    42
  def __init__(self, params):
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
    """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
    44
    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
    45
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    Params:
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
      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
    48
    """
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
    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
    51
    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
    52
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
    53
    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
    54
        'tos_link_id': widgets.ReferenceField(
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    55
            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
    56
            filter_fields={'prefix': params['document_prefix']},
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    57
            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
    58
            help_text=soc.models.work.Work.link_id.help_text),
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    59
        'clean': cleaning.clean_refs(params,
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    60
                                     ['home_link_id', 'tos_link_id']),
1051
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
        }
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    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
    64
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    super(View, self).__init__(params=params)
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
  def _editGet(self, request, entity, form):
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
    """See base.View._editGet().
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
    """
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
    try:
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
      if entity.tos:
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
        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
    74
    except db.Error:
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
      pass
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
    super(View, self)._editGet(request, entity, form)
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
  def _editPost(self, request, entity, fields):
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
    """See base.View._editPost().
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
    """
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    83
    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
    84
      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
    85
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    86
    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
    87
    fields['tos'] = tos_doc
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
c532dd9def48 Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
    super(View, self)._editPost(request, entity, fields)