app/soc/views/models/club_admin.py
author Sverre Rabbelier <srabbelier@gmail.com>
Fri, 23 Jan 2009 21:20:33 +0000
changeset 935 09f47e08f805
parent 934 9fcc08971efe
child 944 5ea2bd9e3fa6
permissions -rw-r--r--
Adust the as_table tag to render a pick link if appropriate The templates are adjusted to pass on a 'reference' value, which is the url_name of the view from which the entity should be picked. The as_table (and related) function(s) construct and then pass on this argument and enable takes_contex so that we have access to the context of the enclosing template. We only extract ReferenceProperties that end with '_link_id' since that is how all RP's are currently named. It is not possible to create a field with the same name as the RP, as GAE will try to interpret it's contents as the key of an entity before even calling any function we can override. Patch by: Sverre Rabbelier
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 base
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
from soc.views.models import club as club_view
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    42
from soc.views.models import request as request_view
802
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
import soc.logic.models.club_admin
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
class View(base.View):
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    48
  """View methods for the Club Admin model.
802
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
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
  def __init__(self, params=None):
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    """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
    53
    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
    54
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
    Params:
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
      params: a dict with params for this View
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
    """
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    59
    rights = {}
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    60
    rights['create'] = [access.checkIsHost]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    61
    rights['edit'] = [access.checkIsMyActiveRole(soc.logic.models.club_admin)]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    62
    rights['delete'] = [access.checkIsHost]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    63
    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
    64
    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
    65
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
    new_params = {}
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
    new_params['logic'] = soc.logic.models.club_admin.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
    new_params['scope_redirect'] = redirects.getCreateRedirect
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
    new_params['name'] = "Club Admin"
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
925
a85719e94570 Removed club property from club_admin model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 920
diff changeset
    75
    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
    76
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    77
    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
    78
       '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
    79
                                  required=True),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    80
       '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
    81
       '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
    82
       '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
    83
       '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
    84
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    85
    patterns = [(r'^%(url_name)s/(?P<access_type>invite)/%(lnp)s$',
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    86
        'soc.views.models.%(module_name)s.invite',
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    87
        'Create invite for %(name_plural)s'),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    88
        (r'^%(url_name)s/(?P<access_type>accept_invite)/%(scope)s/%(lnp)s$',
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    89
        'soc.views.models.%(module_name)s.acceptInvite',
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    90
        'Accept invite for %(name_plural)s')]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    91
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    92
    new_params['extra_django_patterns'] = patterns
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    93
    
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
    params = dicts.merge(params, new_params)
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
    super(View, self).__init__(params=params)
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    98
    # 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
    99
    updated_fields = {
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   100
        '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
   101
            required=False)}
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
    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
   104
        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
   105
        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
   106
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   107
    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
   108
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   109
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   110
  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
   111
    """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
   112
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   113
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   114
    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
   115
    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
   116
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   117
    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
   118
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   119
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   120
  @decorators.merge_params
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   121
  @decorators.check_access
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   122
  def acceptInvite(self, request, access_type,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   123
                   page_name=None, params=None, **kwargs):
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   124
    """Creates the page process an invite into a Club Admin.
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   125
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   126
    Args:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   127
      request: the standard Django HTTP request object
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   128
      access_type : the name of the access type which should be checked
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   129
      context: dictionary containing the context for this view
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   130
      params: a dict with params for this View
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   131
      kwargs: the Key Fields for the specified entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   132
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   133
  
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   134
     # get the context for this webpage
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   135
    context = responses.getUniversalContext(request)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   136
    context['page_name'] = page_name
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   137
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   138
    if request.method == 'POST':
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   139
      return self.acceptInvitePost(request, context, params, **kwargs)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   140
    else:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   141
      # request.method == 'GET'
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   142
      return self.acceptInviteGet(request, context, params, **kwargs)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   143
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   144
  def acceptInviteGet(self, request, context, params, **kwargs):
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   145
    """Handles the GET request concerning the creation of a Club Admin via an
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   146
    invite.
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   147
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   148
    Args:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   149
      request: the standard Django HTTP request object
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   150
      context: dictionary containing the context for this view
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   151
      params: a dict with params for this View
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   152
      kwargs: the Key Fields for the specified entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   153
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   154
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   155
    # create the form using the scope_path and link_id from kwargs as initial value
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   156
    fields = {'link_id' : kwargs['link_id'],
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   157
              'scope_path' : kwargs['scope_path']}
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   158
    form = params['invited_create_form'](initial=fields)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   159
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   160
    # construct the appropriate response
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   161
    return super(View, self)._constructResponse(request, entity=None,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   162
        context=context, form=form, params=params)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   163
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   164
  def acceptInvitePost(self, request, context, params, **kwargs):
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   165
    """Handles the POST request concerning the creation of a Club Admin via an
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   166
    invite.
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   167
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   168
    Args:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   169
      request: the standard Django HTTP request object
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   170
      context: dictionary containing the context for this view
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   171
      params: a dict with params for this View
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   172
      kwargs: the Key Fields for the specified entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   173
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   174
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   175
    # populate the form using the POST data
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   176
    form = params['invited_create_form'](request.POST)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   177
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   178
    if not form.is_valid():
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   179
      # return the invalid form response
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   180
      return self._constructResponse(request, entity=None, context=context,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   181
          form=form, params=params)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   182
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   183
    # collect the cleaned data from the valid form
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   184
    key_name, fields = soc.views.helper.forms.collectCleanedFields(form)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   185
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   186
    # 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
   187
    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
   188
    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
   189
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   190
    club = club_logic.logic.getFromKeyName(fields['scope_path'])
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   191
    fields['scope'] = club
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   192
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   193
    # make sure that this role becomes active once more in case this user
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   194
    # has been reinvited
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   195
    fields ['state'] = 'active'
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   196
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   197
    # get the key_name for the new entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   198
    key_fields =  self._logic.getKeyFieldsFromDict(fields)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   199
    key_name = self._logic.getKeyNameForFields(key_fields)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   200
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   201
    # create new Club Admin entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   202
    entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   203
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   204
    # redirect to the roles overview page
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   205
    return http.HttpResponseRedirect('/user/roles')
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   206
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   207
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   208
  @decorators.merge_params
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   209
  @decorators.check_access
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   210
  def invite(self, request, access_type,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   211
                   page_name=None, params=None, **kwargs):
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   212
    """Creates the page upon which a Club Admin can invite another Club Admin.
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   213
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   214
    Args:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   215
      request: the standard Django HTTP request object
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   216
      access_type : the name of the access type which should be checked
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   217
      context: dictionary containing the context for this view
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   218
      params: a dict with params for this View
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   219
      kwargs: the Key Fields for the specified entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   220
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   221
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   222
    # get the context for this webpage
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   223
    context = responses.getUniversalContext(request)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   224
    context['page_name'] = page_name
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   225
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   226
    if request.method == 'POST':
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   227
      return self.invitePost(request, context, params, **kwargs)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   228
    else:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   229
      # request.method == 'GET'
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   230
      return self.inviteGet(request, context, params, **kwargs)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   231
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   232
  def inviteGet(self, request, context, params, **kwargs):
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   233
    """Handles the GET request concerning the view that creates an invite
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   234
    for becoming a Club Admin.
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   235
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   236
    Args:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   237
      request: the standard Django HTTP request object
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   238
      page_name: the page name displayed in templates as page and header title
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   239
      params: a dict with params for this View
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   240
      kwargs: the Key Fields for the specified entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   241
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   242
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   243
    # set the role to the right name
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   244
    fields = {'role' : '%(module_name)s' %(params)}
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   245
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   246
    # get the request view parameters and initialize the create form
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   247
    request_params = request_view.view.getParams()
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   248
    form = request_params['create_form'](initial=fields)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   249
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   250
    # construct the appropriate response
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   251
    return super(View, self)._constructResponse(request, entity=None,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   252
        context=context, form=form, params=params)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   253
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   254
  def invitePost(self, request, context, params, **kwargs):
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   255
    """Handles the POST request concerning the view that creates an invite
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   256
    for becoming a Club Admin.
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   257
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   258
    Args:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   259
      request: the standard Django HTTP request object
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   260
      page_name: the page name displayed in templates as page and header title
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   261
      params: a dict with params for this View
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   262
      kwargs: the Key Fields for the specified entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   263
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   264
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   265
    # get the request view parameters and populate the form using POST data
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   266
    request_params = request_view.view.getParams()
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   267
    form = request_params['create_form'](request.POST)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   268
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   269
    if not form.is_valid():
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   270
      # return the invalid form response
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   271
      return self._constructResponse(request, entity=None, context=context,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   272
          form=form, params=params)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   273
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   274
    # collect the cleaned data from the valid form
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   275
    key_name, form_fields = soc.views.helper.forms.collectCleanedFields(form)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   276
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   277
    # get the club entity for which this request is for from link_id in kwargs
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   278
    club = club_logic.logic.getForFields({'link_id' : kwargs['link_id']}, unique=True)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   279
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   280
    # create the fields for the new request entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   281
    request_fields = {'link_id' : form_fields['link_id'].link_id,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   282
        'scope' : club,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   283
        'scope_path' : club.link_id,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   284
        'role' : params['module_name'],
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   285
        'role_verbose' : params['name'],
928
df051fc9d7a1 Replaced the boolean properties in soc/models/request.py with a state property.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 925
diff changeset
   286
        'state' : 'group_accepted'}
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   287
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   288
    # extract the key_name for the new request entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   289
    key_fields = request_logic.logic.getKeyFieldsFromDict(request_fields)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   290
    key_name = request_logic.logic.getKeyNameForFields(key_fields)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   291
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   292
    # create the request entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   293
    entity = request_logic.logic.updateOrCreateFromKeyName(request_fields, key_name)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   294
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   295
    # TODO(ljvderijk) redirect to a more useful place like the club homepage
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   296
    return http.HttpResponseRedirect('/')
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   297
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   298
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   299
view = View()
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   300
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   301
acceptInvite = view.acceptInvite
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   302
create = view.create
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   303
delete = view.delete
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   304
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
   305
invite = view.invite
802
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   306
list = view.list
95c534d02e39 Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   307
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
   308
export = view.export