app/soc/views/models/club_member.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 08 Mar 2009 13:14:28 +0000
changeset 1741 0da1285f5bc0
parent 1662 1ccf04cbca15
child 2018 c584eb2f57db
permissions -rw-r--r--
Public reviews are now shown on the public page for the student proposal. The assigned mentor name has been removed from the public page. The student proposal view now uses the new getReviewsForEntity method. 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
#
1307
091a21cf3627 Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
     3
# Copyright 2009 the Melange authors.
980
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
1583
1e4c785f1adf Added decorators
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    31
from soc.views.helper import decorators
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.views.helper import dynaform
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.views.helper import widgets
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
from soc.views.models import club as club_view
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
from soc.views.models import role
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
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
    38
import soc.logic.models.club_admin
980
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
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
class View(role.View):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
  """View methods for the Club Member model.
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
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
  def __init__(self, params=None):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
    """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
    47
    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
    48
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    Params:
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
      params: a dict with params for this View
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    53
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    54
    rights['create'] = ['checkIsDeveloper']
1248
f318538394d9 Rename checkHasActiveRole to checkHasActiveRoleForScope
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1203
diff changeset
    55
    rights['edit'] = [('checkHasActiveRoleForScope', club_admin_logic.logic)]
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    56
    rights['delete'] = ['checkIsDeveloper']
1248
f318538394d9 Rename checkHasActiveRole to checkHasActiveRoleForScope
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1203
diff changeset
    57
    rights['invite'] = [('checkHasActiveRoleForScope', club_admin_logic.logic)]
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    58
    rights['accept_invite'] = [('checkCanCreateFromRequest','club_member')]
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    59
    rights['request'] = ['checkIsUser',
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    60
                         ('checkCanMakeRequestToGroup', club_logic)]
1662
1ccf04cbca15 Fix too long lines soc.views.models.club_admin, club_app and club_member modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
    61
    rights['process_request'] = [('checkHasActiveRoleForScope', 
1ccf04cbca15 Fix too long lines soc.views.models.club_admin, club_app and club_member modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
    62
                                  club_admin_logic.logic),
1ccf04cbca15 Fix too long lines soc.views.models.club_admin, club_app and club_member modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
    63
                                  ('checkCanProcessRequest','club_member')]
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1116
diff changeset
    64
    rights['manage'] = [('checkIsAllowedToManageRole',
1184
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    65
                         [soc.logic.models.club_member.logic,
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    66
                          club_admin_logic.logic])]
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params = {}
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
    new_params['logic'] = soc.logic.models.club_member.logic
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
    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
    71
    new_params['group_view'] = club_view.view
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
    new_params['rights'] = rights
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['scope_view'] = club_view
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
    new_params['name'] = "Club Member"
1025
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
    77
    new_params['sidebar_grouping'] = 'Clubs'
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1067
diff changeset
    79
    new_params['extra_dynaexclude'] = ['agreed_to_tos']
980
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
    new_params['allow_requests_and_invites'] = True
1384
bb22ea156567 Role overview membership is now determined by setting show_in_roles_overview param to true in the view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1343
diff changeset
    82
    new_params['show_in_roles_overview'] = False
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
    params = dicts.merge(params, new_params)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
    super(View, self).__init__(params=params)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
    88
    # 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
    89
    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
    90
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
    # create and store the special form for invited users
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
    updated_fields = {
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
            required=False)}
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
    invited_create_form = dynaform.extendDynaForm(
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
        dynaform = self._params['create_form'],
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1384
diff changeset
    98
        dynaproperties = updated_fields)
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
    params['invited_create_form'] = invited_create_form
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
  def _editPost(self, request, entity, fields):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
    """See base.View._editPost().
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
    
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
    if not entity:
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
      fields['user'] = fields['link_id']
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
      fields['link_id'] = fields['user'].link_id
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
    super(View, self)._editPost(request, entity, fields)
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
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
    """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
   114
    
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
    For params see base.View._acceptInvitePost()
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
    # 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
   118
    fields['user'] = fields['link_id']
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
    fields['link_id'] = fields['user'].link_id
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
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
view = View()
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   124
accept_invite = decorators.view(view.acceptInvite)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   125
admin = decorators.view(view.admin)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   126
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   127
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   128
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   129
invite = decorators.view(view.invite)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   130
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   131
manage = decorators.view(view.manage)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   132
process_request = decorators.view(view.processRequest)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   133
request = decorators.view(view.request)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   134
public = decorators.view(view.public)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   135
export = decorators.view(view.export)