Changeset 6161


Ignore:
Timestamp:
20 May 2011, 09:39:59 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement deletion of local roles for faculties and departments.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/browser
Files:
4 edited

Legend:

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

    r6154 r6161  
    4848    user = form['user']
    4949    role_manager = IPrincipalRoleManager(view.context)
     50    role_manager.assignRoleToPrincipal(localrole, user)
     51    view.redirect(view.url(view.context, u'@@manage')+'#tab-%s' % tab)
     52    return
     53
     54def get_users_with_local_roles(view):
     55    role_manager = IPrincipalRoleManager(view.context)
    5056    role_map = IPrincipalRoleMap(view.context)
    51     role_manager.assignRoleToPrincipal(localrole, user)
     57    for item in role_map.getPrincipalsAndRoles():
     58        local_role = item[0]
     59        user_name = item[1]
     60        setting = item[2]
     61        user = grok.getSite()['users'].get(user_name,None)
     62        roles_dict = view.context.local_roles
     63        local_role_title = roles_dict[local_role]
     64        if user:
     65            yield(dict(user_name=user_name, user_title=user.description,
     66                local_role=local_role, local_role_title=local_role_title,
     67                setting=setting))
     68        else:
     69            yield(dict(user_name=user_name, user_title=user_name,
     70                local_role=local_role, local_role_title=local_role_title,
     71                setting=setting))
     72
     73def del_local_roles(view, tab, **data):
     74    form = view.request.form
     75    if form.has_key('role_id'):
     76        child_id = form['role_id']
     77    else:
     78        view.flash('No local role selected!')
     79        view.redirect(view.url(view.context, '@@manage')+'#tab-%s' % tab)
     80        return
     81    if not isinstance(child_id, list):
     82        child_id = [child_id]
     83    #import pdb; pdb.set_trace()
     84    deleted = []
     85    role_manager = IPrincipalRoleManager(view.context)
     86    for id in child_id:
     87        localrole = id.split('|')[1]
     88        user_name = id.split('|')[0]
     89        try:
     90            role_manager.unsetRoleForPrincipal(localrole, user_name)
     91            deleted.append(id)
     92        except:
     93            view.flash('Could not remove %s: %s: %s' % (
     94                    id, sys.exc_info()[0], sys.exc_info()[1]))
     95    if len(deleted):
     96        view.flash('Successfully removed: %s' % ', '.join(deleted))
    5297    view.redirect(view.url(view.context, u'@@manage')+'#tab-%s' % tab)
    5398    return
     
    859904    def delFaculties(self, **data):
    860905        form = self.request.form
    861         child_id = form['val_id']
     906        if form.has_key('val_id'):
     907            child_id = form['val_id']
     908        else:
     909            self.flash('No faculty selected!')
     910            self.redirect(self.url(self.context, '@@manage')+'#tab-1')
     911            return
    862912        if not isinstance(child_id, list):
    863913            child_id = [child_id]
     
    947997    taboneactions = ['Save','Cancel']
    948998    tabtwoactions = ['Add department', 'Remove selected','Cancel']
    949     tabthreeactions = ['Add local role', 'Remove local roles selected']
     999    tabthreeactions1 = ['Remove selected local roles']
     1000    tabthreeactions2 = ['Add local role']
    9501001
    9511002    form_fields = grok.AutoFields(IFaculty)
     
    9611012    def update(self):
    9621013        tabs.need()
    963         #warning.need()
     1014        datatable.need()
    9641015        return super(FacultyManageFormPage, self).update()
    9651016
     
    9741025            url = self.url(val)
    9751026            yield(dict(url=url, name=key, val=val))
     1027
     1028    def getUsersWithLocalRoles(self):
     1029        return get_users_with_local_roles(self)
    9761030
    9771031    # ToDo: Show warning message before deletion
     
    9821036            child_id = form['val_id']
    9831037        else:
    984             self.flash('No subunit selected!')
    985             self.redirect(self.url(self.context, '@@manage')+'#tab-%s' % tab)
     1038            self.flash('No department selected!')
     1039            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    9861040            return
    9871041        if not isinstance(child_id, list):
     
    10191073        return add_local_role(self, '3', **data)
    10201074
     1075    @grok.action('Remove selected local roles')
     1076    def delLocalRoles(self, **data):
     1077        return del_local_roles(self,3,**data)
     1078
    10211079class DepartmentAddFormPage(WAeUPAddFormPage):
    10221080    """Add a department to a faculty.
     
    11001158    tabtwoactions = ['Add course', 'Remove selected courses','Cancel']
    11011159    tabthreeactions = ['Add certificate', 'Remove selected certificates', 'Cancel']
    1102     tabfouractions = ['Add local role', 'Remove local roles selected']
     1160    tabfouractions1 = ['Remove selected local roles']
     1161    tabfouractions2 = ['Add local role']
    11031162
    11041163    form_fields = grok.AutoFields(IDepartment)
     
    11421201            url = self.url(val)
    11431202            yield(dict(url=url, name=key, val=val))
     1203           
     1204    def getUsersWithLocalRoles(self):
     1205        return get_users_with_local_roles(self)
    11441206
    11451207    @grok.action('Save')
     
    11521214    def delCourses(self, **data):
    11531215        form = self.request.form
    1154         child_id = form['val_id']
     1216        if form.has_key('val_id'):
     1217            child_id = form['val_id']
     1218        else:
     1219            self.flash('No course selected!')
     1220            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     1221            return
    11551222        if not isinstance(child_id, list):
    11561223            child_id = [child_id]
     
    11711238    def delCertificates(self, **data):
    11721239        form = self.request.form
    1173         child_id = form['val_id']
     1240        if form.has_key('val_id'):
     1241            child_id = form['val_id']
     1242        else:
     1243            self.flash('No certificate selected!')
     1244            self.redirect(self.url(self.context, '@@manage')+'#tab-3')
     1245            return
    11741246        if not isinstance(child_id, list):
    11751247            child_id = [child_id]
     
    12061278        return add_local_role(self, 4, **data)
    12071279
     1280    @grok.action('Remove selected local roles')
     1281    def delLocalRoles(self, **data):
     1282        return del_local_roles(self,4,**data)
     1283
    12081284class CourseAddFormPage(WAeUPAddFormPage):
    12091285    """Add-form to add course to a department.
     
    13961472    def delCertificateCourses(self, **data):
    13971473        form = self.request.form
    1398         child_id = form['val_id']
     1474        if form.has_key('val_id'):
     1475            child_id = form['val_id']
     1476        else:
     1477            self.flash('No course referrer selected!')
     1478            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     1479            return
    13991480        if not isinstance(child_id, list):
    14001481            child_id = [child_id]
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/static/waeup-base.css

    r6133 r6161  
    6666.ui-tabs .ui-tabs-nav li a:hover {
    6767  text-decoration: underline;
     68}
     69
     70.dataTables_wrapper {
     71  min-height: 100px;
    6872}
    6973
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/departmentmanagepage.pt

    r6152 r6161  
    3131   
    3232<div id="tab-1">       
    33       <table class="zebra">
    34       <tbody>
    35       <tal:block repeat="widget view/widgets">
    36         <tr>
    37           <td class="label" tal:define="hint widget/hint">
    38         <label tal:condition="python:hint"
    39                tal:attributes="for widget/name">
    40           <span class="required" tal:condition="widget/required"
    41                 >*</span><span i18n:translate=""
    42                 tal:content="widget/label">label</span>
    43         </label>
    44         <label tal:condition="python:not hint"
    45                tal:attributes="for widget/name">
    46           <span class="required" tal:condition="widget/required"
    47                 >*</span><span i18n:translate=""
    48                 tal:content="widget/label">label</span>
    49         </label>:
    50           </td>
    51           <td class="field">
    52         <div class="widget" tal:content="structure widget">
    53           <input type="text" />
    54         </div>
    55         <div class="error" tal:condition="widget/error">
    56           <span tal:replace="structure widget/error">error</span>
    57         </div>
    58           </td>
    59         </tr>
    60       </tal:block>
    61       </tbody>
    62       </table>
    63 
    64     <div id="actionsView">
    65         <span class="actionButtons" tal:condition="view/availableActions">
    66             <span tal:repeat="action view/actions"
    67                   tal:omit-tag="">
    68               <input tal:condition="python:action.label in view.taboneactions"
    69                      tal:replace="structure action/render"/>
    70             </span>
    71         </span>
    72     </div>   
     33    <table class="zebra">
     34        <tbody>
     35        <tal:block repeat="widget view/widgets">
     36            <tr>
     37              <td class="label" tal:define="hint widget/hint">
     38            <label tal:condition="python:hint"
     39                   tal:attributes="for widget/name">
     40              <span class="required" tal:condition="widget/required"
     41                >*</span><span i18n:translate=""
     42                tal:content="widget/label">label</span>
     43            </label>
     44            <label tal:condition="python:not hint"
     45                   tal:attributes="for widget/name">
     46              <span class="required" tal:condition="widget/required"
     47                >*</span><span i18n:translate=""
     48                tal:content="widget/label">label</span>
     49            </label>:
     50              </td>
     51              <td class="field">
     52            <div class="widget" tal:content="structure widget">
     53              <input type="text" />
     54            </div>
     55            <div class="error" tal:condition="widget/error">
     56              <span tal:replace="structure widget/error">error</span>
     57            </div>
     58              </td>
     59            </tr>
     60        </tal:block>
     61        </tbody>
     62    </table>
     63
     64    <div class="actionButtons" tal:condition="view/availableActions">
     65        <span tal:repeat="action view/actions"
     66              tal:omit-tag="">
     67          <input tal:condition="python:action.label in view.taboneactions"
     68                 tal:replace="structure action/render"/>
     69        </span>
     70    </div>
    7371
    7472</div>   
     
    10098    </table>
    10199    <br /><br />
    102     <div id="actionsView">
    103         <span class="actionButtons" tal:condition="view/availableActions">
    104             <span tal:repeat="action view/actions"
    105                   tal:omit-tag="">
    106               <input tal:condition="python:action.label in view.tabtwoactions"
    107                      tal:replace="structure action/render"/>
    108             </span>
    109         </span>
    110     </div>         
     100    <div class="actionButtons" tal:condition="view/availableActions">
     101        <span tal:repeat="action view/actions"
     102              tal:omit-tag="">
     103          <input tal:condition="python:action.label in view.tabtwoactions"
     104                 tal:replace="structure action/render"/>
     105        </span>
     106    </div>
    111107</div>
    112108
     
    137133    </table>
    138134    <br /><br />
    139     <div id="actionsView">
    140         <span class="actionButtons" tal:condition="view/availableActions">
    141             <span tal:repeat="action view/actions"
    142                   tal:omit-tag="">
    143               <input tal:condition="python:action.label in view.tabthreeactions"
    144                      tal:replace="structure action/render"/>
    145             </span>
    146         </span>
    147     </div>         
     135    <div class="actionButtons" tal:condition="view/availableActions">
     136        <span tal:repeat="action view/actions"
     137              tal:omit-tag="">
     138          <input tal:condition="python:action.label in view.tabthreeactions"
     139                 tal:replace="structure action/render"/>
     140        </span>
     141    </div>
    148142</div>
    149143
    150144<div id="tab-4">
    151     <h3>Manage local roles</h3>
     145    <br />
     146    <table class="display dataTableManage">
     147      <thead>
     148        <tr>
     149          <th>&nbsp;</th><th>User</th><th>Local Role</th>
     150        </tr>
     151      </thead>
     152      <tbody>
     153        <tr tal:repeat="entry view/getUsersWithLocalRoles"
     154        class="gradeB">
     155          <td>
     156            <input type="checkbox" name="role_id"
     157                tal:attributes="value python: entry['user_name']+'|'+entry['local_role']" />
     158          </td>
     159          <td tal:content="entry/user_title">User
     160          </td>
     161          <td tal:content="entry/local_role_title">
     162               Local Role
     163          </td>
     164        </tr>
     165      </tbody>
     166    </table>
     167    <div class="actionButtons" tal:condition="view/availableActions">
     168        <span tal:repeat="action view/actions"
     169              tal:omit-tag="">
     170          <input tal:condition="python:action.label in view.tabfouractions1"
     171                 tal:replace="structure action/render"/>
     172        </span>
     173    </div>
     174    <br /><br />
    152175    <table class="zebra">
    153176    <tr>
    154         <td>
    155         <label>User:</label>
    156         </td>
    157177        <td>
    158178            <select  id="user" name="user"  tal:repeat="user view/getUsers">
     
    161181              </option>
    162182            </select>
    163         </td>
    164     </tr>
    165     <tr>
    166         <td>
    167         <label>Local Role:</label>
    168183        </td>
    169184        <td>
     
    174189            </select>
    175190        </td>
     191        <td>
     192            <div class="actionButtons" tal:condition="view/availableActions">
     193                <span tal:repeat="action view/actions"
     194                      tal:omit-tag="">
     195                  <input tal:condition="python:action.label in view.tabfouractions2"
     196                         tal:replace="structure action/render"/>
     197                </span>
     198            </div>
     199        </td>
     200       
    176201    </tr>
    177202    </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>
    189    
     203</div>
    190204</div>
    191205</form> 
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/facultymanagepage.pt

    r6130 r6161  
    3030   
    3131<div id="tab-1">       
    32       <table class="zebra">
    33       <tbody>
    34       <tal:block repeat="widget view/widgets">
    35         <tr>
    36           <td class="label" tal:define="hint widget/hint">
    37         <label tal:condition="python:hint"
    38                tal:attributes="for widget/name">
    39           <span class="required" tal:condition="widget/required"
    40                 >*</span><span i18n:translate=""
    41                 tal:content="widget/label">label</span>
    42         </label>
    43         <label tal:condition="python:not hint"
    44                tal:attributes="for widget/name">
    45           <span class="required" tal:condition="widget/required"
    46                 >*</span><span i18n:translate=""
    47                 tal:content="widget/label">label</span>
    48         </label>:
    49           </td>
    50           <td class="field">
    51         <div class="widget" tal:content="structure widget">
    52           <input type="text" />
    53         </div>
    54         <div class="error" tal:condition="widget/error">
    55           <span tal:replace="structure widget/error">error</span>
    56         </div>
    57           </td>
    58         </tr>
    59       </tal:block>
    60       </tbody>
    61       </table>
     32    <table class="zebra">
     33        <tbody>
     34        <tal:block repeat="widget view/widgets">
     35            <tr>
     36              <td class="label" tal:define="hint widget/hint">
     37            <label tal:condition="python:hint"
     38                   tal:attributes="for widget/name">
     39              <span class="required" tal:condition="widget/required"
     40                >*</span><span i18n:translate=""
     41                tal:content="widget/label">label</span>
     42            </label>
     43            <label tal:condition="python:not hint"
     44                   tal:attributes="for widget/name">
     45              <span class="required" tal:condition="widget/required"
     46                >*</span><span i18n:translate=""
     47                tal:content="widget/label">label</span>
     48            </label>:
     49              </td>
     50              <td class="field">
     51            <div class="widget" tal:content="structure widget">
     52              <input type="text" />
     53            </div>
     54            <div class="error" tal:condition="widget/error">
     55              <span tal:replace="structure widget/error">error</span>
     56            </div>
     57              </td>
     58            </tr>
     59        </tal:block>
     60        </tbody>
     61    </table>
    6262
    63     <div id="actionsView">
    64         <span class="actionButtons" tal:condition="view/availableActions">
    65             <span tal:repeat="action view/actions"
    66                   tal:omit-tag="">
    67               <input tal:condition="python:action.label in view.taboneactions"
    68                      tal:replace="structure action/render"/>
    69             </span>
     63    <div class="actionButtons" tal:condition="view/availableActions">
     64        <span tal:repeat="action view/actions"
     65              tal:omit-tag="">
     66          <input tal:condition="python:action.label in view.taboneactions"
     67                 tal:replace="structure action/render"/>
    7068        </span>
    71     </div>   
     69    </div>
    7270
    7371</div>   
     
    7573<div id="tab-2">
    7674  <h3 tal:content="view/subunits">Departments</h3>
    77   <table class="zebra">
     75    <table class="zebra">
    7876    <thead>
    7977      <tr>
     
    10199      </tr>
    102100    </tbody>
    103   </table>
     101    </table>
    104102 
    105     <div id="actionsView">
    106         <span class="actionButtons" tal:condition="view/availableActions">
    107             <span tal:repeat="action view/actions"
    108                   tal:omit-tag="">
    109               <input tal:condition="python:action.label in view.tabtwoactions"
    110                      tal:replace="structure action/render"/>
    111             </span>
     103    <div class="actionButtons" tal:condition="view/availableActions">
     104        <span tal:repeat="action view/actions"
     105              tal:omit-tag="">
     106          <input tal:condition="python:action.label in view.tabtwoactions"
     107                 tal:replace="structure action/render"/>
    112108        </span>
    113     </div>     
     109    </div>
    114110</div>
    115111
    116112<div id="tab-3">
    117     <h3>Manage local roles</h3>
     113    <br />
     114    <table class="display dataTableManage">
     115      <thead>
     116        <tr>
     117          <th>&nbsp;</th><th>User</th><th>Local Role</th>
     118        </tr>
     119      </thead>
     120      <tbody>
     121        <tr tal:repeat="entry view/getUsersWithLocalRoles"
     122        class="gradeB">
     123          <td>
     124            <input type="checkbox" name="role_id"
     125                tal:attributes="value python: entry['user_name']+'|'+entry['local_role']" />
     126          </td>
     127          <td tal:content="entry/user_title">User
     128          </td>
     129          <td tal:content="entry/local_role_title">
     130               Local Role
     131          </td>
     132        </tr>
     133      </tbody>
     134    </table>
     135    <div class="actionButtons" tal:condition="view/availableActions">
     136        <span tal:repeat="action view/actions"
     137              tal:omit-tag="">
     138          <input tal:condition="python:action.label in view.tabthreeactions1"
     139                 tal:replace="structure action/render"/>
     140        </span>
     141    </div>
     142    <br /><br />
    118143    <table class="zebra">
    119144    <tr>
    120         <td>
    121         <label>User:</label>
    122         </td>
    123145        <td>
    124146            <select  id="user" name="user"  tal:repeat="user view/getUsers">
     
    127149              </option>
    128150            </select>
    129         </td>
    130     </tr>
    131     <tr>
    132         <td>
    133         <label>Local Role:</label>
    134151        </td>
    135152        <td>
     
    140157            </select>
    141158        </td>
     159        <td>
     160            <div class="actionButtons" tal:condition="view/availableActions">
     161                <span tal:repeat="action view/actions"
     162                      tal:omit-tag="">
     163                  <input tal:condition="python:action.label in view.tabthreeactions2"
     164                         tal:replace="structure action/render"/>
     165                </span>
     166            </div>
     167        </td>
    142168    </tr>
    143169    </table>
    144 
    145     <div id="actionsView">
    146         <span class="actionButtons" tal:condition="view/availableActions">
    147             <span tal:repeat="action view/actions"
    148                   tal:omit-tag="">
    149               <input tal:condition="python:action.label in view.tabthreeactions"
    150                      tal:replace="structure action/render"/>
    151             </span>
    152         </span>
    153     </div>
    154170</div>
    155171
Note: See TracChangeset for help on using the changeset viewer.