Changeset 14169 for main/waeup.kofa/trunk/src/waeup/kofa/browser
- Timestamp:
- 20 Sep 2016, 08:33:44 (8 years ago)
- 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 19 19 """ 20 20 import grok 21 from datetime import datetime, timedelta 21 22 from zope.i18n import translate 22 23 from zope.component import getUtility, queryUtility … … 25 26 from waeup.kofa.interfaces import IJobManager, IKofaUtils 26 27 from waeup.kofa.interfaces import MessageFactory as _ 27 from waeup.kofa.browser.layout import KofaPage 28 from waeup.kofa.browser.layout import KofaPage, jsaction 28 29 from waeup.kofa.utils.helpers import get_current_principal 29 30 from waeup.kofa.reports import ( … … 47 48 return self.url(self.context, '%s/pdf' % job_id) 48 49 49 def update(self, job_id=None, DISCARD=None, DOWNLOAD=None ):50 def update(self, job_id=None, DISCARD=None, DOWNLOAD=None, PURGE=None): 50 51 self.entries = [] 52 ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '') 51 53 if job_id and DISCARD: 52 54 entry = self.context.report_entry_from_job_id(job_id) 53 55 self.context.delete_report_entry(entry) 54 56 self.flash('Report discarded: %s' % job_id) 55 ob_class = self.__implemented__.__name__.replace(56 'waeup.kofa.', '')57 57 grok.getSite().logger.info( 58 58 '%s - report %s discarded' % (ob_class, job_id)) 59 59 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 62 61 else: 63 self.entries = self._generate_entries(user_id=None) 62 user_id = None 63 self.entries = self._generate_entries(user_id=user_id) 64 64 if job_id and DOWNLOAD: 65 65 self.redirect(self._report_url(job_id)) 66 66 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)) 67 82 return 68 83 … … 87 102 entries.append(new_entry) 88 103 return entries 89 90 104 91 105 class ReportsContainerTraverser(grok.Traverser): -
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/reportscontainerpage.pt
r11254 r14169 47 47 </tbody> 48 48 </table> 49 49 50 <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> 54 61 </form> 62 63 64
Note: See TracChangeset for help on using the changeset viewer.