Changeset 15498


Ignore:
Timestamp:
15 Jul 2019, 19:44:05 (7 years ago)
Author:
Henrik Bettermann
Message:

Add components to enable exports in applicants section for bursary officers.

File:
1 edited

Legend:

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

    r14865 r15498  
    1919"""
    2020import grok
    21 from zope.component import getUtility
     21from zope.component import getUtility, queryUtility
    2222from zope.i18n import translate
    2323from hurry.workflow.interfaces import IWorkflowState
    … …  
    2525from zope.formlib.textwidgets import BytesDisplayWidget
    2626from waeup.kofa.interfaces import IExtFileStore, IKofaUtils
     27from waeup.kofa.browser.pages import doll_up
    2728from waeup.kofa.applicants.interfaces import (
    28     IApplicant, IApplicantEdit)
     29    IApplicant, IApplicantEdit,
     30    IApplicantsContainer,)
    2931from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
    3032    ApplicantManageFormPage, ApplicantEditFormPage,
    31     ApplicantsContainerPage, ApplicationFeePaymentAddPage)
     33    ApplicantsContainerPage, ApplicationFeePaymentAddPage,
     34    ExportJobContainerOverview,
     35    ExportJobContainerJobStart,
     36    ExportJobContainerDownload)
     37from waeup.kofa.browser.viewlets import ManageActionButton
    3238from waeup.kofa.applicants.viewlets import (
    3339    PaymentReceiptActionButton, PDFActionButton)
    … …  
    6369    ]
    6470
     71##### Bursary exports
     72
     73class BursaryExportPaymentsActionButton(ManageActionButton):
     74    """ 'Export payment data' button for faculties.
     75    """
     76    grok.context(IApplicantsContainer)
     77    grok.view(ApplicantsContainerPage)
     78    grok.require('waeup.exportBursaryData')
     79    icon = 'actionicon_down.png'
     80    text = _('Export payment data')
     81    target = 'bursary_exports/index2.html'
     82    grok.order(4)
     83
     84class BursaryExportJobContainerOverview(ExportJobContainerOverview):
     85    """Page that lists active applicant data export jobs and provides links
     86    to discard or download CSV files.
     87    """
     88    grok.require('waeup.exportBursaryData')
     89    grok.name('index2.html')
     90
     91    def update(self, CREATE=None, DISCARD=None, job_id=None):
     92        if CREATE:
     93            self.redirect(self.url('@@start_bursary_export'))
     94            return
     95        if DISCARD and job_id:
     96            entry = self.context.entry_from_job_id(job_id)
     97            self.context.delete_export_entry(entry)
     98            ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
     99            self.context.logger.info(
     100                '%s - discarded: job_id=%s' % (ob_class, job_id))
     101            self.flash(_('Discarded export') + ' %s' % job_id)
     102        self.entries = doll_up(self, user=self.request.principal.id)
     103        return
     104
     105class  BursaryExportJobContainerJobStart(ExportJobContainerJobStart):
     106    """View that starts export job.
     107    """
     108    grok.require('waeup.exportBursaryData')
     109    grok.name('start_bursary_export')
     110
     111    def update(self):
     112        utils = queryUtility(IKofaUtils)
     113        if not utils.expensive_actions_allowed():
     114            self.flash(_(
     115                "Currently, exporters cannot be started due to high "
     116                "system load. Please try again later."), type='danger')
     117            self.entries = doll_up(self, user=None)
     118            return
     119
     120        ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
     121        container_code = self.context.__parent__.code
     122        # Start payments exporter
     123        exporter = 'applicantpayments'
     124        job_id = self.context.start_export_job(exporter,
     125                                      self.request.principal.id,
     126                                      container=container_code)
     127        self.context.logger.info(
     128            '%s - exported: %s (%s), job_id=%s'
     129            % (ob_class, exporter, container_code, job_id))
     130
     131        self.flash(_('Exports started.'))
     132        self.redirect(self.url(self.context))
     133        return
     134
     135    def render(self):
     136        return
     137
     138class BursaryExportJobContainerDownload(ExportJobContainerDownload):
     139    """Page that downloads a students export csv file.
     140
     141    """
     142    grok.require('waeup.exportBursaryData')
     143    grok.context(IApplicantsContainer)
     144
    65145class CustomApplicantsContainerPage(ApplicantsContainerPage):
    66146    """The standard view for regular applicant containers.
Note: See TracChangeset for help on using the changeset viewer.