Ignore:
Timestamp:
29 Aug 2014, 19:04:38 (10 years ago)
Author:
Henrik Bettermann
Message:

Implement admission checking fee payment. Completely untested! Tests will follow.

Location:
main/waeup.uniben/trunk/src/waeup/uniben/applicants
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/applicants/applicant.py

    r9064 r11784  
    3131    grok.provides(ICustomApplicant)
    3232
     33    def admchecking_fee_paid(self):
     34        for key in self.keys():
     35            ticket = self[key]
     36            if ticket.p_state == 'paid' and ticket.p_category == 'admission_checking':
     37                return True
     38        return False
     39
    3340# Set all attributes of CustomApplicant required in ICustomApplicant as field
    3441# properties. Doing this, we do not have to set initial attributes
  • main/waeup.uniben/trunk/src/waeup/uniben/applicants/browser.py

    r11782 r11784  
    1919"""
    2020import grok
     21from time import time
    2122from zope.component import getUtility, createObject
    2223from zope.security import checkPermission
     24from hurry.workflow.interfaces import IWorkflowState
     25from waeup.kofa.browser.layout import action, UtilityView
    2326from waeup.kofa.interfaces import IExtFileStore
    2427from waeup.kofa.applicants.browser import (
    2528    ApplicantRegistrationPage, ApplicantsContainerPage,
    2629    ApplicationFeePaymentAddPage,
    27     OnlinePaymentApprovePage)
     30    OnlinePaymentApprovePage,
     31    ExportPDFPageApplicationSlip)
    2832from waeup.kofa.applicants.interfaces import (
    2933    ISpecialApplicant, IApplicantsUtils)
     
    3438from waeup.uniben.applicants.interfaces import (
    3539    ICustomApplicant)
     40from waeup.kofa.applicants.workflow import ADMITTED, PAID
    3641
    3742from waeup.uniben.interfaces import MessageFactory as _
     
    112117               and self.context.state in ('paid', 'submitted')
    113118
    114     # customizations for admission checking payments
     119    # Customizations for admission checking payments
     120
    115121    @property
    116122    def form_fields(self):
    117         if self.context.special:
    118             form_fields = grok.AutoFields(ISpecialApplicant).omit('locked')
    119         else:
    120             form_fields = grok.AutoFields(ICustomApplicant).omit(
    121                 'locked', 'course_admitted', 'password', 'suspended')
     123        form_fields = super(CustomApplicantDisplayFormPage, self).form_fields
     124        if not self.context.admchecking_fee_paid():
     125            form_fields = form_fields.omit(
     126                'screening_score', 'aggregate', 'student_id')
    122127        return form_fields
    123128
     129    @property
     130    def display_actions(self):
     131        state = IWorkflowState(self.context).getState()
     132        actions = []
     133        if state == ADMITTED and not self.context.admchecking_fee_paid():
     134            actions = [_('Add admission checking payment ticket')]
     135        return actions
     136
     137
     138    def getCourseAdmitted(self):
     139        """Return link, title and code in html format to the certificate
     140           admitted.
     141        """
     142        course_admitted = self.context.course_admitted
     143        if getattr(course_admitted, '__parent__',None) and \
     144            self.context.admchecking_fee_paid():
     145            url = self.url(course_admitted)
     146            title = course_admitted.title
     147            code = course_admitted.code
     148            return '<a href="%s">%s - %s</a>' %(url,code,title)
     149        return ''
     150
     151    @action(_('Add admission checking payment ticket'), style='primary')
     152    def addPaymentTicket(self, **data):
     153        self.redirect(self.url(self.context, '@@addacp'))
     154        return
     155
    124156class CustomNigeriaPDFApplicationSlip(NigeriaPDFApplicationSlip):
    125 
    126157
    127158    @property
     
    147178        return ''
    148179
    149     # customizations for admission checking payments
     180class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View):
     181    """ Page to add an admission checking online payment ticket.
     182    """
     183    grok.context(ICustomApplicant)
     184    grok.name('addacp')
     185    grok.require('waeup.payApplicant')
     186    factory = u'waeup.ApplicantOnlinePayment'
     187
     188    def _setPaymentDetails(self, payment):
     189        container = self.context.__parent__
     190        timestamp = ("%d" % int(time()*10000))[1:]
     191        session = str(container.year)
     192        try:
     193            session_config = grok.getSite()['configuration'][session]
     194        except KeyError:
     195            return _(u'Session configuration object is not available.'), None
     196        payment.p_id = "p%s" % timestamp
     197        payment.p_item = container.title
     198        payment.p_session = container.year
     199        payment.amount_auth = 0.0
     200        payment.p_category = 'admission_checking'
     201        payment.amount_auth = session_config.admchecking_fee
     202        if payment.amount_auth in (0.0, None):
     203            return _('Amount could not be determined.'), None
     204        return
     205
    150206    def update(self):
    151         # Additional requirements in custom packages.
    152         if self.custom_requirements:
    153             self.flash(
    154                 self.custom_requirements,
    155                 type='danger')
    156             self.redirect(self.url(self.context))
    157             return
    158         if not self.context.special:
    159             for key in self.context.keys():
    160                 ticket = self.context[key]
    161                 if ticket.p_state == 'paid':
    162                       self.flash(
    163                           _('This type of payment has already been made.'),
    164                           type='warning')
    165                       self.redirect(self.url(self.context))
    166                       return
    167         applicants_utils = getUtility(IApplicantsUtils)
    168         container = self.context.__parent__
     207        if self.context.admchecking_fee_paid():
     208              self.flash(
     209                  _('Admission checking payment has already been made.'),
     210                  type='warning')
     211              self.redirect(self.url(self.context))
     212              return
    169213        payment = createObject(self.factory)
    170         failure = applicants_utils.setPaymentDetails(
    171             container, payment, self.context)
     214        failure = self._setPaymentDetails(payment)
    172215        if failure is not None:
    173216            self.flash(failure[0], type='danger')
     
    179222        return
    180223
     224    def render(self):
     225        return
     226
    181227
    182228class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
     
    191237    """
    192238
    193     # customizations for admission checking payments
     239
    194240    def update(self):
    195         flashtype, msg, log = self.context.approveApplicantPayment()
     241        if self.context.p_category == 'admission_checking':
     242            if self.context.p_state == 'paid':
     243                flashtype = 'warning'
     244                msg = _('This ticket has already been paid.')
     245                log = None
     246            else:
     247                self.context.approve()
     248                log = 'payment approved: %s' % self.context.p_id
     249                msg = _('Payment approved')
     250                flashtype = 'success'
     251        else:
     252            flashtype, msg, log = self.context.approveApplicantPayment()
    196253        if log is not None:
    197254            applicant = self.context.__parent__
     
    206263        self.flash(msg, type=flashtype)
    207264        return
     265
     266class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
     267    """Deliver a PDF slip of the context.
     268    """
     269
     270
     271    def update(self):
     272        super(CustomExportPDFPageApplicationSlip, self).update()
     273        if self.context.state == ADMITTED and \
     274            not self.context.admchecking_fee_paid():
     275            self.flash(
     276                _('Please pay admission checking fee before trying to download '
     277                  'the application slip.'), type='warning')
     278            return self.redirect(self.url(self.context))
     279        return
  • main/waeup.uniben/trunk/src/waeup/uniben/applicants/browser_templates/applicantdisplaypage.pt

    r11315 r11784  
    109109  </tbody>
    110110</table>
     111<form action="." tal:attributes="action request/URL" method="post"
     112      i18n:domain="waeup.kofa">
     113  <div tal:condition="view/availableActions">
     114    <span tal:repeat="action view/actions"
     115          tal:omit-tag="">
     116      <input tal:condition="python:action.label in view.display_actions"
     117             tal:replace="structure action/render"/>
     118    </span>
     119  </div>
     120</form>
Note: See TracChangeset for help on using the changeset viewer.