Ignore:
Timestamp:
5 Sep 2018, 10:58:59 (6 years ago)
Author:
Henrik Bettermann
Message:

Applicants have to pay an admission checking fee before they can view their admission 'status'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/applicants/browser.py

    r15087 r15123  
    1919"""
    2020import grok
     21from time import time
    2122from zope.formlib.textwidgets import BytesDisplayWidget
     23from zope.component import getUtility, createObject
     24from hurry.workflow.interfaces import IWorkflowState
    2225from waeup.kofa.applicants.browser import (
    23     ApplicantRegistrationPage, ApplicantsContainerPage)
     26    ApplicantRegistrationPage, ApplicantsContainerPage,
     27    ExportPDFPageApplicationSlip)
     28from waeup.kofa.browser.layout import action, UtilityView
    2429from kofacustom.nigeria.applicants.browser import (
    2530    NigeriaApplicantDisplayFormPage,
     
    3742    PG_OMIT_EDIT_FIELDS,
    3843    )
     44from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED
    3945from kofacustom.edopoly.applicants.interfaces import (
    4046    ICustomUGApplicantEdit, ICustomUGApplicant,
    41     ICustomPGApplicantEdit, ICustomPGApplicant)
     47    ICustomPGApplicantEdit, ICustomPGApplicant,
     48    ICustomApplicant,)
    4249
    4350from kofacustom.edopoly.interfaces import MessageFactory as _
     
    7582    """A display view for applicant data.
    7683    """
     84    grok.template('applicantdisplaypage')
    7785
    7886    @property
     
    8088        target = getattr(self.context.__parent__, 'prefix', None)
    8189        form_fields = grok.AutoFields(ICustomUGApplicant)
     90        for field in UG_OMIT_DISPLAY_FIELDS:
     91            form_fields = form_fields.omit(field)
    8292        form_fields['notice'].custom_widget = BytesDisplayWidget
    8393        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
     
    90100        if not getattr(self.context, 'screening_date'):
    91101            form_fields = form_fields.omit('screening_date')
    92         return form_fields
     102        if not self.context.admchecking_fee_paid():
     103            form_fields = form_fields.omit(
     104                'screening_score', 'aggregate', 'student_id')
     105        return form_fields
     106
     107    @property
     108    def admission_checking_info(self):
     109        if self.context.state == ADMITTED and \
     110            not self.context.admchecking_fee_paid():
     111            return _('You must pay the admission checking fee '
     112                     'to view your screening results and course admitted.')
     113
     114    @property
     115    def display_actions(self):
     116        state = IWorkflowState(self.context).getState()
     117        actions = []
     118        if state == ADMITTED and not self.context.admchecking_fee_paid():
     119            actions = [_('Add admission checking payment ticket')]
     120        return actions
     121
     122    def getCourseAdmitted(self):
     123        """Return link, title and code in html format to the certificate
     124           admitted.
     125        """
     126        if self.admission_checking_info:
     127            return self.admission_checking_info
     128        return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted()
     129
     130    @action(_('Add admission checking payment ticket'), style='primary')
     131    def addPaymentTicket(self, **data):
     132        self.redirect(self.url(self.context, '@@addacp'))
     133        return
     134
     135class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View):
     136    """ Page to add an admission checking online payment ticket.
     137    """
     138    grok.context(ICustomApplicant)
     139    grok.name('addacp')
     140    grok.require('waeup.payApplicant')
     141    factory = u'waeup.ApplicantOnlinePayment'
     142
     143    def _setPaymentDetails(self, payment):
     144        container = self.context.__parent__
     145        timestamp = ("%d" % int(time()*10000))[1:]
     146        session = str(container.year)
     147        try:
     148            session_config = grok.getSite()['configuration'][session]
     149        except KeyError:
     150            return _(u'Session configuration object is not available.'), None
     151        payment.p_id = "p%s" % timestamp
     152        payment.p_item = container.title
     153        payment.p_session = container.year
     154        payment.amount_auth = 0.0
     155        payment.p_category = 'admission_checking'
     156        payment.amount_auth = session_config.admchecking_fee
     157        if payment.amount_auth in (0.0, None):
     158            return _('Amount could not be determined.'), None
     159        return
     160
     161    def update(self):
     162        if self.context.admchecking_fee_paid():
     163              self.flash(
     164                  _('Admission checking payment has already been made.'),
     165                  type='warning')
     166              self.redirect(self.url(self.context))
     167              return
     168        payment = createObject(self.factory)
     169        failure = self._setPaymentDetails(payment)
     170        if failure is not None:
     171            self.flash(failure[0], type='danger')
     172            self.redirect(self.url(self.context))
     173            return
     174        self.context[payment.p_id] = payment
     175        self.flash(_('Payment ticket created.'))
     176        self.redirect(self.url(payment))
     177        return
     178
     179    def render(self):
     180        return
     181
     182class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
     183    """Deliver a PDF slip of the context.
     184    """
     185
     186    def update(self):
     187        super(CustomExportPDFPageApplicationSlip, self).update()
     188        if self.context.state == ADMITTED and \
     189            not self.context.admchecking_fee_paid():
     190            self.flash(
     191                _('Please pay admission checking fee before trying to download '
     192                  'the application slip.'), type='warning')
     193            return self.redirect(self.url(self.context))
     194        return
    93195
    94196class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
Note: See TracChangeset for help on using the changeset viewer.