app/soc/views/models/request.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 12 Mar 2009 22:30:04 +0000
changeset 1815 7a9b69f36111
parent 1686 d9cc9f8ca19f
child 1938 21699b426f60
permissions -rw-r--r--
Always convert newlines to linebreaks Patch by: Sverre Rabbelier
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
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
495
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
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Views for Requests.
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>',
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
    '"Pawel Solyga" <pawel.solyga@gmail.com>',
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
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import forms
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    28
from django import http
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 962
diff changeset
    29
from django.utils.translation import ugettext
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    31
from soc.logic import cleaning
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from soc.logic import dicts
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.logic.models import user as user_logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
from soc.views import helper
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
    35
from soc.views.helper import access
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    36
from soc.views.helper import decorators
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
    37
from soc.views.helper import dynaform
620
e74e0b74625f Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 618
diff changeset
    38
from soc.views.helper import redirects
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    39
from soc.views.helper import responses
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    40
from soc.views.helper import widgets
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
from soc.views.models import base
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
import soc.models.request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
import soc.logic.models.request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
import soc.logic.dicts
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
import soc.views.helper
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: 629
diff changeset
    47
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: 629
diff changeset
    48
import soc.views.helper.responses
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
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
class View(base.View):
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    52
  """View methods for the Request model.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
  """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    55
  def __init__(self, params=None):
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
    """Defines the fields and methods required for the base View class
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
    to provide the user with list, public, create, edit and delete views.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    60
      params: a dict with params for this View
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    63
    rights = access.Checker(params)
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1011
diff changeset
    64
    rights['listSelf'] = ['checkIsUser']
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    65
    rights['create'] = ['deny']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    66
    rights['edit'] = ['checkIsDeveloper']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    67
    rights['process_invite'] = ['checkIsMyGroupAcceptedRequest']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    68
    rights['list'] = ['checkIsDeveloper']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    69
    rights['delete'] = ['checkIsDeveloper']
1010
aeed003f50c5 Fixed two access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    70
    rights['roles'] = ['checkIsUser']
587
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
    71
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    72
    new_params = {}
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    73
    new_params['rights'] = rights
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    74
    new_params['logic'] = soc.logic.models.request.logic
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    76
    new_params['name'] = "Request"
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
1637
17f2fd8091c3 Remove unused imports and fix too long lines in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1594
diff changeset
    78
    new_params['sidebar_defaults'] = [('/%s/list', 'List %(name_plural)s', 
17f2fd8091c3 Remove unused imports and fix too long lines in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1594
diff changeset
    79
        'list')]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
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
    81
    new_params['create_template'] = ['soc/request/create.html']
1686
d9cc9f8ca19f Added created_on DateTime property to request.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    82
d9cc9f8ca19f Added created_on DateTime property to request.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
    83
    new_params['extra_dynaexclude'] = ['status', 'role_verbose', 'created_on']
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
    84
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1357
diff changeset
    85
    new_params['create_extra_dynaproperties'] = {
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1181
diff changeset
    86
        'link_id': widgets.ReferenceField(reference_url='user'),
951
026696e4a3af Rename processInvite view variable to process_invite to comply to our style guide. Remove some not needed whitespaces. Fix listSelf method parameters docstring in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
    87
        'role': forms.CharField(widget=widgets.ReadOnlyInput(),
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    88
                                   required=True),
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
    89
        'clean_link_id': cleaning.clean_existing_user('link_id'),
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    90
        }
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    91
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1357
diff changeset
    92
    new_params['edit_extra_dynaproperties'] = {
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: 940
diff changeset
    93
        'scope_path': forms.CharField(widget=forms.HiddenInput,
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: 940
diff changeset
    94
                                        required=True),
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: 940
diff changeset
    95
        }
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: 940
diff changeset
    96
1637
17f2fd8091c3 Remove unused imports and fix too long lines in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1594
diff changeset
    97
    patterns = [(r'^%(url_name)s/(?P<access_type>process_invite)/'
17f2fd8091c3 Remove unused imports and fix too long lines in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1594
diff changeset
    98
          '%(key_fields)s$',
951
026696e4a3af Rename processInvite view variable to process_invite to comply to our style guide. Remove some not needed whitespaces. Fix listSelf method parameters docstring in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
    99
          'soc.views.models.%(module_name)s.process_invite',
982
9efcedcfeb3e Changed the title for the process_request webpage.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   100
          'Process Invite to become')]
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   101
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   102
    new_params['extra_django_patterns'] = patterns
1686
d9cc9f8ca19f Added created_on DateTime property to request.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
   103
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   104
    new_params['invite_processing_template'] = 'soc/request/process_invite.html'
1637
17f2fd8091c3 Remove unused imports and fix too long lines in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1594
diff changeset
   105
    new_params['request_processing_template'] = \
17f2fd8091c3 Remove unused imports and fix too long lines in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1594
diff changeset
   106
        'soc/request/process_request.html'
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   108
    params = dicts.merge(params, new_params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   110
    super(View, self).__init__(params=params)
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   111
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   112
    # create and store the special forms for invite and requests
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   113
    params['invite_form'] = params['create_form']
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   114
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   115
    updated_fields = {
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   116
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   117
            required=True),
1030
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1012
diff changeset
   118
        'group_id': forms.CharField(widget=widgets.ReadOnlyInput(),
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   119
            required=True)}
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   120
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   121
    request_form = dynaform.extendDynaForm(
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   122
        dynaform = self._params['create_form'],
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1357
diff changeset
   123
        dynaproperties = updated_fields)
962
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   124
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   125
    params['request_form'] = request_form
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   126
606871fda11c Added request creation and processing to role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 953
diff changeset
   127
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   128
  @decorators.merge_params
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   129
  @decorators.check_access
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   130
  def processInvite(self, request, access_type,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   131
                   page_name=None, params=None, **kwargs):
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   132
    """Creates the page upon which an invite can be processed.
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   133
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   134
    Args:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   135
      request: the standard Django HTTP request object
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   136
      access_type : the name of the access type which should be checked
951
026696e4a3af Rename processInvite view variable to process_invite to comply to our style guide. Remove some not needed whitespaces. Fix listSelf method parameters docstring in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
   137
      page_name: the page name displayed in templates as page and header title
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   138
      params: a dict with params for this View
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   139
      kwargs: the Key Fields for the specified entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   140
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   141
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   142
    # get the context for this webpage
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   143
    context = responses.getUniversalContext(request)
1357
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
   144
    helper.responses.useJavaScript(context, params['js_uses_all'])
3dd1507aa723 Prepare all views for a new modular approach to JS loading
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
   145
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   146
    request_logic = params['logic']
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   147
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   148
    # get the request entity using the information from kwargs
951
026696e4a3af Rename processInvite view variable to process_invite to comply to our style guide. Remove some not needed whitespaces. Fix listSelf method parameters docstring in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
   149
    fields = {'link_id': kwargs['link_id'],
026696e4a3af Rename processInvite view variable to process_invite to comply to our style guide. Remove some not needed whitespaces. Fix listSelf method parameters docstring in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
   150
        'scope_path': kwargs['scope_path'],
026696e4a3af Rename processInvite view variable to process_invite to comply to our style guide. Remove some not needed whitespaces. Fix listSelf method parameters docstring in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
   151
        'role': kwargs['role'],
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   152
        'status': 'group_accepted'}
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   153
    request_entity = request_logic.getForFields(fields, unique=True)
982
9efcedcfeb3e Changed the title for the process_request webpage.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   154
9efcedcfeb3e Changed the title for the process_request webpage.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   155
    # set the page name using the request_entity
9efcedcfeb3e Changed the title for the process_request webpage.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   156
    context['page_name'] = '%s %s' % (page_name, 
9efcedcfeb3e Changed the title for the process_request webpage.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   157
        request_entity.role_verbose)
9efcedcfeb3e Changed the title for the process_request webpage.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   158
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   159
    get_dict = request.GET
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   160
    
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   161
    if 'status' in get_dict.keys():
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   162
      if get_dict['status'] == 'rejected':
928
df051fc9d7a1 Replaced the boolean properties in soc/models/request.py with a state property.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 920
diff changeset
   163
        # this invite has been rejected mark as rejected
986
e9611a2288ca Rename ModelProperties to EntityProperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 982
diff changeset
   164
        request_logic.updateEntityProperties(request_entity, {
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   165
            'status': 'rejected'})
982
9efcedcfeb3e Changed the title for the process_request webpage.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 970
diff changeset
   166
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   167
        # redirect to user role overview
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   168
        return http.HttpResponseRedirect('/user/roles')
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   169
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   170
    # put the entity in the context
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   171
    context['entity'] = request_entity
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   172
    context['module_name'] = params['module_name']
929
7431d7770197 Renamed redirect methods to comply with the rest of the module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 928
diff changeset
   173
    context['invite_accepted_redirect'] = (
940
a40056afef83 Changed the access checks to comply with state in request.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 929
diff changeset
   174
        redirects.getInviteAcceptedRedirect(request_entity, self._params))
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   175
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   176
    #display the invite processing page using the appropriate template
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   177
    template = params['invite_processing_template']
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   178
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   179
    return responses.respond(request, template, context=context)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   180
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   181
  @decorators.merge_params
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   182
  @decorators.check_access
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   183
  def listSelf(self, request, access_type,
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   184
               page_name=None, params=None, **kwargs):
519
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   185
    """Displays the unhandled requests for this user.
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   186
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   187
    Args:
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   188
      request: the standard Django HTTP request object
951
026696e4a3af Rename processInvite view variable to process_invite to comply to our style guide. Remove some not needed whitespaces. Fix listSelf method parameters docstring in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
   189
      access_type : the name of the access type which should be checked
519
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   190
      page_name: the page name displayed in templates as page and header title
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   191
      params: a dict with params for this View
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   192
      kwargs: not used
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   193
    """
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   194
561a438115eb Adds the user's role page. Currently this only has an overview of the user's unhandled requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 514
diff changeset
   195
    # get the current user
1181
6fb4134e1dfc Calling getForCurrentAccount where necessary.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1085
diff changeset
   196
    user_entity = user_logic.logic.getForCurrentAccount()
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   197
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   198
    # construct the Unhandled Invites list
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   199
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   200
    # only select the Invites for this user that haven't been handled yet
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   201
    filter = {'link_id': user_entity.link_id,
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   202
              'status': 'group_accepted'}
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   203
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   204
    uh_params = params.copy()
929
7431d7770197 Renamed redirect methods to comply with the rest of the module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 928
diff changeset
   205
    uh_params['list_action'] = (redirects.getInviteProcessRedirect, None)
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 962
diff changeset
   206
    uh_params['list_description'] = ugettext(
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   207
        "An overview of your unhandled invites.")
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   208
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   209
    uh_list = helper.lists.getListContent(
1667
95bc81b4cd5c Updated list to use the new order in getForFields.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1637
diff changeset
   210
        request, uh_params, filter, idx=0)
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   211
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   212
    # construct the Open Requests list
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   213
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   214
    # only select the requests from the user
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   215
    # that haven't been accepted by an admin yet
951
026696e4a3af Rename processInvite view variable to process_invite to comply to our style guide. Remove some not needed whitespaces. Fix listSelf method parameters docstring in soc.views.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 944
diff changeset
   216
    filter = {'link_id': user_entity.link_id,
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1084
diff changeset
   217
              'status': 'new'}
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   218
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   219
    ar_params = params.copy()
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 962
diff changeset
   220
    ar_params['list_description'] = ugettext(
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   221
        "List of your pending requests.")
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   222
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   223
    ar_list = helper.lists.getListContent(
1667
95bc81b4cd5c Updated list to use the new order in getForFields.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1637
diff changeset
   224
        request, ar_params, filter, idx=1)
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   225
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   226
    # fill contents with all the needed lists
626
342bebadd075 Fix too long lines in soc.views.models.request, remove unused imports and change pending requests list description. Remove unused imports from soc.logic.path_link_name module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
   227
    contents = [uh_list, ar_list]
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   228
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   229
    # call the _list method from base to display the list
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   230
    return self._list(request, params, contents, page_name)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   231
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   232
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   233
view = View()
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   234
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   235
admin = decorators.view(view.admin)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   236
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   237
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   238
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   239
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   240
list_self = decorators.view(view.listSelf)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   241
process_invite = decorators.view(view.processInvite)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   242
public = decorators.view(view.public)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   243
export = decorators.view(view.export)
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 822
diff changeset
   244