Changeset 16064 for main/waeup.kofa


Ignore:
Timestamp:
21 Apr 2020, 07:58:26 (5 years ago)
Author:
Henrik Bettermann
Message:

Implement ApplicantRefereeReportExporter.

Location:
main/waeup.kofa/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r16059 r16064  
    441.6.1.dev0 (unreleased)
    55=======================
     6
     7* Implement `ApplicantRefereeReportExporter`.
    68
    79* Improve referee reports.
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r16059 r16064  
    16641664
    16651665class ExportJobContainerJobStart(UtilityView, grok.View):
    1666     """View that starts two export jobs, one for applicants and a second
    1667     one for applicant payments.
     1666    """View that starts three export jobs, one for applicants, a second
     1667    one for applicant payments and a third for referee reports.
    16681668    """
    16691669    grok.context(VirtualApplicantsExportJobContainer)
     
    16831683        container_code = self.context.__parent__.code
    16841684        # Start first exporter
    1685         exporter = 'applicants'
    1686         job_id = self.context.start_export_job(exporter,
    1687                                       self.request.principal.id,
    1688                                       container=container_code)
    1689         self.context.logger.info(
    1690             '%s - exported: %s (%s), job_id=%s'
    1691             % (ob_class, exporter, container_code, job_id))
    1692         # Commit transaction so that job is stored in the ZODB
    1693         transaction.commit()
    1694         # Start second exporter
    1695         exporter = 'applicantpayments'
    1696         job_id = self.context.start_export_job(exporter,
    1697                                       self.request.principal.id,
    1698                                       container=container_code)
    1699         self.context.logger.info(
    1700             '%s - exported: %s (%s), job_id=%s'
    1701             % (ob_class, exporter, container_code, job_id))
    1702 
     1685        for exporter in ('applicants',
     1686                         'applicantpayments',
     1687                         'applicantrefereereports'):
     1688            job_id = self.context.start_export_job(exporter,
     1689                                          self.request.principal.id,
     1690                                          container=container_code)
     1691            self.context.logger.info(
     1692                '%s - exported: %s (%s), job_id=%s'
     1693                % (ob_class, exporter, container_code, job_id))
     1694            # Commit transaction so that job is stored in the ZODB
     1695            transaction.commit()
    17031696        self.flash(_('Exports started.'))
    17041697        self.redirect(self.url(self.context))
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/export.py

    r15156 r16064  
    2222from zope.component import queryUtility
    2323from waeup.kofa.applicants.interfaces import (
    24     IApplicantBaseData, IApplicantsContainer, IApplicantOnlinePayment)
     24    IApplicantBaseData, IApplicantsContainer, IApplicantOnlinePayment,
     25    IApplicantRefereeReport)
    2526from waeup.kofa.interfaces import ICSVExporter
    2627from waeup.kofa.interfaces import MessageFactory as _
     
    145146
    146147class ApplicantPaymentExporter(grok.GlobalUtility, ExporterBase):
    147     """The Applicant Payments Exporter exports all payments made by applicants.
     148    """The Applicant Payment Exporter exports all payments made by applicants.
    148149    In other words, it exports payment tickets in state 'paid'. The exporter
    149150    searches :class:`ApplicantsCatalog` and iterates over all payment tickets
     
    219220                    payments.append(payment)
    220221        return self.export(payments, filepath=filepath)
     222
     223class ApplicantRefereeReportExporter(grok.GlobalUtility, ExporterBase):
     224    """The Applicant Referee Report Exporter exports all referee reports.
     225    The exportersearches :class:`ApplicantsCatalog` and iterates over all
     226    referee reports which are stored in an applicant (container).
     227
     228    The exporter exports all referee reports if started in the Data Center
     229    which means in the context of the `DataCenter` object. The exporter can also
     230    be started 'locally' which means in the context of an
     231    `ApplicantsContainer` container, see `ApplicantExporter` above.
     232    """
     233    grok.implements(ICSVExporter)
     234    grok.name('applicantrefereereports')
     235
     236    fields = tuple(sorted(iface_names(
     237        IApplicantRefereeReport,
     238        exclude_attribs=False,
     239        omit=['display_item']))) + (
     240              'applicant_id',
     241              'reg_number',
     242              'display_fullname',)
     243    title = _(u'Applicant Referee Reports')
     244
     245    def mangle_value(self, value, name, context=None):
     246        """The mangler determines the applicant's id.
     247        """
     248        if name in ('applicant_id', 'reg_number',
     249            'display_fullname',) and context is not None:
     250            applicant = context.__parent__
     251            value = getattr(applicant, name, None)
     252        return super(
     253            ApplicantRefereeReportExporter, self).mangle_value(
     254            value, name, context=context)
     255
     256    def export(self, payments, filepath=None):
     257        """
     258        """
     259        writer, outfile = self.get_csv_writer(filepath)
     260        for payment in payments:
     261            self.write_item(payment, writer)
     262        return self.close_outfile(filepath, outfile)
     263
     264    def export_all(self, site, filepath=None):
     265        """
     266        """
     267        catalog = queryUtility(
     268            ICatalog, context=site, name='applicants_catalog', default=None)
     269        if catalog is None:
     270            return self.export([], filepath)
     271        applicants = catalog.searchResults(
     272            # reg_num might not be set and then would not be found.
     273            # We therefore search for applicant_id.
     274            applicant_id=(None, None))
     275        refereereports = []
     276        for applicant in applicants:
     277            for refereereport in applicant.refereereports:
     278                refereereports.append(refereereport)
     279            return self.export(refereereports, filepath=filepath)
     280
     281    def export_filtered(self, site, filepath=None, **kw):
     282        """
     283        """
     284        container = grok.getSite()['applicants'][kw['container']]
     285        container_values = container.values()
     286        refereereports = []
     287        for applicant in container_values:
     288            for refereereport in applicant.refereereports:
     289                refereereports.append(refereereport)
     290            return self.export(refereereports, filepath=filepath)
     291        return self.export(refereereports, filepath=filepath)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r16059 r16064  
    15621562        self.browser.getControl("Start new exports").click()
    15631563        job_ids = self.wait_for_export_jobs_completed()
    1564         # Two exports were created
    1565         self.assertEqual(len(self.app['datacenter'].running_exports), 2)
     1564        # Three exports were created
     1565        self.assertEqual(len(self.app['datacenter'].running_exports), 3)
    15661566       # When the jobs are finished and we reload the page...
    15671567        self.browser.open(container_path + '/exports')
     
    15801580            'filename="WAeUP.Kofa_applicantpayments_%s.csv' % job_ids[1] in
    15811581            self.browser.headers['content-disposition'])
     1582        self.browser.open(container_path + '/exports')
     1583        self.browser.getLink("Download", index=2).click()
     1584        self.assertEqual(self.browser.headers['content-type'],
     1585            'text/csv; charset=UTF-8')
     1586        self.assertTrue(
     1587            'filename="WAeUP.Kofa_applicantrefereereports_%s.csv' % job_ids[2] in
     1588            self.browser.headers['content-disposition'])
    15821589        # ... and discarded
    15831590        self.browser.open(container_path + '/exports')
     1591        self.browser.getControl("Discard", index=0).click()
     1592        self.assertEqual(len(self.app['datacenter'].running_exports), 2)
    15841593        self.browser.getControl("Discard", index=0).click()
    15851594        self.assertEqual(len(self.app['datacenter'].running_exports), 1)
     
    16171626            'zope.mgr - applicants.browser.ExportJobContainerOverview '
    16181627            '- discarded: job_id=%s' % job_ids[1] in logcontent
     1628            )
     1629        self.assertTrue(
     1630            'zope.mgr - applicants.browser.ExportJobContainerJobStart - '
     1631            'exported: applicantrefereereports (%s), job_id=%s'
     1632            % (container_name_1, job_ids[2]) in logcontent
     1633            )
     1634        self.assertTrue(
     1635            'zope.mgr - applicants.browser.ExportJobContainerDownload '
     1636            '- downloaded: WAeUP.Kofa_applicantrefereereports_%s.csv, job_id=%s'
     1637            % (job_ids[2], job_ids[2]) in logcontent
     1638            )
     1639        self.assertTrue(
     1640            'zope.mgr - applicants.browser.ExportJobContainerOverview '
     1641            '- discarded: job_id=%s' % job_ids[2] in logcontent
    16191642            )
    16201643
Note: See TracChangeset for help on using the changeset viewer.