app/soc/views/models/role.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 31 Jan 2009 16:07:30 +0000
changeset 1118 d2a2268b3227
parent 1116 5a9d4c2d6748
child 1119 bd25a058ea2c
permissions -rw-r--r--
When moving stuff please make sure that all your belongings are safely secured. Brown Paper Bag fix. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
837
bc1c951bf3a0 Add missing blank line in soc.views.helper.params module. Fix docstring typo in soc.views.models.role module. Add missing dots at the end of sentences in soc.logic.cleaning and soc.view.models.user_self modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 755
diff changeset
    17
"""Views for Role profiles.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
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: 908
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
1118
d2a2268b3227 When moving stuff please make sure that all your belongings are safely secured.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1116
diff changeset
    26
from django import forms
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: 908
diff changeset
    27
from django import http
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 964
diff changeset
    28
from django.utils.translation import ugettext
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
1116
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
    30
from soc.logic import cleaning
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic import dicts
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: 908
diff changeset
    32
from soc.logic.models import request as request_logic
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
    33
from soc.logic.models import user as user_logic
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
    34
from soc.logic.helper import notifications as notifications_helper
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: 908
diff changeset
    35
from soc.logic.helper import request as request_helper
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: 908
diff changeset
    36
from soc.views.helper import decorators
620
e74e0b74625f Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 616
diff changeset
    37
from soc.views.helper import redirects
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: 908
diff changeset
    38
from soc.views.helper import responses
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
from soc.views.models import base
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: 908
diff changeset
    40
from soc.views.models import request as request_view
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
import soc.models.request
646
860e17e5118f Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 624
diff changeset
    43
import soc.views.helper.lists
860e17e5118f Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 624
diff changeset
    44
import soc.views.helper.responses
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
import soc.views.helper.widgets
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
657
c781de4f6d39 Rename role.RoleView to role.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    48
class View(base.View):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    49
  """Views for all entities that inherit from Role.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
  All views that only Role entities have are defined in this subclass.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
  """
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    53
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 964
diff changeset
    54
  DEF_INVITE_INSTRUCTION_MSG_FMT = ugettext(
520
b0c623819b68 Split a too long line
Sverre Rabbelier <srabbelier@gmail.com>
parents: 518
diff changeset
    55
      'Please use this form to invite someone to become a %(name)s.')
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    57
  DEF_REQUEST_INSTRUCTION_MSG_FMT = ugettext(
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    58
      'Please use this form to request to become a %(name)s')
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    59
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    60
  DEF_INVITE_ERROR_MSG_FMT = ugettext(
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    61
      'This user can not receive an invite to become a %(name)s. <br/>'
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    62
      'Please make sure there is no outstanding invite or request and '
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    63
      'be sure that this user is not a %(name)s.')
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    64
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    65
  DEF_REQUEST_ERROR_MSG_FMT = ugettext(
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    66
      'You can not request to become a %(name)s. <br/>'
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    67
      'Please make sure there is no outstanding invite or request and '
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    68
      'be sure that you are not a %(name)s already.')
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    69
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    70
616
580b1c21b808 Fixed requests not working anymore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
    71
  def __init__(self, params=None):
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
    Args:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    75
      params: This dictionary should be filled with the parameters
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
    78
    new_params = {}
963
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    79
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    80
    patterns = params.get('extra_django_patterns')
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    81
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    82
    if not patterns:
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    83
      patterns = []
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    84
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    85
    if params.get('allow_requests_and_invites'):
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    86
      # add patterns concerning requests and invites
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    87
      patterns += [(r'^%(url_name)s/(?P<access_type>invite)/%(scope)s$',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    88
          'soc.views.models.%(module_name)s.invite',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    89
          'Create invite for %(name)s'),
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    90
          (r'^%(url_name)s/(?P<access_type>accept_invite)/%(scope)s/%(lnp)s$',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    91
          'soc.views.models.%(module_name)s.accept_invite',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    92
          'Accept invite for %(name)s'),
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    93
          (r'^%(url_name)s/(?P<access_type>process_request)/%(scope)s/%(lnp)s$',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    94
          'soc.views.models.%(module_name)s.process_request',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    95
          'Process request for %(name)s'),
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    96
          (r'^%(url_name)s/(?P<access_type>request)/%(scope)s$',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    97
          'soc.views.models.%(module_name)s.request',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    98
          'Create a Request to become %(name)s')]
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
    99
    elif params.get('allow_invites'):
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   100
      # add patterns concerning only invites
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   101
      patterns += [(r'^%(url_name)s/(?P<access_type>invite)/%(scope)s$',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   102
          'soc.views.models.%(module_name)s.invite',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   103
          'Create invite for %(name)s'),
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   104
          (r'^%(url_name)s/(?P<access_type>accept_invite)/%(scope)s/%(lnp)s$',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   105
          'soc.views.models.%(module_name)s.accept_invite',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   106
          'Accept invite for %(name)s'),
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   107
          (r'^%(url_name)s/(?P<access_type>process_request)/%(scope)s/%(lnp)s$',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   108
          'soc.views.models.%(module_name)s.process_request',
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   109
          'Process request for %(name)s')]
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
   110
1067
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   111
    # add manage pattern
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   112
    patterns += [(r'^%(url_name)s/(?P<access_type>manage)/%(scope)s/%(lnp)s$',
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   113
        'soc.views.models.%(module_name)s.manage',
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   114
        'Manage a %(name)s'),]
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   115
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
   116
    new_params['extra_django_patterns'] = patterns
663
c2dcae606699 Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
   117
    new_params['scope_redirect'] = redirects.getInviteRedirect
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
   118
1116
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   119
    new_params['create_extra_dynafields'] = {
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   120
       'clean_link_id' : cleaning.clean_existing_user('link_id'),
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   121
       'clean_home_page' : cleaning.clean_url('home_page'),
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   122
       'clean_blog' : cleaning.clean_url('blog'),
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   123
       'clean_photo_url' : cleaning.clean_url('photo_url'),
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   124
       'scope_path': forms.CharField(widget=forms.HiddenInput,
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   125
                                  required=True),
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   126
       }
5a9d4c2d6748 Moved create_extra_dynafields from club_admin and member to role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
   127
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   128
    new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on']
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1067
diff changeset
   129
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1067
diff changeset
   130
    params = dicts.merge(params, new_params, sub_merge=True)
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 657
diff changeset
   131
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
   132
    super(View, self).__init__(params=params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
1067
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   134
    # add manage template
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   135
    params['manage_template'] = 'soc/%(module_name)s/manage.html' % params
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   136
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: 908
diff changeset
   137
  @decorators.merge_params
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: 908
diff changeset
   138
  @decorators.check_access
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 708
diff changeset
   139
  def invite(self, request, access_type,
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: 908
diff changeset
   140
                   page_name=None, params=None, **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: 908
diff changeset
   141
    """Creates the page on which an invite can be send out.
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: 908
diff changeset
   142
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: 908
diff changeset
   143
    Args:
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: 908
diff changeset
   144
      request: the standard Django HTTP request object
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: 908
diff changeset
   145
      access_type : the name of the access type which should be checked
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: 908
diff changeset
   146
      context: dictionary containing the context for this view
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: 908
diff changeset
   147
      params: a dict with params for this View
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: 908
diff changeset
   148
      kwargs: the Key Fields for the specified entity
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: 908
diff changeset
   149
    """
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: 908
diff changeset
   150
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: 908
diff changeset
   151
    # get the context for this webpage
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: 908
diff changeset
   152
    context = responses.getUniversalContext(request)
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: 908
diff changeset
   153
    context['page_name'] = page_name
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   154
    context['instruction_message'] = (self.DEF_INVITE_INSTRUCTION_MSG_FMT %
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   155
        params)
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: 908
diff changeset
   156
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: 908
diff changeset
   157
    if request.method == 'POST':
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: 908
diff changeset
   158
      return self.invitePost(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: 908
diff changeset
   159
    else:
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: 908
diff changeset
   160
      # request.method == 'GET'
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: 908
diff changeset
   161
      return self.inviteGet(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: 908
diff changeset
   162
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: 908
diff changeset
   163
  def inviteGet(self, 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: 908
diff changeset
   164
    """Handles the GET request concerning the view that creates an invite
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: 908
diff changeset
   165
    for attaining a certain Role.
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: 908
diff changeset
   166
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: 908
diff changeset
   167
    Args:
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: 908
diff changeset
   168
      request: the standard Django HTTP request object
959
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   169
      context: dictionary containing the context for this 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: 908
diff changeset
   170
      params: a dict with params for this View
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: 908
diff changeset
   171
      kwargs: the Key Fields for the specified entity
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: 908
diff changeset
   172
    """
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: 908
diff changeset
   173
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: 908
diff changeset
   174
    # set the role to the right name
959
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   175
    fields = {'role': '%(module_name)s' % (params)}
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: 908
diff changeset
   176
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: 908
diff changeset
   177
    # get the request view parameters and initialize the create 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: 908
diff changeset
   178
    request_params = request_view.view.getParams()
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   179
    form = request_params['invite_form'](initial=fields)
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: 908
diff changeset
   180
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: 908
diff changeset
   181
    # construct the appropriate response
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: 908
diff changeset
   182
    return super(View, self)._constructResponse(request, entity=None,
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   183
        context=context, form=form, params=request_params)
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: 908
diff changeset
   184
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: 908
diff changeset
   185
  def invitePost(self, 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: 908
diff changeset
   186
    """Handles the POST request concerning the view that creates an invite
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: 908
diff changeset
   187
    for attaining a certain Role.
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: 908
diff changeset
   188
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: 908
diff changeset
   189
    Args:
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: 908
diff changeset
   190
      request: the standard Django HTTP request object
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: 908
diff changeset
   191
      page_name: the page name displayed in templates as page and header title
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: 908
diff changeset
   192
      params: a dict with params for this View
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: 908
diff changeset
   193
      kwargs: the Key Fields for the specified entity
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   194
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   195
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: 908
diff changeset
   196
    # get the request view parameters and populate the form using POST data
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: 908
diff changeset
   197
    request_params = request_view.view.getParams()
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   198
    form = request_params['invite_form'](request.POST)
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: 908
diff changeset
   199
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: 908
diff changeset
   200
    if not form.is_valid():
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: 908
diff changeset
   201
      # return the invalid form response
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: 908
diff changeset
   202
      return self._constructResponse(request, entity=None, context=context,
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: 908
diff changeset
   203
          form=form, params=params)
708
89f1a8c2ea59 Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
   204
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: 908
diff changeset
   205
    # collect the cleaned data from the valid 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: 908
diff changeset
   206
    key_name, form_fields = soc.views.helper.forms.collectCleanedFields(form)
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   207
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: 908
diff changeset
   208
    # get the group entity for which this request is via the scope_path
978
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   209
    group = self._logic.getGroupEntityFromScopePath(params['group_logic'],
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   210
         kwargs['scope_path'])
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   211
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   212
    # get the request scope path
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   213
    request_scope_path = self._getRequestScopePathFromGroup(group)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   214
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: 908
diff changeset
   215
    # create the fields for the new request entity
959
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   216
    request_fields = {'link_id': form_fields['link_id'].link_id,
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   217
        'scope': group,
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   218
        'scope_path': request_scope_path,
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   219
        'role': params['module_name'],
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   220
        'role_verbose': params['name'],
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   221
        'status': 'group_accepted'}
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: 908
diff changeset
   222
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   223
    if not self._isValidNewRequest(request_fields, params):
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   224
      # not a valid invite
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   225
      context['error_message'] = self.DEF_INVITE_ERROR_MSG_FMT % (
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   226
          params)
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   227
      return self.inviteGet(request, context, params, **kwargs)
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   228
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: 908
diff changeset
   229
    # extract the key_name for the new request entity
1115
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   230
    key_fields = request_logic.logic.getKeyFieldsFromFields(request_fields)
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   231
    key_name = request_logic.logic.getKeyNameFromFields(key_fields)
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: 908
diff changeset
   232
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: 908
diff changeset
   233
    # create the request entity
959
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   234
    entity = request_logic.logic.updateOrCreateFromKeyName(request_fields, 
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   235
        key_name)
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   236
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   237
    # send out an invite notification
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   238
    notifications_helper.sendInviteNotification(entity)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   239
990
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   240
    group_view = params.get('group_view')
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   241
    if not group_view:
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   242
      return http.HttpResponseRedirect('/')
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   243
    else:
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   244
      # redirect to the requests list
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   245
      return http.HttpResponseRedirect(
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   246
          redirects.getListRequestsRedirect(group, group_view.getParams()))
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: 908
diff changeset
   247
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   248
  def _getRequestScopePathFromGroup(self, group_entity):
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   249
    """Returns the scope_path that should be put in a request for a given group.
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   250
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   251
    Args:
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   252
      group_entity: The group entity for which the request scope_path should
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   253
                    be returned.
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   254
    """
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   255
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   256
    if group_entity.scope_path:
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   257
      request_scope_path = '%s/%s' % [
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   258
          group_entity.scope_path, group_entity.link_id]
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   259
    else:
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   260
      request_scope_path = group_entity.link_id
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   261
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   262
    return request_scope_path
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   263
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   264
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: 908
diff changeset
   265
  @decorators.merge_params
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: 908
diff changeset
   266
  @decorators.check_access
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: 908
diff changeset
   267
  def acceptInvite(self, request, access_type,
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: 908
diff changeset
   268
                   page_name=None, params=None, **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: 908
diff changeset
   269
    """Creates the page process an invite into a Role.
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: 908
diff changeset
   270
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: 908
diff changeset
   271
    Args:
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: 908
diff changeset
   272
      request: the standard Django HTTP request object
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: 908
diff changeset
   273
      access_type : the name of the access type which should be checked
959
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   274
      page_name: the page name displayed in templates as page and header title
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: 908
diff changeset
   275
      params: a dict with params for this View
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: 908
diff changeset
   276
      kwargs: the Key Fields for the specified entity
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: 908
diff changeset
   277
    """
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: 908
diff changeset
   278
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: 908
diff changeset
   279
     # get the context for this webpage
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: 908
diff changeset
   280
    context = responses.getUniversalContext(request)
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: 908
diff changeset
   281
    context['page_name'] = page_name
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: 908
diff changeset
   282
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: 908
diff changeset
   283
    if request.method == 'POST':
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: 908
diff changeset
   284
      return self.acceptInvitePost(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: 908
diff changeset
   285
    else:
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: 908
diff changeset
   286
      # request.method == 'GET'
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: 908
diff changeset
   287
      return self.acceptInviteGet(request, context, params, **kwargs)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   288
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: 908
diff changeset
   289
  def acceptInviteGet(self, 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: 908
diff changeset
   290
    """Handles the GET request concerning the creation of a Role via an
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: 908
diff changeset
   291
    invite.
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: 908
diff changeset
   292
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: 908
diff changeset
   293
    Args:
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: 908
diff changeset
   294
      request: the standard Django HTTP request object
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: 908
diff changeset
   295
      context: dictionary containing the context for this view
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: 908
diff changeset
   296
      params: a dict with params for this View
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: 908
diff changeset
   297
      kwargs: the Key Fields for the specified entity
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: 908
diff changeset
   298
    """
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: 908
diff changeset
   299
959
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   300
    # create the form using the scope_path and link_id from kwargs 
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   301
    # as initial value
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   302
    fields = {'link_id': kwargs['link_id'],
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   303
              'scope_path': kwargs['scope_path']}
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: 908
diff changeset
   304
    form = params['invited_create_form'](initial=fields)
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: 908
diff changeset
   305
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: 908
diff changeset
   306
    # construct the appropriate response
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: 908
diff changeset
   307
    return super(View, self)._constructResponse(request, entity=None,
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: 908
diff changeset
   308
        context=context, form=form, params=params)
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: 908
diff changeset
   309
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: 908
diff changeset
   310
  def acceptInvitePost(self, 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: 908
diff changeset
   311
    """Handles the POST request concerning the creation of a Role via an
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: 908
diff changeset
   312
    invite.
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: 908
diff changeset
   313
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: 908
diff changeset
   314
    Args:
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: 908
diff changeset
   315
      request: the standard Django HTTP request object
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: 908
diff changeset
   316
      context: dictionary containing the context for this view
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: 908
diff changeset
   317
      params: a dict with params for this View
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: 908
diff changeset
   318
      kwargs: the Key Fields for the specified entity
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: 908
diff changeset
   319
    """
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: 908
diff changeset
   320
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: 908
diff changeset
   321
    # populate the form using the POST data
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: 908
diff changeset
   322
    form = params['invited_create_form'](request.POST)
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: 908
diff changeset
   323
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: 908
diff changeset
   324
    if not form.is_valid():
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: 908
diff changeset
   325
      # return the invalid form response
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: 908
diff changeset
   326
      return self._constructResponse(request, entity=None, context=context,
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: 908
diff changeset
   327
          form=form, params=params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   328
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: 908
diff changeset
   329
    # collect the cleaned data from the valid 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: 908
diff changeset
   330
    key_name, fields = soc.views.helper.forms.collectCleanedFields(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: 908
diff changeset
   331
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: 908
diff changeset
   332
    # call the post process method
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: 908
diff changeset
   333
    self._acceptInvitePost(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: 908
diff changeset
   334
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: 908
diff changeset
   335
    group_logic = params['group_logic']
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: 908
diff changeset
   336
    group_entity = group_logic.getFromKeyName(fields['scope_path'])
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: 908
diff changeset
   337
    fields['scope'] = group_entity
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   338
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: 908
diff changeset
   339
    # make sure that this role becomes active once more in case this user
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: 908
diff changeset
   340
    # has been reinvited
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   341
    fields ['status'] = 'active'
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: 908
diff changeset
   342
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: 908
diff changeset
   343
    # get the key_name for the new entity
1115
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   344
    key_fields =  self._logic.getKeyFieldsFromFields(fields)
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   345
    key_name = self._logic.getKeyNameFromFields(key_fields)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   346
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: 908
diff changeset
   347
    # create new Role entity
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: 908
diff changeset
   348
    entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
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: 908
diff changeset
   349
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: 908
diff changeset
   350
    # mark the request as completed
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: 908
diff changeset
   351
    request_helper.completeRequestForRole(entity, params['module_name'])
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: 908
diff changeset
   352
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: 908
diff changeset
   353
    # redirect to the roles overview page
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: 908
diff changeset
   354
    return http.HttpResponseRedirect('/user/roles')
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: 908
diff changeset
   355
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: 908
diff changeset
   356
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
959
b6e8750c9407 Some style guide fixes, docstring fixes and removal of unused imports in different modules. Rename acceptInvite view variable to accept_invite in soc.views.models.host module to comply to our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 952
diff changeset
   357
    """Used to post-process data after the fields have been cleaned.
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 837
diff changeset
   358
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: 908
diff changeset
   359
      Args:
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: 908
diff changeset
   360
      fields : the cleaned fields from the role 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: 908
diff changeset
   361
      request: the standard Django HTTP request object
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: 908
diff changeset
   362
      context: dictionary containing the context for this view
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: 908
diff changeset
   363
      params: a dict with params for this View
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: 908
diff changeset
   364
      kwargs: the Key Fields for the specified entity
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: 908
diff changeset
   365
    """
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: 908
diff changeset
   366
    pass
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   367
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   368
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   369
  @decorators.merge_params
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   370
  @decorators.check_access
1067
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   371
  def manage(self, request, access_type,
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   372
                   page_name=None, params=None, **kwargs):
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   373
    """Handles the request concerning the view that let's 
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   374
       you manage a role's status.
1067
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   375
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   376
    Args:
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   377
      request: the standard Django HTTP request object
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   378
      page_name: the page name displayed in templates as page and header title
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   379
      params: a dict with params for this View
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   380
      kwargs: the Key Fields for the specified entity
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   381
    """
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   382
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   383
    # get the context for this webpage
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   384
    context = responses.getUniversalContext(request)
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   385
    context['page_name'] = page_name
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   386
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   387
    logic = params['logic']
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   388
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   389
    # get the entity for the given fields in kwargs
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   390
    fields = {'scope_path': kwargs['scope_path'],
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   391
        'link_id': kwargs['link_id']}
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   392
    role_entity = logic.getForFields(kwargs, unique=True)
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   393
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   394
    # get the redirect for the cancel button or when the resignation is done
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   395
    redirect = redirects.getListRolesRedirect(role_entity.scope, 
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   396
        params['group_view'].getParams())
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   397
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   398
    # check to see if resign is true
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   399
    get_dict = request.GET
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   400
    resign = get_dict.get('resign')
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   401
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   402
    if resign == 'true':
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   403
      # change the status of this role_entity to invalid
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   404
      fields = {'status': 'invalid'}
1067
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   405
      logic.updateEntityProperties(role_entity, fields)
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   406
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   407
      # redirect to the roles listing
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   408
      return http.HttpResponseRedirect(redirect)
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   409
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   410
    # set the appropriate context
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   411
    context['entity'] = role_entity
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   412
    context['url_name'] = params['url_name']
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   413
    context['cancel_redirect'] = redirect
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   414
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   415
    # get the manage template
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   416
    template = params['manage_template']
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   417
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   418
    # return a proper response
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   419
    return responses.respond(request, template, context=context)
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   420
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   421
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   422
  @decorators.merge_params
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   423
  @decorators.check_access
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   424
  def request(self, request, access_type,
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   425
                   page_name=None, params=None, **kwargs):
1067
ecf3df87b81c Added manage view for Club Admins, Club Members and Hosts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
   426
    """Handles the request concerning the view that creates a request
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   427
    for attaining a certain Role.
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   428
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   429
    Args:
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   430
      request: the standard Django HTTP request object
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   431
      page_name: the page name displayed in templates as page and header title
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   432
      params: a dict with params for this View
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   433
      kwargs: the Key Fields for the specified entity
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   434
    """
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   435
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   436
    # get the context for this webpage
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   437
    context = responses.getUniversalContext(request)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   438
    context['page_name'] = page_name
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   439
    context['instruction_message'] = (self.DEF_REQUEST_INSTRUCTION_MSG_FMT %
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   440
        params)
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   441
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   442
    if request.method == 'POST':
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   443
      return self.requestPost(request, context, params, **kwargs)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   444
    else:
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   445
      # request.method == 'GET'
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   446
      return self.requestGet(request, context, params, **kwargs)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   447
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   448
  def requestGet(self, request, context, params, **kwargs):
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   449
    """Handles the GET request concerning the creation of a request
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   450
    to attain a role.
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   451
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   452
    Args:
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   453
      request: the standard Django HTTP request object
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   454
      context: dictionary containing the context for this view
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   455
      params: a dict with params for this View
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   456
      kwargs: the Key Fields for the specified entity
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   457
    """
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   458
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   459
    # set right fields for the request form
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   460
    user_entity = user_logic.logic.getForCurrentAccount()
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   461
    fields = {'link_id' : user_entity.link_id,
964
63005fcf12df Coding style fix in views/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 963
diff changeset
   462
              'role' : params['module_name'],
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   463
              'group_id' : kwargs['scope_path']}
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   464
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   465
    # get the request view parameters and initialize the create form
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   466
    request_params = request_view.view.getParams()
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   467
    form = request_params['request_form'](initial=fields)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   468
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   469
    # construct the appropriate response
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   470
    return super(View, self)._constructResponse(request, entity=None,
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   471
        context=context, form=form, params=request_params)
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   472
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   473
  def requestPost(self, request, context, params, **kwargs):
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   474
    """Handles the POST request concerning the creation of a request
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   475
    to attain a role.
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   476
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   477
    Args:
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   478
      request: the standard Django HTTP request object
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   479
      context: dictionary containing the context for this view
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   480
      params: a dict with params for this View
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   481
      kwargs: the Key Fields for the specified entity
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   482
    """
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   483
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   484
    # get the request view parameters and populate the form using POST data
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   485
    request_params = request_view.view.getParams()
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   486
    form = request_params['invite_form'](request.POST)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   487
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   488
    if not form.is_valid():
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   489
      # return the invalid form response
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   490
      return self._constructResponse(request, entity=None, context=context,
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   491
          form=form, params=params)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   492
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   493
    # get the group entity for which this request is via the scope_path
978
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   494
    group = self._logic.getGroupEntityFromScopePath(params['group_logic'],
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   495
         kwargs['scope_path'])
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   496
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   497
    # get the request scope path
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   498
    request_scope_path = self._getRequestScopePathFromGroup(group)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   499
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   500
    # defensively set the fields we need for this request and set status to new
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   501
    user_entity = user_logic.logic.getForCurrentAccount()
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   502
    request_fields = {'link_id' : user_entity.link_id,
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   503
        'scope' : group,
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   504
        'scope_path' : request_scope_path,
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   505
        'role' : params['module_name'],
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   506
        'role_verbose' : params['name'],
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   507
        'status' : 'new'}
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   508
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   509
    if self._isValidNewRequest(request_fields, params):
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   510
      # not a valid request
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   511
      context['error_message'] = self.DEF_REQUEST_ERROR_MSG_FMT % (
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   512
          params)
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   513
      return self.requestGet(request, context, params, **kwargs)
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   514
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   515
    # extract the key_name for the new request entity
1115
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   516
    key_fields = request_logic.logic.getKeyFieldsFromFields(request_fields)
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   517
    key_name = request_logic.logic.getKeyNameFromFields(key_fields)
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   518
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   519
    # create the request entity
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   520
    entity = request_logic.logic.updateOrCreateFromKeyName(request_fields, key_name)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   521
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   522
    # TODO(ljvderijk) send out a message to alert the users able to process this request
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   523
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   524
    # redirect to roles overview
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   525
    return http.HttpResponseRedirect('/user/roles')
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   526
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   527
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   528
  @decorators.merge_params
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   529
  @decorators.check_access
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   530
  def processRequest(self, request, access_type,
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   531
                   page_name=None, params=None, **kwargs):
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   532
    """Creates the page upon which a request can be processed.
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   533
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   534
    Args:
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   535
      request: the standard Django HTTP request object
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   536
      access_type : the name of the access type which should be checked
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   537
      page_name: the page name displayed in templates as page and header title
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   538
      params: a dict with params for this View
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   539
      kwargs: the Key Fields for the specified entity
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   540
    """
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   541
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   542
    # get the context for this webpage
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   543
    context = responses.getUniversalContext(request)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   544
    context['page_name'] = page_name
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   545
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   546
    # get the request entity using the information from kwargs
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   547
    fields = {'link_id': kwargs['link_id'],
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   548
        'scope_path': kwargs['scope_path'],
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   549
        'role': params['module_name']}
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   550
    request_entity = request_logic.logic.getForFields(fields, unique=True)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   551
    
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   552
    get_dict = request.GET
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   553
    
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   554
    if 'status' in get_dict.keys():
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   555
      if get_dict['status'] in ['group_accepted', 'rejected', 'ignored']:
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   556
        # update the request_entity and redirect away from this page
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   557
        request_status = get_dict['status']
986
e9611a2288ca Rename ModelProperties to EntityProperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 978
diff changeset
   558
        request_logic.logic.updateEntityProperties(request_entity, {
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   559
            'status': get_dict['status']})
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   560
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   561
        if request_status == 'group_accepted':
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   562
          notifications_helper.sendInviteNotification(request_entity)
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   563
990
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   564
        group_view = params.get('group_view')
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   565
        if not group_view:
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   566
          return http.HttpResponseRedirect('/')
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   567
        else:
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   568
          # redirect to the requests list
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   569
          return http.HttpResponseRedirect(
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   570
              redirects.getListRequestsRedirect(request_entity.scope, 
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
   571
                  group_view.getParams()))
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   572
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   573
    # put the entity in the context
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   574
    context['entity'] = request_entity
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   575
    context['module_name'] = params['module_name']
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   576
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   577
    #display the request processing page using the appropriate template
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   578
    template = request_view.view.getParams()['request_processing_template']
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 959
diff changeset
   579
963
24c0a9da6360 Parameterized patterns in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 962
diff changeset
   580
    return responses.respond(request, template, context=context)
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   581
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   582
  def _isValidNewRequest(self, request_fields, params):
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   583
    """Checks if this is a valid Request object to make.
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   584
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   585
    Args:
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   586
    request_fields: dict containing the fields for the new request entity.
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   587
    params: parameters for the current view
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   588
    """
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   589
    fields = request_fields.copy()
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   590
    fields['status'] = ['new', 'group_accepted', 'ignored']
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   591
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   592
    request_entity = request_logic.logic.getForFields(fields, unique=True)
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   593
    
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   594
    if request_entity:
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   595
      # already outstanding request
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   596
      return False
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   597
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   598
    # check if the role already exists
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   599
    fields = {'scope' : request_fields['scope'],
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   600
        'link_id': request_fields['link_id'],
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   601
        'status': ['active','inactive'],
1084
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   602
        }
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   603
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   604
    role_entity = params['logic'].getForFields(fields, unique=True)
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   605
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   606
    if role_entity:
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   607
      # already has this role
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   608
      return False
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   609
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   610
    # no oustanding request or a valid role
9c4221f7b747 Requests can now not be created when you already have a similar request or already have the role the request is for.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   611
    return True