Changeset 9127
- Timestamp:
- 30 Aug 2012, 08:55:31 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/utils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/browser.py
r9122 r9127 42 42 return 43 43 44 def removeStudentMessage(student_id, number): 45 students = grok.getSite()['students'] 46 student = students.get(student_id, None) 47 if student: 48 history = IObjectHistory(student) 49 success, text = history.removeMessage(number) 50 return success, text 51 52 def removeApplicantMessage(applicant_id, number): 53 applicants = grok.getSite()['applicants'] 54 try: 55 container, application_number = applicant_id.split('_') 56 except: 57 return False, 'applicant_id is wrong' 58 container = applicants.get(container, None) 59 if not container: 60 return False, 'No such container' 61 applicant = container.get(application_number, None) 62 if applicant is None: 63 return False, 'No such applicant' 64 history = IObjectHistory(applicant) 65 success, text = history.removeMessage(number) 66 return success, text 67 44 68 class ReindexPage(UtilityView, grok.View): 45 69 """ Reindex view. … … 94 118 return 95 119 120 class RemoveStudentHistoryMessage(UtilityView, grok.View): 121 """ View to remove a single student history entry. 122 123 """ 124 grok.context(IUniversity) 125 grok.name('remove_student_history_message') 126 grok.require('waeup.managePortal') 127 128 def update(self,student_id=None, number=None): 129 if None in (student_id, number): 130 self.flash('Syntax: /remove_student_history_message?student_id=[id]&number=[line number, starting with 0]') 131 return 132 try: 133 number=int(number) 134 except: 135 self.flash('Error') 136 return 137 success, text = removeStudentMessage(student_id, number) 138 if not success: 139 self.flash('Error: %s' % text) 140 return 141 self.context.logger.info( 142 "line '%s' removed in %s history" % (text, student_id)) 143 self.flash('Finished') 144 return 145 146 def render(self): 147 self.redirect(self.url(self.context, '@@index')) 148 return 149 96 150 class ModifyAllApplicantHistory(UtilityView, grok.View): 97 151 """ View to modify all student histories. … … 115 169 self.redirect(self.url(self.context, '@@index')) 116 170 return 171 172 class RemoveApplicantHistoryMessage(UtilityView, grok.View): 173 """ View to remove a single applicant history entry. 174 175 """ 176 grok.context(IUniversity) 177 grok.name('remove_applicant_history_message') 178 grok.require('waeup.managePortal') 179 180 def update(self,applicant_id=None, number=None): 181 if None in (applicant_id, number): 182 self.flash('Syntax: /remove_applicant_history_message?applicant_id=[id]&number=[line number, starting with 0]') 183 return 184 try: 185 number=int(number) 186 except: 187 self.flash('Error') 188 return 189 success, text = removeApplicantMessage(applicant_id, number) 190 if not success: 191 self.flash('Error: %s' % text) 192 return 193 self.context.logger.info( 194 "line '%s' removed in %s history" % (text, applicant_id)) 195 self.flash('Finished') 196 return 197 198 def render(self): 199 self.redirect(self.url(self.context, '@@index')) 200 return -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_browser.py
r9122 r9127 62 62 self.student.history.messages[0]) 63 63 64 def test_remove_student_history_message(self): 65 self.assertTrue('Record created by system' in 66 self.student.history.messages[0]) 67 self.assertEqual(len(self.student.history.messages),1) 68 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 69 self.browser.open('http://localhost/app/remove_student_history_message') 70 self.assertTrue( 71 'Syntax: /remove_student_history_message?student_id=[id]&number=[line number, starting with 0]' 72 in self.browser.contents) 73 self.browser.open( 74 'http://localhost/app/remove_student_history_message?student_id=%s&number=0' % self.student.student_id) 75 self.assertTrue('Finished' in self.browser.contents) 76 self.assertEqual(len(self.student.history.messages),0) 77 logfile = os.path.join( 78 self.app['datacenter'].storage, 'logs', 'main.log') 79 logcontent = open(logfile).read() 80 self.assertMatches( 81 "...zope.mgr - line '<YYYY-MM-DD hh:mm:ss> UTC - " 82 "Record created by system' removed in K1000000 history", 83 logcontent) 84 64 85 def test_reindex(self): 65 86 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') … … 96 117 self.assertTrue('Application initialized by me' in 97 118 self.applicant.history.messages[0]) 119 120 def test_remove_applicant_history_message(self): 121 self.assertTrue('Application initialized by system' in 122 self.applicant.history.messages[0]) 123 self.assertEqual(len(self.applicant.history.messages),1) 124 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 125 self.browser.open('http://localhost/app/remove_applicant_history_message') 126 self.assertTrue( 127 'Syntax: /remove_applicant_history_message?applicant_id=[id]&number=[line number, starting with 0]' 128 in self.browser.contents) 129 self.browser.open( 130 'http://localhost/app/remove_applicant_history_message?applicant_id=%s&number=0' % self.applicant.applicant_id) 131 self.assertTrue('Finished' in self.browser.contents) 132 self.assertEqual(len(self.applicant.history.messages),0) 133 logfile = os.path.join( 134 self.app['datacenter'].storage, 'logs', 'main.log') 135 logcontent = open(logfile).read() 136 self.assertMatches( 137 "...zope.mgr - line '<YYYY-MM-DD hh:mm:ss> UTC - " 138 "Application initialized by system' removed in %s history" 139 % self.applicant.applicant_id, logcontent)
Note: See TracChangeset for help on using the changeset viewer.