Changeset 6152 for main/waeup.sirp


Ignore:
Timestamp:
19 May 2011, 19:40:10 (13 years ago)
Author:
Henrik Bettermann
Message:

Revert r6151. The ContainerManageFormPage? does not make sense. Its code cannot be reused.

Implement local role assignment on DepartmentManageFormPage?.

There is a lot of recurring code in pages.py. I have no ideas how to reuse the code.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
3 edited

Legend:

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

    r6151 r6152  
    4848grok.templatedir('templates')
    4949
     50def addLocalRole(view, tab, **data):
     51    form = view.request.form
     52    localrole = form['local_role']
     53    user = form['user']
     54    role_manager = IPrincipalRoleManager(view.context)
     55    role_map = IPrincipalRoleMap(view.context)
     56    role_manager.assignRoleToPrincipal(localrole, user)
     57    view.redirect(view.url(view.context, u'@@manage')+'#tab-%s' % tab)
     58    return
     59
    5060#
    5161# Login/logout pages...
     
    7686            self.flash('You entered wrong credentials!')
    7787
    78 
    7988class LoginStaffPage(LoginPage):
    8089    """A login page for staff members.
     
    8493    grok.require('waeup.Public')
    8594    title = u'Staff Login'
    86 
    8795
    8896class LoginStudentPage(LoginPage):
     
    108116        self.redirect(self.url(self.context))
    109117
    110 
    111118#
    112119# University related pages...
    113120#
    114 
    115 class 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
    186121
    187122class UniversityPage(WAeUPDisplayFormPage):
     
    1006941        return 'Departments'
    1007942
    1008 class FacultyManageFormPage(ContainerManageFormPage):
     943class FacultyManageFormPage(WAeUPEditFormPage):
    1009944    """Manage the basic properties of a `Faculty` instance.
    1010945    """
    1011946    grok.context(IFaculty)
     947    grok.name('manage')
     948    grok.require('waeup.manageUniversity')
    1012949    grok.template('facultymanagepage')
    1013950    pnav = 1
    1014951    subunits = 'Departments'
     952    taboneactions = ['Save','Cancel']
     953    tabtwoactions = ['Add department', 'Remove selected','Cancel']
     954    tabthreeactions = ['Add local role', 'Remove local roles selected']
    1015955
    1016956    form_fields = grok.AutoFields(IFaculty)
     
    1028968        #warning.need()
    1029969        return super(FacultyManageFormPage, self).update()
     970
     971    def getLocalRoles(self):
     972        roles = ILocalRolesAssignable(self.context)
     973        return roles()
     974
     975    def getUsers(self):
     976        """Get a list of all users.
     977        """
     978        for key, val in grok.getSite()['users'].items():
     979            url = self.url(val)
     980            yield(dict(url=url, name=key, val=val))
     981
     982    # ToDo: Show warning message before deletion
     983    @grok.action('Remove selected')
     984    def delSubobjects(self, **data):
     985        form = self.request.form
     986        if form.has_key('val_id'):
     987            child_id = form['val_id']
     988        else:
     989            self.flash('No subunit selected!')
     990            self.redirect(self.url(self.context, '@@manage')+'#tab-%s' % tab)
     991            return
     992        if not isinstance(child_id, list):
     993            child_id = [child_id]
     994        deleted = []
     995        for id in child_id:
     996            try:
     997                del self.context[id]
     998                deleted.append(id)
     999            except:
     1000                self.flash('Could not delete %s: %s: %s' % (
     1001                        id, sys.exc_info()[0], sys.exc_info()[1]))
     1002        if len(deleted):
     1003            self.flash('Successfully removed: %s' % ', '.join(deleted))
     1004        self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     1005        return
     1006
     1007    @grok.action('Save')
     1008    def save(self, **data):
     1009        self.applyData(self.context, **data)
     1010        return
     1011
     1012    @grok.action('Cancel', validator=NullValidator)
     1013    def cancel(self, **data):
     1014        self.redirect(self.url(self.context))
     1015        return
     1016
     1017    @grok.action('Add department', validator=NullValidator)
     1018    def addSubunit(self, **data):
     1019        self.redirect(self.url(self.context, '@@add'))
     1020        return
     1021
     1022    @grok.action('Add local role', validator=NullValidator)
     1023    def addLocalRole(self, **data):
     1024        return addLocalRole(self, '3', **data)
    10301025
    10311026class DepartmentAddFormPage(WAeUPAddFormPage):
     
    11101105    tabtwoactions = ['Add course', 'Remove selected courses','Cancel']
    11111106    tabthreeactions = ['Add certificate', 'Remove selected certificates', 'Cancel']
     1107    tabfouractions = ['Add local role', 'Remove local roles selected']
     1108
     1109    form_fields = grok.AutoFields(IDepartment)
    11121110
    11131111    @property
     
    11381136        super(DepartmentManageFormPage, self).update()
    11391137        return
    1140 
    1141     form_fields = grok.AutoFields(IDepartment)
     1138       
     1139    def getLocalRoles(self):
     1140        roles = ILocalRolesAssignable(self.context)
     1141        return roles()
     1142
     1143    def getUsers(self):
     1144        """Get a list of all users.
     1145        """
     1146        for key, val in grok.getSite()['users'].items():
     1147            url = self.url(val)
     1148            yield(dict(url=url, name=key, val=val))
    11421149
    11431150    @grok.action('Save')
     
    11991206        self.redirect(self.url(self.context))
    12001207        return
     1208       
     1209    @grok.action('Add local role', validator=NullValidator)
     1210    def addLocalRole(self, **data):
     1211        return addLocalRole(self, 4, **data)
    12011212
    12021213class CourseAddFormPage(WAeUPAddFormPage):
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/departmentmanagepage.pt

    r6025 r6152  
    2727  <li><a href="#tab-2">Courses</a></li>
    2828  <li><a href="#tab-3">Certificates</a></li>
     29  <li><a href="#tab-4">Local Roles</a></li>
    2930</ul>
    3031   
     
    146147    </div>         
    147148</div>
     149
     150<div id="tab-4">
     151    <h3>Manage local roles</h3>
     152    <table class="zebra">
     153    <tr>
     154        <td>
     155        <label>User:</label>
     156        </td>
     157        <td>
     158            <select  id="user" name="user"  tal:repeat="user view/getUsers">
     159              <option tal:attributes="value user/name">
     160                <span tal:replace="user/val/description">USERTITLE</span>
     161              </option>
     162            </select>
     163        </td>
     164    </tr>
     165    <tr>
     166        <td>
     167        <label>Local Role:</label>
     168        </td>
     169        <td>
     170            <select  id="local_role" name="local_role"  tal:repeat="localrole view/getLocalRoles">
     171              <option tal:attributes="value localrole/name">
     172                <span tal:replace="localrole/title">LOCALROLETITLE</span>
     173              </option>
     174            </select>
     175        </td>
     176    </tr>
     177    </table>
     178
     179    <div id="actionsView">
     180        <span class="actionButtons" tal:condition="view/availableActions">
     181            <span tal:repeat="action view/actions"
     182                  tal:omit-tag="">
     183              <input tal:condition="python:action.label in view.tabfouractions"
     184                     tal:replace="structure action/render"/>
     185            </span>
     186        </span>
     187    </div>
     188</div>
    148189   
    149190</div>
  • main/waeup.sirp/trunk/src/waeup/sirp/university/department.py

    r5988 r6152  
    1313    grok.implements(IDepartment, IDepartmentAdd)
    1414
     15    @property       # Make this method read_only and looking like an attr.
     16    def local_roles(cls):
     17        return [
     18            {'name':'waeup.local.DepartmentOfficer',
     19             'title':'Department Officer'},
     20            ]
     21
    1522    # A simple counter for ids.
    1623    next_id = 0L
    17    
     24
    1825    def __init__(self,
    1926                 title=u'Unnamed Department',
Note: See TracChangeset for help on using the changeset viewer.