Ignore:
Timestamp:
20 Sep 2016, 08:33:44 (8 years ago)
Author:
Henrik Bettermann
Message:

Add report purge button.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/browser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/reports.py

    r13958 r14169  
    1919"""
    2020import grok
     21from datetime import datetime, timedelta
    2122from zope.i18n import translate
    2223from zope.component import getUtility, queryUtility
     
    2526from waeup.kofa.interfaces import IJobManager, IKofaUtils
    2627from waeup.kofa.interfaces import MessageFactory as _
    27 from waeup.kofa.browser.layout import KofaPage
     28from waeup.kofa.browser.layout import KofaPage, jsaction
    2829from waeup.kofa.utils.helpers import get_current_principal
    2930from waeup.kofa.reports import (
     
    4748        return self.url(self.context, '%s/pdf' % job_id)
    4849
    49     def update(self, job_id=None, DISCARD=None, DOWNLOAD=None):
     50    def update(self, job_id=None, DISCARD=None, DOWNLOAD=None, PURGE=None):
    5051        self.entries = []
     52        ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '')
    5153        if job_id and DISCARD:
    5254            entry = self.context.report_entry_from_job_id(job_id)
    5355            self.context.delete_report_entry(entry)
    5456            self.flash('Report discarded: %s' % job_id)
    55             ob_class = self.__implemented__.__name__.replace(
    56                 'waeup.kofa.', '')
    5757            grok.getSite().logger.info(
    5858                '%s - report %s discarded' % (ob_class, job_id))
    5959        if not checkPermission('waeup.manageReports', self.context):
    60             user = get_current_principal()
    61             self.entries = self._generate_entries(user_id=user.id)
     60            user_id = get_current_principal().id
    6261        else:
    63             self.entries = self._generate_entries(user_id=None)
     62            user_id = None
     63        self.entries = self._generate_entries(user_id=user_id)
    6464        if job_id and DOWNLOAD:
    6565            self.redirect(self._report_url(job_id))
    6666            return
     67        if PURGE:
     68            counter = 0
     69            for entry in self.context.get_running_report_jobs(user_id=user_id):
     70                job_id, gen_name, user = entry
     71                job = getUtility(IJobManager).get(job_id)
     72                starttime = getattr(job, 'begin_after', None)
     73                delta = timedelta(weeks=4)
     74                tz = getUtility(IKofaUtils).tzinfo
     75                if datetime.now(tz) - delta > starttime:
     76                    self.context.delete_report_entry(entry)
     77                    counter += 1
     78                    grok.getSite().logger.info(
     79                        '%s - report %s purged' % (ob_class, job_id))
     80            self.flash('%s report(s) purged' % counter)
     81            self.redirect(self.url(self.context))
    6782        return
    6883
     
    87102            entries.append(new_entry)
    88103        return entries
    89 
    90104
    91105class ReportsContainerTraverser(grok.Traverser):
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/reportscontainerpage.pt

    r11254 r14169  
    4747  </tbody>
    4848</table>
     49
    4950<form method="POST" i18n:domain="waeup.kofa">
    50   <a tal:attributes="href python:view.url(context, 'create')"
    51      class="btn btn-primary" i18n:translate="">
    52     Create new report
    53   </a>
     51  <div class="form-group">
     52    <a tal:attributes="href python:view.url(context, 'create')"
     53       class="btn btn-primary" i18n:translate="">
     54      Create new report
     55    </a>
     56    <input type="submit" class="btn btn-default"
     57      name="PURGE" value="Purge outdated reports"
     58      data-toggle="tooltip" title="All reports older than 4 weeks will be discarded!"
     59      onclick="return window.confirm('Are you really sure?')"/>
     60  </div>
    5461</form>
     62
     63
     64
Note: See TracChangeset for help on using the changeset viewer.