app/soc/modules/ghop/views/models/mentor.py
author Lennard de Rijk <ljvderijk@gmail.com>
Mon, 14 Sep 2009 19:58:43 +0200
changeset 2919 cb677410c0f1
parent 2886 52f9b098a6da
child 3032 f3886d1b00a5
permissions -rw-r--r--
Using the new checkIsMyActiveRole check where necessary.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2886
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
#
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
#
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
#
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
"""GHOP specific views for Organization Mentors.
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
"""
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
__authors__ = [
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
    '"Madhusudan.C.S" <madhusudancs@gmail.com>'
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
  ]
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
from soc.logic import dicts
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
from soc.views.helper import decorators
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
from soc.views.models import mentor
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
import soc.cache.logic
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
from soc.modules.ghop.logic.models import organization as ghop_org_logic
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
from soc.modules.ghop.logic.models import student as ghop_student_logic
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
from soc.modules.ghop.views.helper import access as ghop_access
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
from soc.modules.ghop.views.models import organization as ghop_org_view
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
import soc.modules.ghop.logic.models.mentor
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
class View(mentor.View):
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
  """View methods for the GHOP Mentor model.
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
  """
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
  def __init__(self, params=None):
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
    """Defines the fields and methods required for the mentor View class
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
    to provide the user with list, public, create, edit and delete views.
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
    Params:
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
      params: a dict with params for this View
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
    """
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
    rights = ghop_access.GHOPChecker(params)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
    rights['create'] = ['checkIsDeveloper']
2919
cb677410c0f1 Using the new checkIsMyActiveRole check where necessary.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2886
diff changeset
    55
    rights['edit'] = [('checkIsMyActiveRole', ghop_mentor_logic.logic)]
2886
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
    rights['delete'] = ['checkIsDeveloper']
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
    rights['invite'] = [('checkHasActiveRoleForScope',
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
                         ghop_org_admin_logic.logic)]
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
    rights['accept_invite'] = [('checkCanCreateFromRequest', 'ghop/mentor'),
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
        ('checkIsNotStudentForProgramOfOrg',
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
         [ghop_org_logic.logic, ghop_student_logic.logic])]
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
    rights['request'] = [
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
        ('checkIsNotStudentForProgramOfOrg',
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
         [ghop_org_logic.logic, ghop_student_logic.logic]),
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
        ('checkCanMakeRequestToGroup', ghop_org_logic)]
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
    rights['process_request'] = [
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
        ('checkHasActiveRoleForScope', ghop_org_admin_logic.logic),
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
        ('checkCanProcessRequest', 'ghop/mentor')]
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
    rights['manage'] = [
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
        ('checkIsAllowedToManageRole', [ghop_mentor_logic.logic,
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
                                        ghop_org_admin_logic.logic])]
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
    new_params = {}
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
    new_params['logic'] = soc.modules.ghop.logic.models.mentor.logic
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
    new_params['group_logic'] = ghop_org_logic.logic
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
    new_params['group_view'] = ghop_org_view.view
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
    new_params['rights'] = rights
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
    new_params['scope_view'] = ghop_org_view
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
    new_params['name'] = "GHOP Mentor"
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
    new_params['module_name'] = "mentor"
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
    new_params['sidebar_grouping'] = 'Organizations'
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
    new_params['module_package'] = 'soc.modules.ghop.views.models'
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
    new_params['url_name'] = 'ghop/mentor'
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
    new_params['role'] = 'ghop/mentor'
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
    params = dicts.merge(params, new_params, sub_merge=True)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
    super(View, self).__init__(params=params)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
view = View()
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
accept_invite = decorators.view(view.acceptInvite)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
admin = decorators.view(view.admin)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
create = decorators.view(view.create)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
delete = decorators.view(view.delete)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
edit = decorators.view(view.edit)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
invite = decorators.view(view.invite)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
list = decorators.view(view.list)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
manage = decorators.view(view.manage)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
process_request = decorators.view(view.processRequest)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
role_request = decorators.view(view.request)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
public = decorators.view(view.public)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
export = decorators.view(view.export)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
pick = decorators.view(view.pick)
52f9b098a6da Added GHOP Mentor View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110