Ignore:
Timestamp:
21 May 2011, 18:51:49 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement local role assignment and removal in application section.

browser.py line 341: Use correct context for the IPrincipalRoleManager adapter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py

    r6153 r6184  
    4343    ThumbnailWidget, EncodingImageFileWidget,
    4444    )
    45 from waeup.sirp.interfaces import IWAeUPObject
     45from waeup.sirp.interfaces import IWAeUPObject, ILocalRolesAssignable
    4646from waeup.sirp.widgets.datewidget import (
    4747    FriendlyDateWidget, FriendlyDateDisplayWidget)
     
    5858    IApplicantsContainerAdd, application_types_vocab
    5959    )
     60from waeup.sirp.browser.pages import add_local_role, del_local_roles
     61from waeup.sirp.permissions import get_users_with_local_roles, getRoles
    6062
    6163results_widget = CustomWidgetFactory(
     
    99101    grok.require('waeup.manageUniversity')
    100102    taboneactions = ['Add applicants container', 'Remove selected','Cancel']
     103    tabtwoactions1 = ['Remove selected local roles']
     104    tabtwoactions2 = ['Add local role']
    101105    subunits = 'Applicants Containers'
    102106
     
    105109        datatable.need()
    106110        return super(ApplicantsRootManageFormPage, self).update()
     111
     112    def getLocalRoles(self):
     113        roles = ILocalRolesAssignable(self.context)
     114        return roles()
     115
     116    def getUsers(self):
     117        """Get a list of all users.
     118        """
     119        for key, val in grok.getSite()['users'].items():
     120            url = self.url(val)
     121            yield(dict(url=url, name=key, val=val))
     122
     123    def getUsersWithLocalRoles(self):
     124        return get_users_with_local_roles(self.context)
    107125
    108126    # ToDo: Show warning message before deletion
     
    136154        return
    137155
     156    @grok.action('Add local role', validator=NullValidator)
     157    def addLocalRole(self, **data):
     158        return add_local_role(self,2, **data)
     159
     160    @grok.action('Remove selected local roles')
     161    def delLocalRoles(self, **data):
     162        return del_local_roles(self,2,**data)
     163
    138164class ApplicantsContainerAddFormPage(WAeUPAddFormPage):
    139165    grok.context(IApplicantsRoot)
     
    255281    taboneactions = ['Save','Cancel']
    256282    tabtwoactions = ['Add applicant', 'Remove selected','Cancel']
     283    tabthreeactions1 = ['Remove selected local roles']
     284    tabthreeactions2 = ['Add local role']
    257285    # Use friendlier date widget...
    258286    form_fields['startdate'].custom_widget = FriendlyDateWidget('le')
     
    276304        return super(ApplicantsContainerManageFormPage, self).update()
    277305
     306    def getLocalRoles(self):
     307        roles = ILocalRolesAssignable(self.context)
     308        return roles()
     309
     310    def getUsers(self):
     311        """Get a list of all users.
     312        """
     313        for key, val in grok.getSite()['users'].items():
     314            url = self.url(val)
     315            yield(dict(url=url, name=key, val=val))
     316
     317    def getUsersWithLocalRoles(self):
     318        return get_users_with_local_roles(self.context)
     319
    278320    @grok.action('Save')
    279321    def apply(self, **data):
     
    295337        self.redirect(self.url(self.context))
    296338        return
     339
     340    @grok.action('Add local role', validator=NullValidator)
     341    def addLocalRole(self, **data):
     342        return add_local_role(self,3, **data)
     343
     344    @grok.action('Remove selected local roles')
     345    def delLocalRoles(self, **data):
     346        return del_local_roles(self,3,**data)
    297347
    298348
     
    339389        # Assign current principal the owner role on created applicant
    340390        # record
    341         role_manager = IPrincipalRoleManager(self.context)
     391        role_manager = IPrincipalRoleManager(self.context[pin])
    342392        role_manager.assignRoleToPrincipal(
    343393            'waeup.local.ApplicationOwner', self.request.principal.id)
Note: See TracChangeset for help on using the changeset viewer.