app/soc/views/models/club_admin.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 24 Jan 2009 10:19:17 +0000
changeset 944 5ea2bd9e3fa6
parent 934 9fcc08971efe
child 952 e087015e09c9
permissions -rw-r--r--
Refactored invite system from club_admin to role to make the system work with host as well. 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
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    26
from django import http
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import forms
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic import cleaning
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
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
    31
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
    32
from soc.logic.models import user as user_logic
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.logic.models import request as request_logic
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    34
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
    35
from soc.views.helper import decorators
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    36
from soc.views.helper import dynaform
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
from soc.views.helper import redirects
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    38
from soc.views.helper import responses
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    39
from soc.views.helper import widgets
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
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
    41
from soc.views.models import role
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
import soc.logic.models.club_admin
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
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
    46
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
    47
  """View methods for the Club Admin model.
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  """
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
  def __init__(self, params=None):
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
    """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
    52
    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
    53
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
    Params:
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
      params: a dict with params for this View
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
    """
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    58
    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
    59
    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
    60
    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
    61
    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
    62
    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
    63
    rights['accept_invite'] = [access.checkCanCreateFromRequest('club_admin')]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    64
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    new_params = {}
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
    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
    67
    new_params['group_logic'] = club_logic.logic
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    68
    new_params['rights'] = rights
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
    new_params['scope_view'] = club_view
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
    new_params['name'] = "Club Admin"
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
925
a85719e94570 Removed club property from club_admin model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 920
diff changeset
    74
    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
    75
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    76
    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
    77
       '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
    78
                                  required=True),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    79
       '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
    80
       '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
    81
       '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
    82
       '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
    83
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
    params = dicts.merge(params, new_params)
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
    super(View, self).__init__(params=params)
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    88
    # 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
    89
    updated_fields = {
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    90
        '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
    91
            required=False)}
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    92
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    93
    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
    94
        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
    95
        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
    96
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    97
    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
    98
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    99
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   100
  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
   101
    """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
   102
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   103
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   104
    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
   105
    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
   106
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   107
    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
   108
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):
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
   111
    """Fills in the fields that were missing in the invited_created_form
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
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   122
acceptInvite = 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
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
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
   129
export = view.export