Changeset 14173 for main/waeup.ikoba
- Timestamp:
- 22 Sep 2016, 19:43:09 (8 years ago)
- Location:
- main/waeup.ikoba/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/CHANGES.txt
r13806 r14173 4 4 0.2.dev0 (unreleased) 5 5 ===================== 6 7 * Add reports and exports purge buttons. 6 8 7 9 * Add portal maintenance mode. -
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/pages.py
r13809 r14173 196 196 return 197 197 198 def doll_up(view, user=None ):198 def doll_up(view, user=None, purge=False): 199 199 """Doll up export jobs for displaying in table. 200 200 """ 201 ob_class = view.__implemented__.__name__.replace('waeup.ikoba.','') 201 202 job_entries = view.context.get_running_export_jobs(user) 202 203 job_manager = getUtility(IJobManager) … … 222 223 job.failed and time_delta and \ 223 224 time_delta.days < 1 225 if not show_download_button and purge: 226 entry = view.context.entry_from_job_id(job_id) 227 view.context.delete_export_entry(entry) 228 view.context.logger.info( 229 '%s - purged: job_id=%s' % (ob_class, job_id)) 230 continue 224 231 new_entry = dict( 225 232 job=job_id, … … 1628 1635 return sorted(title_name_tuples) 1629 1636 1630 def update(self, CREATE=None, DISCARD=None, exporter=None,1637 def update(self, CREATE=None, DISCARD=None, PURGE=None, exporter=None, 1631 1638 job_id=None, CANCEL=None): 1632 1639 if CANCEL is not None: … … 1657 1664 '%s - discarded: job_id=%s' % (ob_class, job_id)) 1658 1665 self.flash(_('Discarded export') + ' %s' % job_id) 1659 self.entries = doll_up(self, user=None) 1666 self.entries = doll_up(self, user=None, purge=PURGE) 1667 if PURGE: 1668 self.flash(_('Exports successfully purged.')) 1660 1669 return 1661 1670 -
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/reports.py
r12659 r14173 19 19 """ 20 20 import grok 21 from datetime import datetime, timedelta 21 22 from zope.component import getUtility, queryUtility 22 23 from zope.location.location import located 24 from zope.security import checkPermission 23 25 from waeup.ikoba.interfaces import IJobManager, IIkobaUtils 24 26 from waeup.ikoba.interfaces import MessageFactory as _ 25 from waeup.ikoba.browser.layout import IkobaPage 27 from waeup.ikoba.browser.layout import IkobaPage, jsaction 26 28 from waeup.ikoba.reports import IReportsContainer, IReportGenerator 27 29 from waeup.ikoba.reports import get_generators … … 42 44 return self.url(self.context, '%s/pdf' % job_id) 43 45 44 def update(self, job_id=None, DISCARD=None, DOWNLOAD=None ):46 def update(self, job_id=None, DISCARD=None, DOWNLOAD=None, PURGE=None): 45 47 self.entries = [] 48 ob_class = self.__implemented__.__name__.replace('waeup.ikoba.', '') 46 49 if job_id and DISCARD: 47 50 entry = self.context.report_entry_from_job_id(job_id) 48 51 self.context.delete_report_entry(entry) 49 self.flash('Report discarded: %s' % job_id) 50 ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','') 52 self.flash('Report %s discarded' % job_id) 51 53 grok.getSite().logger.info( 52 54 '%s - report %s discarded' % (ob_class, job_id)) 53 self.entries = self._generate_entries(user_id=None) 55 if not checkPermission('waeup.manageReports', self.context): 56 user_id = get_current_principal().id 57 else: 58 user_id = None 59 self.entries = self._generate_entries(user_id=user_id) 54 60 if job_id and DOWNLOAD: 55 61 self.redirect(self._report_url(job_id)) 56 62 return 63 if PURGE: 64 counter = 0 65 for entry in self.context.get_running_report_jobs(user_id=user_id): 66 job_id, gen_name, user = entry 67 job = getUtility(IJobManager).get(job_id) 68 starttime = getattr(job, 'begin_after', None) 69 delta = timedelta(weeks=4) 70 tz = getUtility(IIkobaUtils).tzinfo 71 if datetime.now(tz) - delta > starttime: 72 self.context.delete_report_entry(entry) 73 counter += 1 74 grok.getSite().logger.info( 75 '%s - report %s purged' % (ob_class, job_id)) 76 self.flash('%s report(s) purged.' % counter) 77 self.redirect(self.url(self.context)) 57 78 return 58 79 -
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/templates/datacenterexportpage.pt
r12633 r14173 79 79 <a href="" class="btn btn-primary btn-xs" 80 80 tal:attributes="href job/download_url" 81 tal:condition="job/show_download_button"> 81 tal:condition="job/show_download_button" 82 i18n:translate=""> 82 83 Download</a> 83 84 <input type="hidden" name="job_id" … … 85 86 <input type="submit" class="btn btn-default btn-xs" 86 87 name="DISCARD" value="Discard" 87 tal:condition="job/show_discard_button" /> 88 tal:condition="job/show_discard_button" 89 i18n:translate=""/> 88 90 </form> 89 91 </td> … … 91 93 </tbody> 92 94 </table> 95 96 <form method="POST" i18n:domain="waeup.ikoba"> 97 <div class="form-group"> 98 <input type="submit" class="btn btn-primary" 99 name="PURGE" value="Purge outdated exports" 100 data-toggle="tooltip" 101 title="All exports older than 24 hours will be discarded!" 102 i18n:translate="" 103 /> 104 </div> 105 </form> -
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/templates/reportscontainerpage.pt
r11949 r14173 48 48 </table> 49 49 <form method="POST" i18n:domain="waeup.ikoba"> 50 <a tal:attributes="href python:view.url(context, 'create')" 51 class="btn btn-primary" i18n:translate=""> 52 Create new report 53 </a> 50 <div class="form-group"> 51 <a tal:attributes="href python:view.url(context, 'create')" 52 class="btn btn-primary" i18n:translate=""> 53 Create new report 54 </a> 55 <input type="submit" class="btn btn-default" 56 name="PURGE" value="Purge outdated reports" 57 data-toggle="tooltip" title="All reports older than 4 weeks will be discarded!" 58 onclick="return window.confirm('Are you really sure?')"/> 59 </div> 54 60 </form> -
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/tests/test_browser.py
r13808 r14173 24 24 import os 25 25 import grok 26 from datetime import datetime, timedelta 26 27 from zc.async.testing import wait_for_result 27 28 from zope.component import createObject, getUtility … … 32 33 from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase 33 34 from waeup.ikoba.app import Company 34 from waeup.ikoba.interfaces import IJobManager, IUserAccount 35 from waeup.ikoba.interfaces import IJobManager, IUserAccount, IIkobaUtils 35 36 from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase 36 37 … … 83 84 wait_for_result(job) 84 85 return job_id 86 87 def trigger_export(self): 88 # helper to start an export. Make sure to remove the result file 89 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 90 self.browser.open(self.datacenter_path) 91 self.browser.getLink("Export data").click() 92 self.browser.getControl(name="exporter").value = ['products'] 93 self.browser.getControl("Create CSV file").click() 94 return 85 95 86 96 def cleanup_run_job(self): … … 194 204 return 195 205 206 def test_export_download(self): 207 # we can download a generated export result 208 self.trigger_export() 209 # while the export file is created, we get a reload button 210 # (or a loading bar if javascript is enabled)... 211 self.assertTrue('Reload' in self.browser.contents) 212 # ...which is displayed as long as the job is not finished. 213 # When the job is finished and we reload the page... 214 job_id = self.wait_for_export_job_completed() 215 self.browser.open(self.datacenter_path + '/export') 216 self.assertFalse('Reload' in self.browser.contents) 217 # ...we can download the result 218 self.browser.getLink("Download").click() 219 self.assertEqual(self.browser.headers['content-type'], 220 'text/csv; charset=UTF-8') 221 self.assertEqual(self.browser.headers['content-disposition'], 222 'attachment; filename="WAeUP.Ikoba_products_%s.csv' % job_id) 223 self.assertEqual(self.browser.contents, 224 'contract_category,contract_title,description,options,' 225 'product_id,terms_and_conditions,title,valid_from,valid_to,' 226 'users_with_local_roles\r\n') 227 # Thew job can be discarded 228 self.browser.open(self.datacenter_path + '/export') 229 self.browser.getControl("Discard").click() 230 self.assertEqual(len(self.app['datacenter'].running_exports), 0) 231 logfile = os.path.join( 232 self.app['datacenter'].storage, 'logs', 'datacenter.log') 233 logcontent = open(logfile).read() 234 self.assertTrue('zope.mgr - browser.pages.ExportCSVPage - exported: ' 235 'products, job_id=' in logcontent) 236 self.assertTrue('zope.mgr - browser.pages.ExportCSVView - ' 237 'downloaded: WAeUP.Ikoba_products_%s.csv, job_id=%s' 238 % (job_id, job_id) in logcontent) 239 return 240 241 def test_export_discard(self): 242 # we can discard a generated export result 243 self.trigger_export() 244 job_id = self.wait_for_export_job_completed() 245 self.browser.open(self.datacenter_path + '/@@export') 246 self.browser.getControl("Discard").click() 247 self.assertTrue('Discarded export' in self.browser.contents) 248 logfile = os.path.join( 249 self.app['datacenter'].storage, 'logs', 'datacenter.log') 250 logcontent = open(logfile).read() 251 self.assertTrue( 252 'zope.mgr - browser.pages.ExportCSVPage - discarded: job_id=%s' 253 % job_id in logcontent) 254 return 255 256 def test_export_purge(self): 257 self.trigger_export() 258 job_id = self.wait_for_export_job_completed() 259 self.browser.open(self.datacenter_path + '/export') 260 self.browser.getControl("Purge").click() 261 # Flash message always says successful ... 262 self.assertTrue( 263 'Exports successfully purged.' in self.browser.contents) 264 # ... but the export is still there 265 self.assertEqual(len(self.app['datacenter'].running_exports), 1) 266 267 job_id, gen_name, user = self.app['datacenter'].get_running_export_jobs()[0] 268 job = getUtility(IJobManager).get(job_id) 269 tz = getUtility(IIkobaUtils).tzinfo 270 delta = timedelta(days=5) 271 setattr(job, '_begin_after', datetime.now(tz) - delta) 272 self.browser.getControl("Purge").click() 273 self.assertEqual(len(self.app['datacenter'].running_exports), 0) 274 logfile = os.path.join( 275 self.app['datacenter'].storage, 'logs', 'datacenter.log') 276 logcontent = open(logfile).read() 277 self.assertTrue('zope.mgr - browser.pages.ExportCSVPage - ' 278 'purged: job_id=%s' % job_id in logcontent) 279 return 280 196 281 197 282 class SupplementaryBrowserTests(CompanySetup): -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/reports/tests/test_contract_statistics.py
r12663 r14173 1 1 # Tests for contract related reports 2 2 import os 3 from datetime import datetime, timedelta 3 4 from zc.async.testing import wait_for_result 4 5 from zope.interface.verify import verifyClass, verifyObject 5 6 from zope.component import getUtility 6 from waeup.ikoba.interfaces import IJobManager 7 from waeup.ikoba.interfaces import IJobManager, IIkobaUtils 7 8 from waeup.ikoba.customers.reports.contract_statistics import ( 8 9 get_contract_stats, ContractStatisticsReport, IContractStatisticsReport) … … 118 119 ) 119 120 return 121 122 def test_report_purge(self): 123 self.trigger_report_creation() 124 job_id = self.wait_for_report_job_completed() 125 self.browser.open('http://localhost/app/reports') 126 self.browser.getControl("Purge").click() 127 self.assertTrue('0 report(s) purged' in self.browser.contents) 128 job_id, gen_name, user = self.app['reports'].get_running_report_jobs(user_id=None)[0] 129 job = getUtility(IJobManager).get(job_id) 130 tz = getUtility(IIkobaUtils).tzinfo 131 delta = timedelta(weeks=5) 132 setattr(job, '_begin_after', datetime.now(tz) - delta) 133 self.browser.getControl("Purge").click() 134 self.assertTrue('1 report(s) purged' in self.browser.contents) 135 logfile = os.path.join( 136 self.app['datacenter'].storage, 'logs', 'main.log') 137 logcontent = open(logfile).read() 138 self.assertTrue( 139 'INFO - zope.mgr - browser.reports.ReportsContainerPage - ' 140 'report %s purged' % job_id in logcontent 141 ) 142 return
Note: See TracChangeset for help on using the changeset viewer.