- Timestamp:
- 20 Sep 2016, 08:33:44 (8 years ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r14133 r14169 4 4 1.4.2.dev0 (unreleased) 5 5 ======================= 6 7 * Add report purge button. 6 8 7 9 * Add property attribute `total_score` in order to make provision -
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 -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_statistics.py
r12897 r14169 1 1 # Tests for student 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.kofa.interfaces import IJobManager 7 from waeup.kofa.interfaces import IJobManager, IKofaUtils 7 8 from waeup.kofa.students.reports.student_statistics import ( 8 9 get_student_stats, StudentStatisticsReport, IStudentStatisticsReport) … … 207 208 ) 208 209 return 210 211 def test_report_purge(self): 212 self.trigger_report_creation() 213 job_id = self.wait_for_report_job_completed() 214 self.browser.open('http://localhost/app/reports') 215 self.browser.getControl("Purge").click() 216 self.assertTrue('0 report(s) purged' in self.browser.contents) 217 job_id, gen_name, user = self.app['reports'].get_running_report_jobs(user_id=None)[0] 218 job = getUtility(IJobManager).get(job_id) 219 tz = getUtility(IKofaUtils).tzinfo 220 delta = timedelta(weeks=5) 221 setattr(job, '_begin_after', datetime.now(tz) - delta) 222 self.browser.getControl("Purge").click() 223 self.assertTrue('1 report(s) purged' in self.browser.contents) 224 logfile = os.path.join( 225 self.app['datacenter'].storage, 'logs', 'main.log') 226 logcontent = open(logfile).read() 227 self.assertTrue( 228 'INFO - zope.mgr - browser.reports.ReportsContainerPage - ' 229 'report %s purged' % job_id in logcontent 230 ) 231 return -
main/waeup.kofa/trunk/src/waeup/kofa/students/student.py
r13224 r14169 37 37 IObjectHistory, IUserAccount, IFileStoreNameChooser, IFileStoreHandler, 38 38 IKofaUtils, registration_states_vocab, IExtFileStore, 39 CREATED, ADMITTED, CLEARANCE, PAID, REGISTERED, VALIDATED, RETURNING) 39 CREATED, ADMITTED, CLEARANCE, PAID, REGISTERED, VALIDATED, RETURNING, 40 GRADUATED) 40 41 from waeup.kofa.students.accommodation import StudentAccommodation 41 42 from waeup.kofa.students.interfaces import ( … … 218 219 @property 219 220 def before_payment(self): 220 non_fresh_states = (PAID, REGISTERED, VALIDATED, RETURNING, )221 non_fresh_states = (PAID, REGISTERED, VALIDATED, RETURNING, GRADUATED) 221 222 if self.is_fresh and self.state not in non_fresh_states: 222 223 return True
Note: See TracChangeset for help on using the changeset viewer.