Changeset 14014 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 4 Jul 2016, 09:02:52 (8 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
r14001 r14014 22 22 import grok 23 23 import transaction 24 from urllib import urlencode 24 25 from datetime import datetime, date 25 26 from time import time … … 30 31 from hurry.workflow.interfaces import ( 31 32 IWorkflowInfo, IWorkflowState, InvalidTransitionError) 33 from waeup.kofa.mandates.mandate import RefereeReportMandate 32 34 from waeup.kofa.applicants.interfaces import ( 33 35 IApplicant, IApplicantEdit, IApplicantsRoot, … … 1169 1171 return 1170 1172 1173 def informReferees(self): 1174 site = grok.getSite() 1175 kofa_utils = getUtility(IKofaUtils) 1176 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 1177 failed = '' 1178 for referee in self.context.referees: 1179 if referee.email_sent: 1180 continue 1181 mandate = RefereeReportMandate() 1182 mandate.params['name'] = referee.name 1183 mandate.params['email'] = referee.email 1184 mandate.params[ 1185 'redirect_path'] = '/applicants/%s/%s/addrefereereport' % ( 1186 self.context.__parent__.code, 1187 self.context.application_number) 1188 site['mandates'].addMandate(mandate) 1189 # Send invitation email 1190 args = {'mandate_id':mandate.mandate_id} 1191 mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) 1192 url_info = u'Report link: %s' % mandate_url 1193 success = kofa_utils.inviteReferee(referee, self.context, url_info) 1194 if success: 1195 self.context.writeLogMessage( 1196 self, 'email sent: %s' % referee.email) 1197 referee.email_sent = True 1198 else: 1199 failed += '%s ' % referee.email 1200 return failed 1201 1171 1202 @action(_('Finally Submit'), warning=WARNING) 1172 1203 def finalsubmit(self, **data): … … 1184 1215 type='danger') 1185 1216 return 1217 msg = _('Form has been submitted.') 1218 # Create mandates and send emails to referees 1219 if getattr(self.context, 'referees', None): 1220 failed = self.informReferees() 1221 if failed: 1222 self.flash( 1223 _('Some invitation emails could not be sent:') + failed, 1224 type='danger') 1225 return 1226 msg = _('Form has been successfully submitted and ' 1227 'all invitation emails were sent.') 1186 1228 IWorkflowInfo(self.context).fireTransition('submit') 1187 1229 # application_date is used in export files for sorting. 1188 1230 # We can thus store utc. 1189 1231 self.context.application_date = datetime.utcnow() 1190 self.flash( _('Form has been submitted.'))1232 self.flash(msg) 1191 1233 self.redirect(self.url(self.context)) 1192 1234 return -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r13992 r14014 24 24 import tempfile 25 25 import grok 26 import logging 26 27 from datetime import datetime 27 28 from StringIO import StringIO … … 41 42 from waeup.kofa.payments.interfaces import IPayer 42 43 from waeup.kofa.configuration import SessionConfiguration 44 from waeup.kofa.refereeentries import RefereeEntry 43 45 from waeup.kofa.applicants.container import ApplicantsContainer 44 46 from waeup.kofa.applicants.applicant import Applicant … … 1526 1528 layer = FunctionalLayer 1527 1529 1530 def setUp(self): 1531 super(ApplicantRefereeReportTests, self).setUp() 1532 self.setup_logging() 1533 return 1534 1535 def tearDown(self): 1536 super(ApplicantRefereeReportTests, self).tearDown() 1537 self.teardown_logging() 1538 return 1539 1540 def setup_logging(self): 1541 # setup a log-handler that catches all fake mailer output 1542 self.stream = StringIO() 1543 handler = logging.StreamHandler(self.stream) 1544 logger = logging.getLogger('test.smtp') 1545 logger.addHandler(handler) 1546 logger.setLevel(logging.INFO) 1547 return 1548 1549 def get_fake_smtp_output(self): 1550 # get output generated by fake mailer 1551 self.stream.flush() 1552 self.stream.seek(0) 1553 return self.stream.read() 1554 1555 def teardown_logging(self): 1556 # remove the log handler for fake mailer output 1557 logger = logging.getLogger('test.smtp') 1558 handlers = [x for x in logger.handlers] 1559 for handler in handlers: 1560 logger.removeHandler(handler) 1561 return 1562 1528 1563 def test_refereereport_mandate(self): 1529 1564 mandate = RefereeReportMandate() … … 1604 1639 # Mandate is deleted 1605 1640 self.assertEqual(len(self.app['mandates'].keys()), 0) 1641 1642 def test_final_submit_with_referees(self): 1643 # Add two referees 1644 referee1 = RefereeEntry() 1645 referee2 = RefereeEntry() 1646 referee1.name = u'Linda Tree' 1647 referee1.email = 'linda@forest.de' 1648 referee2.name = u'Otis Stone' 1649 referee2.email = 'otis@stones.de' 1650 self.applicant.referees = [referee1, referee2] 1651 self.assertFalse(referee1.email_sent) 1652 self.assertFalse(referee2.email_sent) 1653 self.login() 1654 IWorkflowInfo(self.applicant).fireTransition('pay') 1655 self.browser.open(self.edit_path) 1656 self.fill_correct_values() # fill other fields with correct values 1657 image = open(SAMPLE_IMAGE, 'rb') 1658 ctrl = self.browser.getControl(name='form.passport') 1659 file_ctrl = ctrl.mech_control 1660 file_ctrl.add_file(image, filename='myphoto.jpg') 1661 self.browser.getControl("Save").click() 1662 self.browser.getControl(name="confirm_passport").value = True 1663 self.browser.getControl("Finally Submit").click() 1664 self.assertEqual( 1665 [u'Sending email from no-reply@waeup.org to linda@forest.de:', 1666 u'Message:', 1667 u'msg: MIME-Version: 1.0', 1668 u'msg: Content-Type: text/plain; charset="us-ascii"', 1669 u'msg: Content-Transfer-Encoding: 7bit', 1670 u'msg: From: Administrator <no-reply@waeup.org>', 1671 u'msg: To: Linda Tree <linda@forest.de>', 1672 u'msg: Reply-To: Administrator <contact@waeup.org>', 1673 u'msg: Subject: Request for referee report from Sample University', 1674 u'msg: ', 1675 ], self.get_fake_smtp_output().split('\n')[:10] 1676 ) 1677 self.assertTrue( 1678 'Application submitted' in self.browser.contents) 1679 logfile = os.path.join( 1680 self.app['datacenter'].storage, 'logs', 'applicants.log') 1681 logcontent = open(logfile).read() 1682 self.assertTrue( 1683 '%s - applicants.browser.ApplicantEditFormPage - %s - ' 1684 'email sent: otis@stones.de' % 1685 (self.applicant.applicant_id, self.applicant.applicant_id) 1686 in logcontent) 1687 self.assertTrue(referee1.email_sent) 1688 self.assertTrue(referee2.email_sent) 1689 return -
main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py
r13617 r14014 317 317 subject, body, config) 318 318 319 def inviteReferee(self, referee, applicant, url_info=None): 320 """Send invitation email to referee. 321 """ 322 config = grok.getSite()['configuration'] 323 subject = 'Request for referee report from %s' % config.name 324 text = _(u"""Dear ${a}, 325 326 ${c} 327 328 Regards 329 """) 330 from_name = config.name_admin 331 from_addr = config.email_admin 332 rcpt_name = referee.name 333 rcpt_addr = referee.email 334 text = _(text, mapping={ 335 'a': rcpt_name, 336 'c': url_info}) 337 338 body = translate(text, 'waeup.kofa', 339 target_language=self.PORTAL_LANGUAGE) 340 return send_mail( 341 from_name, from_addr, rcpt_name, rcpt_addr, 342 subject, body, config) 343 319 344 def getPaymentItem(self, payment): 320 345 """Return payment item. This method can be used to customize the
Note: See TracChangeset for help on using the changeset viewer.