app/soc/views/models/club_admin.py
author Lennard de Rijk <ljvderijk@gmail.com>
Mon, 26 Jan 2009 09:44:00 +0000
changeset 998 125257161908
parent 990 fd1e6afb2d62
child 1007 3b66772d21a5
permissions -rw-r--r--
Implemented the listing of all the roles in for a specific group. Removed a TODO about removing the tolist assignment in soc/views/models/host.py because this list is now obsolete. Added a TODO to change the redirect of the member listing once the manage page is done. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Views for Club Admins.
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>'
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from django import forms
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.logic import cleaning
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    30
from soc.logic.models import club as club_logic
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    31
from soc.views.helper import access
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    32
from soc.views.helper import dynaform
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    33
from soc.views.helper import widgets
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
from soc.views.models import club as club_view
944
5ea2bd9e3fa6 Refactored invite system from club_admin to role to make the system work with host as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
    35
from soc.views.models import role
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
import soc.logic.models.club_admin
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
944
5ea2bd9e3fa6 Refactored invite system from club_admin to role to make the system work with host as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
    40
class View(role.View):
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    41
  """View methods for the Club Admin model.
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
  """
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  def __init__(self, params=None):
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
    """Defines the fields and methods required for the base View class
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    to provide the user with list, public, create, edit and delete views.
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
    Params:
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
      params: a dict with params for this View
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
    """
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    52
    rights = {}
944
5ea2bd9e3fa6 Refactored invite system from club_admin to role to make the system work with host as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
    53
    rights['create'] = [access.checkIsDeveloper]
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    54
    rights['edit'] = [access.checkIsMyActiveRole(soc.logic.models.club_admin)]
944
5ea2bd9e3fa6 Refactored invite system from club_admin to role to make the system work with host as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
    55
    rights['delete'] = [access.checkIsDeveloper]
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    56
    rights['invite'] = [access.checkIsClubAdminForClub]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    57
    rights['accept_invite'] = [access.checkCanCreateFromRequest('club_admin')]
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 958
diff changeset
    58
    rights['process_request'] = [access.checkIsClubAdminForClub,
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 958
diff changeset
    59
        access.checkCanProcessRequest('club_admin')]
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    60
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
    new_params = {}
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
    new_params['logic'] = soc.logic.models.club_admin.logic
944
5ea2bd9e3fa6 Refactored invite system from club_admin to role to make the system work with host as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
    63
    new_params['group_logic'] = club_logic.logic
990
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 968
diff changeset
    64
    new_params['group_view'] = club_view.view
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    65
    new_params['rights'] = rights
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
    new_params['scope_view'] = club_view
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
    new_params['name'] = "Club Admin"
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
925
a85719e94570 Removed club property from club_admin model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 920
diff changeset
    71
    new_params['extra_dynaexclude'] = ['user', 'state']
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    72
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    73
    new_params['create_extra_dynafields'] = {
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    74
       'scope_path': forms.CharField(widget=forms.HiddenInput,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    75
                                  required=True),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    76
       'clean_link_id' : cleaning.clean_existing_user('link_id'),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    77
       'clean_home_page' : cleaning.clean_url('home_page'),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    78
       'clean_blog' : cleaning.clean_url('blog'),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    79
       'clean_photo_url' : cleaning.clean_url('photo_url')}
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
963
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    81
    new_params['allow_invites'] = True
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    82
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    params = dicts.merge(params, new_params)
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
    super(View, self).__init__(params=params)
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
    87
    # 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
    88
    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
    89
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    90
    # create and store the special form for invited users
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    91
    updated_fields = {
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    92
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    93
            required=False)}
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    94
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    95
    invited_create_form = dynaform.extendDynaForm(
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    96
        dynaform = self._params['create_form'],
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    97
        dynafields = updated_fields)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    98
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    99
    params['invited_create_form'] = invited_create_form
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   100
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   101
  def _editPost(self, request, entity, fields):
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   102
    """See base.View._editPost().
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   103
    """
968
8177ddc9ea35 Fixed a bug in _editPost for club_admin and host.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 963
diff changeset
   104
    if not entity:
8177ddc9ea35 Fixed a bug in _editPost for club_admin and host.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 963
diff changeset
   105
      fields['user'] = fields['link_id']
8177ddc9ea35 Fixed a bug in _editPost for club_admin and host.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 963
diff changeset
   106
      fields['link_id'] = fields['user'].link_id
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   107
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   108
    super(View, self)._editPost(request, entity, fields)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   109
944
5ea2bd9e3fa6 Refactored invite system from club_admin to role to make the system work with host as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
   110
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
958
b4309e3cb899 Fix some missing dots in access and club_admin modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   111
    """Fills in the fields that were missing in the invited_created_form.
944
5ea2bd9e3fa6 Refactored invite system from club_admin to role to make the system work with host as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
   112
    
5ea2bd9e3fa6 Refactored invite system from club_admin to role to make the system work with host as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
   113
    For params see base.View._acceptInvitePost()
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   114
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   115
    # fill in the appropriate fields that were missing in the form
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   116
    fields['user'] = fields['link_id']
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   117
    fields['link_id'] = fields['user'].link_id
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   118
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
view = View()
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
952
e087015e09c9 Rename acceptInvite view variable to accept_invite to comply to our style guide. Remove unused imports. Add missing blank lines in soc.views.models.club_admin module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
   122
accept_invite = view.acceptInvite
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
create = view.create
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
delete = view.delete
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
edit = view.edit
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   126
invite = view.invite
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
list = view.list
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 958
diff changeset
   128
process_request = view.processRequest
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
public = view.public
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 802
diff changeset
   130
export = view.export