Ignore:
Timestamp:
10 Oct 2011, 16:50:11 (13 years ago)
Author:
Henrik Bettermann
Message:

Add user interfaces to add, remove and manage student online payments.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
2 added
1 edited

Legend:

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

    r6859 r6869  
    1717"""
    1818import grok
    19 
     19from time import time
     20from datetime import date, datetime
    2021from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    2122from zope.component import createObject
     
    3031from waeup.sirp.interfaces import IWAeUPObject, IUserAccount
    3132from waeup.sirp.widgets.datewidget import (
    32     FriendlyDateWidget, FriendlyDateDisplayWidget)
     33    FriendlyDateWidget, FriendlyDateDisplayWidget,
     34    FriendlyDatetimeDisplayWidget)
    3335from waeup.sirp.students.interfaces import (
    3436    IStudentsContainer, IStudent, IStudentClearance, IStudentPasswordSetting,
     
    4244from waeup.sirp.students.vocabularies import StudyLevelSource
    4345from waeup.sirp.browser.resources import toggleall
     46from waeup.sirp.payments.interfaces import IOnlinePayment
    4447
    4548# Save function used for save methods in manager pages
     
    757760    grok.require('waeup.viewStudent')
    758761    form_fields = grok.AutoFields(IStudentPaymentsContainer)
    759     #grok.template('paymentspage')
     762    grok.template('paymentspage')
    760763    title = 'Payments'
    761764    pnav = 4
    762765
     766    def formatDatetime(self,datetimeobj):
     767        if isinstance(datetimeobj, datetime):
     768            return datetimeobj.strftime("%Y-%m-%d %H:%M:%S")
     769        else:
     770            return None
     771
    763772    @property
    764773    def label(self):
    765774        return '%s: Payments' % self.context.__parent__.fullname
     775
     776    def update(self):
     777        super(PaymentsDisplayFormPage, self).update()
     778        datatable.need()
     779        return
     780
     781class PaymentsManageFormPage(WAeUPEditFormPage):
     782    """ Page to manage the student payments
     783    """
     784    grok.context(IStudentPaymentsContainer)
     785    grok.name('manage')
     786    grok.require('waeup.manageStudents')
     787    form_fields = grok.AutoFields(IStudentPaymentsContainer)
     788    grok.template('paymentsmanagepage')
     789    title = 'Payments'
     790    pnav = 4
     791
     792    def formatDatetime(self,datetimeobj):
     793        if isinstance(datetimeobj, datetime):
     794            return datetimeobj.strftime("%Y-%m-%d %H:%M:%S")
     795        else:
     796            return None
     797
     798    @property
     799    def label(self):
     800        return '%s: Payments' % self.context.__parent__.fullname
     801
     802    def update(self):
     803        super(PaymentsManageFormPage, self).update()
     804        datatable.need()
     805        return
     806
     807    @grok.action('Remove selected tickets')
     808    def delPaymentTicket(self, **data):
     809        form = self.request.form
     810        if form.has_key('val_id'):
     811            child_id = form['val_id']
     812        else:
     813            self.flash('No payment selected.')
     814            self.redirect(self.url(self.context, '@@manage'))
     815            return
     816        if not isinstance(child_id, list):
     817            child_id = [child_id]
     818        deleted = []
     819        for id in child_id:
     820            try:
     821                del self.context[id]
     822                deleted.append(id)
     823            except:
     824                self.flash('Could not delete %s: %s: %s' % (
     825                        id, sys.exc_info()[0], sys.exc_info()[1]))
     826        if len(deleted):
     827            self.flash('Successfully removed: %s' % ', '.join(deleted))
     828        self.redirect(self.url(self.context, u'@@manage'))
     829        return
     830
     831    @grok.action('Add online payment ticket')
     832    def addPaymentTicket(self, **data):
     833        self.redirect(self.url(self.context, '@@addop'))
     834
     835class OnlinePaymentManageActionButton(ManageActionButton):
     836    grok.order(1)
     837    grok.context(IStudentPaymentsContainer)
     838    grok.view(PaymentsDisplayFormPage)
     839    grok.require('waeup.manageStudents')
     840    text = 'Manage payments'
     841    target = 'manage'
     842
     843class OnlinePaymentAddFormPage(WAeUPAddFormPage):
     844    """ Page to add an online payment ticket
     845    """
     846    grok.context(IStudentPaymentsContainer)
     847    grok.name('addop')
     848    grok.require('waeup.handleStudent')
     849    form_fields = grok.AutoFields(IOnlinePayment).select(
     850        'p_category')
     851    #grok.template('addpaymentpage')
     852    label = 'Add online payment'
     853    title = 'Payments'
     854    pnav = 4
     855
     856    @grok.action('Create ticket')
     857    def createTicket(self, **data):
     858        payment = createObject(u'waeup.OnlinePayment')
     859        self.applyData(payment, **data)
     860        timestamp = "%d" % int(time()*1000)
     861        #order_id = "%s%s" % (student_id[1:],timestamp)
     862        payment.p_id = "p%s" % timestamp
     863        self.context[payment.p_id] = payment
     864        self.flash('Payment ticket created.')
     865        self.redirect(self.url(self.context, u'@@manage'))
     866        return
     867
     868class OnlinePaymentDisplayFormPage(WAeUPDisplayFormPage):
     869    """ Page to view an online payment ticket
     870    """
     871    grok.context(IOnlinePayment)
     872    grok.name('index')
     873    grok.require('waeup.viewStudent')
     874    form_fields = grok.AutoFields(IOnlinePayment)
     875    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     876    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     877    pnav = 4
     878
     879    @property
     880    def title(self):
     881        return 'Online Payment Ticket %s' % self.context.p_id
     882
     883    @property
     884    def label(self):
     885        return '%s: Online Payment Ticket %s' % (
     886            self.context.__parent__.__parent__.fullname,self.context.p_id)
    766887
    767888class AccommodationDisplayFormPage(WAeUPDisplayFormPage):
Note: See TracChangeset for help on using the changeset viewer.