app/soc/views/models/club_member.py
author Lennard de Rijk <ljvderijk@gmail.com>
Mon, 02 Feb 2009 20:07:52 +0000
changeset 1190 449b9d93d890
parent 1184 bd9c6101d41d
child 1203 38225f2ad3a6
permissions -rw-r--r--
Probably fixed a bug on the live instance. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Club Members.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>'
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from django import forms
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
from soc.logic import dicts
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from soc.logic.models import club as club_logic
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    29
from soc.logic.models import club_admin as club_admin_logic
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.views.helper import access
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.views.helper import dynaform
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.views.helper import widgets
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.views.models import club as club_view
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
from soc.views.models import role
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
import soc.logic.models.club_member
1067
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1030
diff changeset
    37
import soc.logic.models.club_admin
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
class View(role.View):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
  """View methods for the Club Member model.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
  """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
  def __init__(self, params=None):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
    """Defines the fields and methods required for the base View class
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
    to provide the user with list, public, create, edit and delete views.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
    Params:
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
      params: a dict with params for this View
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    52
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    53
    rights['create'] = ['checkIsDeveloper']
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    54
    rights['edit'] = [('checkHasRole', club_admin_logic.logic)]
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    55
    rights['delete'] = ['checkIsDeveloper']
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    56
    rights['invite'] = [('checkHasRole', club_admin_logic.logic)]
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    57
    rights['accept_invite'] = [('checkCanCreateFromRequest','club_member')]
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    58
    rights['request'] = ['checkIsUser',
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    59
                         ('checkCanMakeRequestToGroup', club_logic)]
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    60
    rights['process_request'] = [('checkHasRole', club_admin_logic.logic),
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    61
                                 ('checkCanProcessRequest','club_member')]
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    62
    rights['manage'] = [('checkIsAllowedToManageRole',
1184
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    63
                         [soc.logic.models.club_member.logic,
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    64
                          club_admin_logic.logic])]
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    new_params = {}
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    new_params['logic'] = soc.logic.models.club_member.logic
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params['group_logic'] = club_logic.logic
990
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 980
diff changeset
    69
    new_params['group_view'] = club_view.view
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
    new_params['rights'] = rights
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
    new_params['scope_view'] = club_view
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
    new_params['name'] = "Club Member"
1025
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
    75
    new_params['sidebar_grouping'] = 'Clubs'
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1067
diff changeset
    77
    new_params['extra_dynaexclude'] = ['agreed_to_tos']
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
    new_params['allow_requests_and_invites'] = True
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
    params = dicts.merge(params, new_params)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
    super(View, self).__init__(params=params)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
    85
    # register the role with the group_view
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
    86
    params['group_view'].registerRole(params['module_name'], self)
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
    87
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
    # create and store the special form for invited users
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
    updated_fields = {
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
            required=False)}
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
    invited_create_form = dynaform.extendDynaForm(
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
        dynaform = self._params['create_form'],
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
        dynafields = updated_fields)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
    params['invited_create_form'] = invited_create_form
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
  def _editPost(self, request, entity, fields):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
    """See base.View._editPost().
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
    
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
    if not entity:
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
      fields['user'] = fields['link_id']
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
      fields['link_id'] = fields['user'].link_id
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
    super(View, self)._editPost(request, entity, fields)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
    """Fills in the fields that were missing in the invited_created_form.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
    
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
    For params see base.View._acceptInvitePost()
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
    # fill in the appropriate fields that were missing in the form
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
    fields['user'] = fields['link_id']
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
    fields['link_id'] = fields['user'].link_id
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
view = View()
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
accept_invite = view.acceptInvite
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
create = view.create
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
delete = view.delete
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
edit = view.edit
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
invite = view.invite
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
list = view.list
1067
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1030
diff changeset
   127
manage = view.manage
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
process_request = view.processRequest
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
request = view.request
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   130
public = view.public
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   131
export = view.export