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