Changeset 6151 for main


Ignore:
Timestamp:
19 May 2011, 16:49:36 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement a base ContainerManageFormPage? class as subclass for the FacultyManageFormPage?.

File:
1 edited

Legend:

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

    r6150 r6151  
    113113#
    114114
     115class ContainerManageFormPage(WAeUPEditFormPage):
     116    """Manage the basic properties of a container instance with local roles
     117    and contents This is the base class for faculty and department containers
     118    """
     119    grok.name('manage')
     120    grok.require('waeup.manageUniversity')
     121    taboneactions = ['Save','Cancel']
     122    tabtwoactions = ['Add subunit', 'Remove selected','Cancel']
     123    tabthreeactions = ['Add local role', 'Remove local roles selected']
     124
     125    # ToDo: Show warning message before deletion
     126    @grok.action('Remove selected')
     127    def delSubobjects(self, **data):
     128        form = self.request.form
     129        if form.has_key('val_id'):
     130            child_id = form['val_id']
     131        else:
     132            self.flash('No subunit selected!')
     133            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     134            return
     135        if not isinstance(child_id, list):
     136            child_id = [child_id]
     137        deleted = []
     138        for id in child_id:
     139            try:
     140                del self.context[id]
     141                deleted.append(id)
     142            except:
     143                self.flash('Could not delete %s: %s: %s' % (
     144                        id, sys.exc_info()[0], sys.exc_info()[1]))
     145        if len(deleted):
     146            self.flash('Successfully removed: %s' % ', '.join(deleted))
     147        self.redirect(self.url(self.context, '@@manage')+'#tab-1')
     148        return
     149
     150    def getLocalRoles(self):
     151        roles = ILocalRolesAssignable(self.context)
     152        return roles()
     153
     154    def getUsers(self):
     155        """Get a list of all users.
     156        """
     157        for key, val in grok.getSite()['users'].items():
     158            url = self.url(val)
     159            yield(dict(url=url, name=key, val=val))
     160
     161    @grok.action('Save')
     162    def save(self, **data):
     163        self.applyData(self.context, **data)
     164        return
     165
     166    @grok.action('Cancel', validator=NullValidator)
     167    def cancel(self, **data):
     168        self.redirect(self.url(self.context))
     169        return
     170
     171    @grok.action('Add subunit', validator=NullValidator)
     172    def addSubunit(self, **data):
     173        self.redirect(self.url(self.context, '@@add'))
     174        return
     175
     176    @grok.action('Add local role', validator=NullValidator)
     177    def addLocalRole(self, **data):
     178        form = self.request.form
     179        localrole = form['local_role']
     180        user = form['user']
     181        role_manager = IPrincipalRoleManager(self.context)
     182        role_map = IPrincipalRoleMap(self.context)
     183        role_manager.assignRoleToPrincipal(localrole, user)
     184        self.redirect(self.url(self.context, u'@@manage')+'#tab-3')
     185        return
     186
    115187class UniversityPage(WAeUPDisplayFormPage):
    116188    """ The main university page.
     
    9341006        return 'Departments'
    9351007
    936 class FacultyManageFormPage(WAeUPEditFormPage):
     1008class FacultyManageFormPage(ContainerManageFormPage):
    9371009    """Manage the basic properties of a `Faculty` instance.
    9381010    """
    9391011    grok.context(IFaculty)
    940     grok.name('manage')
    941     grok.require('waeup.manageUniversity')
    9421012    grok.template('facultymanagepage')
    9431013    pnav = 1
    944     taboneactions = ['Save','Cancel']
    945     tabtwoactions = ['Add department', 'Remove selected','Cancel']
    946     tabthreeactions = ['Add local role', 'Remove local roles selected']
    9471014    subunits = 'Departments'
    9481015
     
    9561023    def title(self):
    9571024        return self.context.longtitle()
    958 
    959     def getLocalRoles(self):
    960         roles = ILocalRolesAssignable(self.context)
    961         return roles()
    962 
    963     def getUsers(self):
    964         """Get a list of all users.
    965         """
    966         for key, val in grok.getSite()['users'].items():
    967             url = self.url(val)
    968             #import pdb; pdb.set_trace()
    969             yield(dict(url=url, name=key, val=val))
    9701025
    9711026    def update(self):
     
    9731028        #warning.need()
    9741029        return super(FacultyManageFormPage, self).update()
    975 
    976     @grok.action('Save')
    977     def save(self, **data):
    978         self.applyData(self.context, **data)
    979         return
    980 
    981     # ToDo: Show warning message before deletion
    982     @grok.action('Remove selected')
    983     def delDepartments(self, **data):
    984         form = self.request.form
    985         child_id = form['val_id']
    986         if not isinstance(child_id, list):
    987             child_id = [child_id]
    988         deleted = []
    989         for id in child_id:
    990             try:
    991                 del self.context[id]
    992                 deleted.append(id)
    993             except:
    994                 self.flash('Could not delete %s: %s: %s' % (
    995                         id, sys.exc_info()[0], sys.exc_info()[1]))
    996         if len(deleted):
    997             self.flash('Successfully removed: %s' % ', '.join(deleted))
    998         self.redirect(self.url(self.context, u'@@manage')+'#tab-2')
    999         return
    1000 
    1001     @grok.action('Add department', validator=NullValidator)
    1002     def addDepartment(self, **data):
    1003         self.redirect(self.url(self.context, '@@add'))
    1004         return
    1005 
    1006     @grok.action('Cancel', validator=NullValidator)
    1007     def cancel(self, **data):
    1008         self.redirect(self.url(self.context))
    1009         return
    1010 
    1011     @grok.action('Add local role', validator=NullValidator)
    1012     def addLocalRole(self, **data):
    1013         form = self.request.form
    1014         localrole = form['local_role']
    1015         user = form['user']
    1016         role_manager = IPrincipalRoleManager(self.context)
    1017         role_map = IPrincipalRoleMap(self.context)
    1018         #import pdb; pdb.set_trace()
    1019         role_manager.assignRoleToPrincipal(localrole, user)
    1020         self.redirect(self.url(self.context, u'@@manage')+'#tab-3')
    1021         return
    10221030
    10231031class DepartmentAddFormPage(WAeUPAddFormPage):
Note: See TracChangeset for help on using the changeset viewer.