app/soc/views/models/club.py
author Todd Larsen <tlarsen@google.com>
Tue, 20 Jan 2009 22:30:21 +0000
changeset 854 bb43b74c58f6
parent 846 65daaf006399
child 858 e79e7a22326f
permissions -rw-r--r--
A better way to add site-wide ToS link to *all* pages on the site. getUniversalContext() already fetches a copy of the Site settings, so use that to see if the site-wide ToS exist and produce a link. Patch by: Todd Larsen Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
782
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Clubs.
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
800
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
782
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
  ]
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
from google.appengine.api import users
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from django import forms
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.logic import dicts
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.logic.models import user as user_logic
800
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    32
from soc.logic.models import group_app as group_app_logic
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    33
from soc.logic.models import club as club_logic
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 800
diff changeset
    34
from soc.views.helper import access
782
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
from soc.views.helper import widgets
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
from soc.views.models import base
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
import soc.logic.models.club
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
class View(base.View):
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
  """View methods for the Club model.
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
  """
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
  def __init__(self, params=None):
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
    """Defines the fields and methods required for the base View class
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
    to provide the user with list, public, create, edit and delete views.
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    Params:
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
      params: a dict with params for this View
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    """
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 800
diff changeset
    53
    rights = {}
814
25ffebd9fa8f Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents: 802
diff changeset
    54
    rights['create'] = [access.checkIsClubAppAccepted]
25ffebd9fa8f Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents: 802
diff changeset
    55
    rights['edit'] = [access.checkIsClubAdminForClub]
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 800
diff changeset
    56
782
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    new_params = {}
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    new_params['logic'] = soc.logic.models.club.logic
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 800
diff changeset
    59
    new_params['rights'] = rights
782
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    new_params['name'] = "Club"
799
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 790
diff changeset
    62
846
65daaf006399 Remove member_template from extra_dynaexclude in soc.views.models.club since member_template is only available in Organization as of recent commit.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 814
diff changeset
    63
    new_params['extra_dynaexclude'] = ['founder', 'home']
782
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
    new_params['edit_extra_dynafields'] = {
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
        'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(),
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
                                   required=False),
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
        }
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
814
25ffebd9fa8f Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents: 802
diff changeset
    69
    new_params['edit_redirect'] = '/notification/list'
25ffebd9fa8f Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents: 802
diff changeset
    70
782
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
    params = dicts.merge(params, new_params)
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    super(View, self).__init__(params=params)
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
800
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    75
  def create(self, request, access_type,
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    76
             page_name=None, params=None, **kwargs):
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    77
    """See base.View.create()
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    78
    """
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    79
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    80
    if 'link_id' not in kwargs:
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    81
      return super(View, self).create(request, access_type, page_name,
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    82
                                      params=params, **kwargs)
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    83
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    84
    # Find their application
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    85
    key_fields = group_app_logic.logic.getKeyFieldsFromDict(kwargs)
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    86
    application = group_app_logic.logic.getFromFields(**key_fields)
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    87
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    88
    # Extract the application fields
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    89
    field_names = application.properties().keys()
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    90
    fields = dict( [(i, getattr(application, i)) for i in field_names] )
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    91
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    92
    empty = dict( [(i, None) for i in self._logic.getKeyFieldNames()] )
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    93
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    94
    return super(View, self).edit(request, access_type, page_name,
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    95
                                  params=params, seed=fields, **empty)
738f6335b0e2 Added a create method that uses an existing application
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
    96
782
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
  def _editGet(self, request, entity, form):
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
    """See base.View._editGet().
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
    """
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
    # fill in the founded_by with data from the entity
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
    form.fields['founded_by'].initial = entity.founder.name
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
    super(View, self)._editGet(request, entity, form)
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
  def _editPost(self, request, entity, fields):
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
    """See base.View._editPost().
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
    """
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
    if not entity:
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
      # only if we are creating a new entity we should fill in founder
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
      account = users.get_current_user()
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
      user = user_logic.logic.getForFields({'account': account}, unique=True)
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
      fields['founder'] = user
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
    super(View, self)._editPost(request, entity, fields)
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
view = View()
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
create = view.create
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
delete = view.delete
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
edit = view.edit
27924b0f13cd Fixed missing files in r1364.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
list = view.list
814
25ffebd9fa8f Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents: 802
diff changeset
   123
public = view.public