Changeset 14170 for main


Ignore:
Timestamp:
20 Sep 2016, 11:35:42 (8 years ago)
Author:
Henrik Bettermann
Message:

Add export purge button.

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

Legend:

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

    r14169 r14170  
    441.4.2.dev0 (unreleased)
    55=======================
     6
     7* Add export purge button.
    68
    79* Add report purge button.
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r13959 r14170  
    205205    return
    206206
    207 def doll_up(view, user=None):
     207def doll_up(view, user=None, purge=False):
    208208    """Doll up export jobs for displaying in table.
    209209    """
     210    ob_class = view.__implemented__.__name__.replace('waeup.kofa.','')
    210211    job_entries = view.context.get_running_export_jobs(user)
    211212    job_manager = getUtility(IJobManager)
     
    234235                               job.failed and time_delta and \
    235236                               time_delta.days < 1
     237        if not show_download_button and purge:
     238            entry = view.context.entry_from_job_id(job_id)
     239            view.context.delete_export_entry(entry)
     240            view.context.logger.info(
     241                '%s - purged: job_id=%s' % (ob_class, job_id))
     242            continue
    236243        new_entry = dict(
    237244            job=job_id,
     
    18541861        return sorted(title_name_tuples)
    18551862
    1856     def update(self, CREATE=None, DISCARD=None, exporter=None,
     1863    def update(self, CREATE=None, DISCARD=None, PURGE=None, exporter=None,
    18571864               job_id=None, CANCEL=None):
    18581865        if CANCEL is not None:
     
    18761883                '%s - discarded: job_id=%s' % (ob_class, job_id))
    18771884            self.flash(_('Discarded export') + ' %s' % job_id)
    1878         self.entries = doll_up(self, user=None)
     1885        self.entries = doll_up(self, user=None, purge=PURGE)
     1886        if PURGE:
     1887            self.flash(_('Exports successfully purged.'))
    18791888        return
    18801889
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/reports.py

    r14169 r14170  
    5454            entry = self.context.report_entry_from_job_id(job_id)
    5555            self.context.delete_report_entry(entry)
    56             self.flash('Report discarded: %s' % job_id)
     56            self.flash('Report %s discarded' % job_id)
    5757            grok.getSite().logger.info(
    5858                '%s - report %s discarded' % (ob_class, job_id))
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/datacenterexportpage.pt

    r14166 r14170  
    3131  <div class="form-group">
    3232  <input type="submit" name="CANCEL" class="btn btn-default"
    33       tal:attributes="value view/cancel_button" />
     33      tal:attributes="value view/cancel_button"
     34      />
    3435  </div>
    3536</form>
     
    8687          <a href="" class="btn btn-primary btn-xs"
    8788                 tal:attributes="href job/download_url"
    88                  tal:condition="job/show_download_button">
     89                 tal:condition="job/show_download_button"
     90                 i18n:translate="">
    8991            Download</a>
    9092          <input type="hidden" name="job_id"
     
    9294          <input type="submit" class="btn btn-default btn-xs"
    9395                 name="DISCARD" value="Discard"
    94                  tal:condition="job/show_discard_button" />
     96                 tal:condition="job/show_discard_button"
     97                 i18n:translate=""/>
    9598        </form>
    9699      </td>
     
    98101  </tbody>
    99102</table>
     103
     104<form method="POST" i18n:domain="waeup.kofa">
     105  <div class="form-group">
     106    <input type="submit" class="btn btn-primary"
     107      name="PURGE" value="Purge outdated exports"
     108      data-toggle="tooltip"
     109      title="All exports older than 24 hours will be discarded!"
     110      i18n:translate=""
     111      />
     112  </div>
     113</form>
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py

    r14166 r14170  
    2424import os
    2525import grok
     26from datetime import datetime, timedelta
    2627from zc.async.testing import wait_for_result
    2728from zope.component import createObject, getUtility
     
    3233from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
    3334from waeup.kofa.app import University
    34 from waeup.kofa.interfaces import IJobManager, IUserAccount
     35from waeup.kofa.interfaces import IJobManager, IUserAccount, IKofaUtils
    3536from waeup.kofa.tests.test_async import FunctionalAsyncTestCase
    3637from waeup.kofa.university.faculty import Faculty
     
    435436        # we can discard a generated export result
    436437        self.trigger_export()
    437         self.wait_for_export_job_completed()
     438        job_id = self.wait_for_export_job_completed()
    438439        self.browser.open(self.datacenter_path + '/@@export')
    439440        self.browser.getControl("Discard").click()
     
    443444        logcontent = open(logfile).read()
    444445        self.assertTrue(
    445             'zope.mgr - browser.pages.ExportCSVPage - discarded: job_id='
    446             in logcontent)
     446            'zope.mgr - browser.pages.ExportCSVPage - discarded: job_id=%s'
     447            % job_id in logcontent)
     448        return
     449
     450    def test_export_purge(self):
     451        self.trigger_export()
     452        job_id = self.wait_for_export_job_completed()
     453        self.browser.open(self.datacenter_path + '/export')
     454        self.browser.getControl("Purge").click()
     455        # Flash message always says successful ...
     456        self.assertTrue(
     457            'Exports successfully purged.' in self.browser.contents)
     458        # ... but the export is still there
     459        self.assertEqual(len(self.app['datacenter'].running_exports), 1)
     460
     461        job_id, gen_name, user = self.app['datacenter'].get_running_export_jobs()[0]
     462        job = getUtility(IJobManager).get(job_id)
     463        tz = getUtility(IKofaUtils).tzinfo
     464        delta = timedelta(days=5)
     465        setattr(job, '_begin_after', datetime.now(tz) - delta)
     466        self.browser.getControl("Purge").click()
     467        self.assertEqual(len(self.app['datacenter'].running_exports), 0)
     468        logfile = os.path.join(
     469            self.app['datacenter'].storage, 'logs', 'datacenter.log')
     470        logcontent = open(logfile).read()
     471        self.assertTrue('zope.mgr - browser.pages.ExportCSVPage - '
     472                        'purged: job_id=%s' % job_id in logcontent)
    447473        return
    448474
Note: See TracChangeset for help on using the changeset viewer.