Changeset 16064
- Timestamp:
- 21 Apr 2020, 07:58:26 (5 years ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r16059 r16064 4 4 1.6.1.dev0 (unreleased) 5 5 ======================= 6 7 * Implement `ApplicantRefereeReportExporter`. 6 8 7 9 * Improve referee reports. -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
r16059 r16064 1664 1664 1665 1665 class ExportJobContainerJobStart(UtilityView, grok.View): 1666 """View that starts t wo export jobs, one for applicants anda second1667 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. 1668 1668 """ 1669 1669 grok.context(VirtualApplicantsExportJobContainer) … … 1683 1683 container_code = self.context.__parent__.code 1684 1684 # 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() 1703 1696 self.flash(_('Exports started.')) 1704 1697 self.redirect(self.url(self.context)) -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/export.py
r15156 r16064 22 22 from zope.component import queryUtility 23 23 from waeup.kofa.applicants.interfaces import ( 24 IApplicantBaseData, IApplicantsContainer, IApplicantOnlinePayment) 24 IApplicantBaseData, IApplicantsContainer, IApplicantOnlinePayment, 25 IApplicantRefereeReport) 25 26 from waeup.kofa.interfaces import ICSVExporter 26 27 from waeup.kofa.interfaces import MessageFactory as _ … … 145 146 146 147 class ApplicantPaymentExporter(grok.GlobalUtility, ExporterBase): 147 """The Applicant Payment sExporter exports all payments made by applicants.148 """The Applicant Payment Exporter exports all payments made by applicants. 148 149 In other words, it exports payment tickets in state 'paid'. The exporter 149 150 searches :class:`ApplicantsCatalog` and iterates over all payment tickets … … 219 220 payments.append(payment) 220 221 return self.export(payments, filepath=filepath) 222 223 class 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 1562 1562 self.browser.getControl("Start new exports").click() 1563 1563 job_ids = self.wait_for_export_jobs_completed() 1564 # T woexports were created1565 self.assertEqual(len(self.app['datacenter'].running_exports), 2)1564 # Three exports were created 1565 self.assertEqual(len(self.app['datacenter'].running_exports), 3) 1566 1566 # When the jobs are finished and we reload the page... 1567 1567 self.browser.open(container_path + '/exports') … … 1580 1580 'filename="WAeUP.Kofa_applicantpayments_%s.csv' % job_ids[1] in 1581 1581 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']) 1582 1589 # ... and discarded 1583 1590 self.browser.open(container_path + '/exports') 1591 self.browser.getControl("Discard", index=0).click() 1592 self.assertEqual(len(self.app['datacenter'].running_exports), 2) 1584 1593 self.browser.getControl("Discard", index=0).click() 1585 1594 self.assertEqual(len(self.app['datacenter'].running_exports), 1) … … 1617 1626 'zope.mgr - applicants.browser.ExportJobContainerOverview ' 1618 1627 '- 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 1619 1642 ) 1620 1643
Note: See TracChangeset for help on using the changeset viewer.