Changeset 7009


Ignore:
Timestamp:
6 Nov 2011, 17:24:21 (13 years ago)
Author:
Henrik Bettermann
Message:

Filter actions if students are using the AccommodationManageFormPage?.

I first tried to use two different pages, one for officers and one for students, and use different targets in breadcrumbs. But this was much more complicated.

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

Legend:

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

    r7006 r7009  
    132132    title = u'Accommodation'
    133133
     134    #@property
     135    #def target(self):
     136    #    prm = get_principal_role_manager()
     137    #    principal = get_current_principal()
     138    #    roles = [x[0] for x in prm.getRolesForPrincipal(principal.id)]
     139    #    if 'waeup.Student' in roles:
     140    #        return 'index'
     141    #    else:
     142    #        return 'manage'
     143
    134144class BedTicketBreadcrumb(Breadcrumb):
    135145    """A breadcrumb for bed tickets.
    136146    """
    137147    grok.context(IBedTicket)
    138     @property
    139 
     148
     149    @property
    140150    def title(self):
    141151        return 'Bed Ticket %s' % self.context.getSessionString()
     
    10121022# This manage form page is for both students and students officers.
    10131023class AccommodationManageFormPage(WAeUPEditFormPage):
    1014     """ Page to manage the bed tickets
     1024    """ Page to manage bed tickets.
    10151025    """
    10161026    grok.context(IStudentAccommodation)
     
    10211031    title = 'Accommodation'
    10221032    pnav = 4
    1023 
    1024     def unremovable(self):
    1025         prm = get_principal_role_manager()
    1026         roles = [x[0] for x in prm.getRolesForPrincipal(self.request.principal.id)]
    1027         return ('waeup.Student' in roles)
     1033    officers_only_actions = ['delBedTickets']
    10281034
    10291035    def formatDatetime(self,datetimeobj):
     
    10421048        return
    10431049
    1044     # We need an event handler which releases the bed space too.
    1045     @grok.action('Remove selected tickets')
    1046     def delBedTicket(self, **data):
     1050    @grok.action('Remove selected')
     1051    def delBedTickets(self, **data):
    10471052        form = self.request.form
    10481053        if form.has_key('val_id'):
     
    10561061        deleted = []
    10571062        for id in child_id:
    1058             # Students are not allowed to remove bed tickets
    1059             if not self.unremovable():
    1060                 try:
    1061                     del self.context[id]
    1062                     deleted.append(id)
    1063                 except:
    1064                     self.flash('Could not delete %s: %s: %s' % (
    1065                             id, sys.exc_info()[0], sys.exc_info()[1]))
     1063            try:
     1064                del self.context[id]
     1065                deleted.append(id)
     1066            except:
     1067                self.flash('Could not delete %s: %s: %s' % (
     1068                        id, sys.exc_info()[0], sys.exc_info()[1]))
    10661069        if len(deleted):
    10671070            self.flash('Successfully removed: %s' % ', '.join(deleted))
     
    10701073        return
    10711074
    1072     @grok.action('Add bed ticket')
     1075    @grok.action('Book accommodation')
    10731076    def addBedTicket(self, **data):
    10741077        self.redirect(self.url(self.context, '@@add'))
     1078
     1079    def isStudent(self):
     1080        prm = get_principal_role_manager()
     1081        roles = [x[0] for x in prm.getRolesForPrincipal(self.request.principal.id)]
     1082        return 'waeup.Student' in roles
     1083
     1084    @property
     1085    def selected_actions(self):
     1086        sa = self.actions
     1087        if self.isStudent():
     1088            sa = [action for action in self.actions
     1089                  if not action in officers_only_actions]
     1090        return sa
    10751091
    10761092class BedTicketAddPage(WAeUPPage):
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/accommodationmanagepage.pt

    r7007 r7009  
    3030          <input type="checkbox"
    3131                 name="val_id"
    32                  tal:attributes="value cl/__name__"
    33          tal:condition="not: view/unremovable" />
     32                 tal:attributes="value cl/__name__" />
    3433        </td>
    3534        <td> <a tal:attributes="href cl/__name__">
     
    4342
    4443  <div class="actionButtons" tal:condition="view/availableActions">
    45     <span tal:repeat="action view/actions"
     44    <span tal:repeat="action view/selected_actions"
    4645          tal:omit-tag="">
    4746      <input tal:replace="structure action/render"/>
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7006 r7009  
    497497        self.assertTrue('Processing of 1 rows failed' in self.browser.contents)
    498498        self.assertTrue('Successfully processed 2 rows' in self.browser.contents)
     499        return
    499500
    500501    def test_student_change_password(self):
     
    741742        self.assertMatches('...Clearance process has been started...',
    742743                           self.browser.contents)
    743 
     744        return
    744745
    745746    def test_student_payments(self):
     
    834835                           self.browser.contents)
    835836        self.assertTrue(self.student.state,'school fee paid')
     837        return
    836838
    837839    def test_manage_accommodation(self):
     
    856858        # Managers can use HOS code and book a bed space with it
    857859        self.browser.open(self.acco_student_path)
    858         self.browser.getControl("Add bed ticket").click()
     860        self.browser.getControl("Book accommodation").click()
    859861        self.assertMatches('...Wrong state...',
    860862                           self.browser.contents)
    861863        IWorkflowInfo(self.student).fireTransition('admit')
    862         self.browser.getControl("Add bed ticket").click()
     864        self.browser.getControl("Book accommodation").click()
    863865        self.assertMatches('...Activation Code:...',
    864866                           self.browser.contents)
     
    872874        self.assertTrue(bed.owner,self.student_id)
    873875        # BedTicketAddPage is now blocked
    874         self.browser.getControl("Add bed ticket").click()
     876        self.browser.getControl("Book accommodation").click()
    875877        self.assertMatches('...Ticket for 2004 already created...',
    876878            self.browser.contents)
     
    889891        self.browser.getControl("Remove selected", index=0).click()
    890892        self.assertMatches('...Successfully removed...', self.browser.contents)
    891         # Due to an event handler also the bed has been released properly
     893        # The bed has been released properly by the event handler
    892894        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
    893895        self.assertTrue(bed.owner == NOT_OCCUPIED)
     896        return
    894897
    895898    def test_student_accommodation(self):
    896         pass
     899        return
Note: See TracChangeset for help on using the changeset viewer.