Ignore:
Timestamp:
25 Oct 2011, 08:52:28 (13 years ago)
Author:
Henrik Bettermann
Message:

We only need a PaymentsManageFormPage? which can be used by both students and students officers but students are not allowed to remove payment tickets which have received a valid callback.

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

    r6937 r6940  
    4848from waeup.sirp.students.utils import getPaymentDetails
    4949from waeup.sirp.browser.resources import toggleall
     50from waeup.sirp.authentication import get_principal_role_manager
    5051
    5152# Save function used for save methods in manager pages
     
    770771        return
    771772
     773# We don't need the display form page yet
    772774class PaymentsDisplayFormPage(WAeUPDisplayFormPage):
    773775    """ Page to display the student payments
    774776    """
    775777    grok.context(IStudentPaymentsContainer)
    776     grok.name('index')
     778    grok.name('view')
    777779    grok.require('waeup.viewStudent')
    778780    form_fields = grok.AutoFields(IStudentPaymentsContainer)
     
    796798        return
    797799
     800# This manage form page is for both students and students officers.
    798801class PaymentsManageFormPage(WAeUPEditFormPage):
    799802    """ Page to manage the student payments
    800803    """
    801804    grok.context(IStudentPaymentsContainer)
    802     grok.name('manage')
    803     grok.require('waeup.manageStudents')
     805    grok.name('index')
     806    grok.require('waeup.handleStudent')
    804807    form_fields = grok.AutoFields(IStudentPaymentsContainer)
    805808    grok.template('paymentsmanagepage')
    806809    title = 'Payments'
    807810    pnav = 4
     811
     812    def unremovable(self, ticket):
     813        prm = get_principal_role_manager()
     814        roles = [x[0] for x in prm.getRolesForPrincipal(self.request.principal.id)]
     815        return ('waeup.Student' in roles and ticket.r_code)
    808816
    809817    def formatDatetime(self,datetimeobj):
     
    829837        else:
    830838            self.flash('No payment selected.')
    831             self.redirect(self.url(self.context, '@@manage'))
     839            self.redirect(self.url(self.context))
    832840            return
    833841        if not isinstance(child_id, list):
     
    835843        deleted = []
    836844        for id in child_id:
    837             try:
    838                 del self.context[id]
    839                 deleted.append(id)
    840             except:
    841                 self.flash('Could not delete %s: %s: %s' % (
    842                         id, sys.exc_info()[0], sys.exc_info()[1]))
     845            # Students are not allowed to remove payment used tickets
     846            if not self.unremovable(self.context[id]):
     847                try:
     848                    del self.context[id]
     849                    deleted.append(id)
     850                except:
     851                    self.flash('Could not delete %s: %s: %s' % (
     852                            id, sys.exc_info()[0], sys.exc_info()[1]))
    843853        if len(deleted):
    844854            self.flash('Successfully removed: %s' % ', '.join(deleted))
    845         self.redirect(self.url(self.context, u'@@manage'))
     855        self.redirect(self.url(self.context))
    846856        return
    847857
     
    850860        self.redirect(self.url(self.context, '@@addop'))
    851861
    852 class OnlinePaymentManageActionButton(ManageActionButton):
    853     grok.order(1)
    854     grok.context(IStudentPaymentsContainer)
    855     grok.view(PaymentsDisplayFormPage)
    856     grok.require('waeup.manageStudents')
    857     text = 'Manage payments'
    858     target = 'manage'
     862#class OnlinePaymentManageActionButton(ManageActionButton):
     863#    grok.order(1)
     864#    grok.context(IStudentPaymentsContainer)
     865#    grok.view(PaymentsDisplayFormPage)
     866#    grok.require('waeup.manageStudents')
     867#    text = 'Manage payments'
     868#    target = 'manage'
    859869
    860870class OnlinePaymentAddFormPage(WAeUPAddFormPage):
     
    887897        if error:
    888898            self.flash(error)
    889             self.redirect(self.url(self.context, u'@@manage'))
     899            self.redirect(self.url(self.context))
    890900            return
    891901        self.context[payment.p_id] = payment
    892902        self.flash('Payment ticket created.')
    893         self.redirect(self.url(self.context, u'@@manage'))
     903        self.redirect(self.url(self.context))
    894904        return
    895905
     
    935945            pin, error = create_accesscode('CLR',0,student.student_id)
    936946            if error:
    937                 self.flash(error)
     947                self.flash('Valid callback received. ' + error)
    938948                return
    939949            self.context.ac = pin
    940             return
    941950        elif self.context.p_category == 'schoolfee':
    942951            # Create SFE access code
    943             pin, error = create_accesscode('SFE',0)
     952            pin, error = create_accesscode('SFE',0,student.student_id)
    944953            if error:
    945                 self.flash(error)
     954                self.flash('Valid callback received. ' + error)
    946955                return
    947956            self.context.ac = pin
    948             return
     957        self.flash('Valid callback received.')
     958        return
    949959
    950960    def render(self):
    951         self.redirect(self.url(self.context))
     961        self.redirect(self.url(self.context, '@@index'))
    952962        return
    953963
     
    13351345        deleted = []
    13361346        for id in child_id:
    1337             # Student are not allowed to remove core tickets
     1347            # Students are not allowed to remove core tickets
    13381348            if not self.context[id].core_or_elective:
    13391349                try:
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/paymentsmanagepage.pt

    r6869 r6940  
    3232          <input type="checkbox"
    3333                 name="val_id"
    34                  tal:attributes="value cl/__name__" />
     34                 tal:attributes="value cl/__name__"
     35         tal:condition="python: not view.unremovable(cl)" />
    3536        </td>
    3637        <td> <a tal:attributes="href cl/__name__">
     
    5253  </div>
    5354</form>
    54 
    55 
    56 
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r6938 r6940  
    662662        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    663663        self.browser.open(self.payments_student_path)
    664         self.browser.getLink("Manage").click()
     664        #self.browser.getLink("Manage").click()
    665665        self.browser.getControl("Add online payment ticket").click()
    666666        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     
    674674                           self.browser.contents)
    675675        self.browser.open(self.payments_student_path)
    676         self.browser.getLink('Manage').click()
     676        #self.browser.getLink('Manage').click()
    677677        self.browser.getControl("Remove selected").click()
    678678        self.assertMatches('...No payment selected...', self.browser.contents)
Note: See TracChangeset for help on using the changeset viewer.