app/soc/views/models/request.py
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 23 Jan 2009 12:00:48 +0000
changeset 920 39badbfb80be
parent 890 b3bf833c4580
child 928 df051fc9d7a1
permissions -rw-r--r--
Added the new way to process invites for club_admin only. This patch contains the separability needed to ensure that we can successfully do the access checks we need. Host invites can for the time being only be completed by developers due to the reorganization. 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
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 google.appengine.api import users
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
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
    30
from django import http
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    31
from django.core import urlresolvers
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from django.utils.translation import ugettext_lazy
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    34
from soc.logic import cleaning
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.logic import dicts
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
from soc.logic.models import sponsor as sponsor_logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
from soc.logic.models import user as user_logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
from soc.views import helper
557
c6d9f8581730 Added missing import
Lennard de Rijk <ljvderijk@gmail.com>
parents: 556
diff changeset
    39
from soc.views import out_of_band
586
a4a36b06a870 Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents: 572
diff changeset
    40
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
    41
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: 618
diff changeset
    42
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
    43
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
    44
from soc.views.helper import widgets
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
from soc.views.models import base
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
import soc.models.request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
import soc.logic.models.request
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
import soc.logic.dicts
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
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
    51
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
    52
import soc.views.helper.responses
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
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
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
    56
  """View methods for the Request model.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
  """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    59
  def __init__(self, params=None):
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
    """Defines the fields and methods required for the base View class
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
    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
    62
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    64
      params: a dict with params for this View
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
587
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
    67
    rights = {}
890
b3bf833c4580 Tighten more checkIsUser() access to checkAgreesToSiteToS() instead.
Todd Larsen <tlarsen@google.com>
parents: 876
diff changeset
    68
    rights['listSelf'] = [access.checkAgreesToSiteToS]
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    69
    rights['create'] = [access.allow] # TODO(ljvderijk) Set to deny once host has been converted
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    70
    rights['edit'] = [access.checkIsDeveloper]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    71
    rights['process_invite'] = [access.checkIsMyUncompletedRequest]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    72
    rights['list'] = [access.checkIsDeveloper]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    73
    rights['delete'] = [access.checkIsDeveloper]
587
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
    74
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    75
    new_params = {}
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    76
    new_params['rights'] = rights
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    77
    new_params['logic'] = soc.logic.models.request.logic
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    79
    new_params['name'] = "Request"
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    81
    new_params['sidebar_defaults'] = [('/%s/list', 'List %(name_plural)s', 'list')]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
    83
    new_params['save_message'] = [ugettext_lazy('Request saved.')]
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    84
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    85
    new_params['extra_dynaexclude'] = ['group_accepted', 'user_accepted', 
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    86
        'role_verbose', 'completed']
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    87
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    88
    # TODO(ljvderijk) add clean field that checks to see if the user already has
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    89
    # the role that's been entered in the create form fields
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    90
    new_params['create_extra_dynafields'] = {
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    91
        'role' : forms.CharField(widget=widgets.ReadOnlyInput(),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    92
                                   required=True),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    93
        'clean_link_id': cleaning.clean_existing_user('link_id')
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    94
        }
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    95
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    96
    patterns = [(r'^%(url_name)s/(?P<access_type>invite)/%(lnp)s$',
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    97
        'soc.views.models.%(module_name)s.invite',
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    98
        'Create invite for %(name_plural)s'),
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
    99
        (r'^%(url_name)s/(?P<access_type>process_invite)/%(key_fields)s$',
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   100
          'soc.views.models.%(module_name)s.processInvite',
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   101
          'Process Invite to for a Role')]
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   102
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   103
    new_params['extra_django_patterns'] = patterns
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   104
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   105
    new_params['invite_processing_template'] = 'soc/request/process_invite.html'
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   107
    params = dicts.merge(params, new_params)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 651
diff changeset
   109
    super(View, self).__init__(params=params)
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   110
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   111
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   112
  @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
   113
  @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
   114
  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
   115
                   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
   116
    """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
   117
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   118
    Args:
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   119
      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
   120
      access_type : the name of the access type which should be checked
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   121
      context: dictionary containing the context for this view
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   122
      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
   123
      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
   124
    """
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   125
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   126
    # 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
   127
    context = responses.getUniversalContext(request)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   128
    context['page_name'] = page_name
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   129
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   130
    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
   131
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   132
    # get the request entity using the information from kwargs
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   133
    fields = {'link_id' : kwargs['link_id'],
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   134
        'scope_path' : kwargs['scope_path'],
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   135
        'role' : kwargs['role'],
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   136
        'group_accepted' : True,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   137
        'user_accepted' : False,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   138
        'completed' : False}
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   139
    request_entity = request_logic.getForFields(fields, unique=True)
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
    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
   142
    
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   143
    if 'status' in get_dict.keys():
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   144
      if get_dict['status'] == 'rejected':
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   145
        # this invite has been rejected mark accepted as False and mark completed as True
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.updateModelProperties(request_entity, {
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   147
            'user_accepted' : False, 'completed' : True})
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   148
        
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   149
        # 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
   150
        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
   151
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   152
    # 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
   153
    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
   154
    context['module_name'] = params['module_name']
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   155
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   156
    #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
   157
    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
   158
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   159
    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
   160
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   161
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   162
  @decorators.merge_params
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   163
  @decorators.check_access
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   164
  def listSelf(self, request, access_type,
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   165
               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
   166
    """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
   167
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
   168
    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
   169
      request: the standard Django HTTP request object
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
   170
      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
   171
      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
   172
      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
   173
    """
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
   174
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
   175
    # get the current user
521
07b2c382a4d6 Minor improvements to roles page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 519
diff changeset
   176
    properties = {'account': users.get_current_user()}
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
   177
    user_entity = user_logic.logic.getForFields(properties, unique=True)
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   178
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   179
    # 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
   180
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   181
    # 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
   182
    filter = {'link_id': user_entity.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
   183
              'group_accepted' : True,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   184
              'user_accepted' : False,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   185
              'completed' : False}
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   186
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   187
    uh_params = params.copy()
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   188
    uh_params['list_action'] = (redirects.inviteProcessRedirect, None)
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   189
    uh_params['list_description'] = ugettext_lazy(
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   190
        "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
   191
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
   192
    uh_list = helper.lists.getListContent(
651
ef6e22d463cb Remove the logic parameter from getListContent
Sverre Rabbelier <srabbelier@gmail.com>
parents: 646
diff changeset
   193
        request, uh_params, filter, 0)
556
6c22492b6349 Refactor requestSelf to be make use of the new split
Sverre Rabbelier <srabbelier@gmail.com>
parents: 554
diff changeset
   194
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   195
    # construct the Open Requests list
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   196
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   197
    # 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
   198
    # that haven't been accepted by an admin yet
562
1bf2beedda03 Made Request use the new link_id and scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 561
diff changeset
   199
    filter = {'link_id' : user_entity.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
   200
              'group_accepted' : False,
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   201
              'completed' : False}
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   202
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   203
    ar_params = params.copy()
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   204
    ar_params['list_description'] = ugettext_lazy(
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
   205
        "List of your pending requests.")
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   206
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
   207
    ar_list = helper.lists.getListContent(
651
ef6e22d463cb Remove the logic parameter from getListContent
Sverre Rabbelier <srabbelier@gmail.com>
parents: 646
diff changeset
   208
        request, ar_params, filter, 1)
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   209
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   210
    # 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
   211
    contents = [uh_list, ar_list]
822
f37fed16c388 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 799
diff changeset
   212
561
4db464032b25 Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 560
diff changeset
   213
    # 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
   214
    return self._list(request, params, contents, page_name)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   215
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   216
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   217
  def _editPost(self, request, entity, fields):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   218
    """See base.View._editPost().
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   219
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   220
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   221
    # TODO(ljvderijk) remove this once host has been rewritten
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   222
    callback, args, kwargs = urlresolvers.resolve(request.path)
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   223
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   224
    # fill in the fields via kwargs
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   225
    fields['link_id'] = kwargs['link_id']
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   226
    fields['scope_path'] = kwargs['scope_path']
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   227
    fields['role'] = kwargs['role']
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   228
    fields['role_verbose'] = 'Some Role'
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   229
    fields['group_accepted'] = True
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   230
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   231
    super(View, self)._editPost(request, entity, fields)
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
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   234
view = View()
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   235
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   236
create = view.create
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   237
edit = view.edit
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   238
delete = view.delete
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   239
list = view.list
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
   240
list_self = view.listSelf
920
39badbfb80be Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 890
diff changeset
   241
processInvite = view.processInvite
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   242
public = view.public
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 822
diff changeset
   243
export = view.export
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 822
diff changeset
   244