Changeset 16299 for main/waeup.kofa/trunk/src/waeup/kofa/students
- Timestamp:
- 4 Nov 2020, 17:52:22 (4 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r16286 r16299 36 36 from zope.security import checkPermission 37 37 from zope.securitypolicy.interfaces import IPrincipalRoleManager 38 from waeup.kofa.smtp import encode_address 38 39 from waeup.kofa.accesscodes import invalidate_accesscode, get_access_code 39 40 from waeup.kofa.accesscodes.workflow import USED … … 309 310 search_button = _('Find student(s)') 310 311 remove_button = _('Remove selected') 312 send_email_button = _('Send bulk email') 311 313 doclink = DOCLINK + '/students.html' 312 314 … … 340 342 if not self.hitlist: 341 343 self.flash(_('No student found.'), type="warning") 342 if 'remove' in form :344 if 'remove' in form or 'send_email' in form: 343 345 self.flash(_('No item selected.'), type="warning") 344 346 return … … 346 348 if isinstance(entries, basestring): 347 349 entries = [entries] 350 entries.sort() 348 351 deleted = [] 352 emails_tobesent = '' 349 353 for entry in entries: 350 354 if 'remove' in form: 351 355 del self.context[entry] 352 356 deleted.append(entry) 357 if 'send_email' in form and self.context[entry].email: 358 emails_tobesent += '%s,' % encode_address( 359 self.context[entry].email, 360 self.context[entry].student_id) 361 if 'send_email' in form and not len(emails_tobesent): 362 self.flash(_('No email address found.'), type="warning") 363 return 364 if len(emails_tobesent): 365 args = {'bcc_to': emails_tobesent.strip(',')} 366 self.redirect(self.url(self.context) + 367 '/send_bulk_email?%s' % urlencode(args)) 368 return 353 369 self.hitlist = search(query=self.searchterm, 354 370 searchtype=self.searchtype, view=self) … … 521 537 self.config.name, 522 538 data['body'],data['subject']) 539 if success: 540 self.flash(_('Your message has been sent.')) 541 else: 542 self.flash(_('An smtp server error occurred.'), type="danger") 543 return 544 545 class SendBulEmailsFormPage(ContactAdminFormPage): 546 grok.context(IStudentsContainer) 547 grok.name('send_bulk_email') 548 grok.require('waeup.manageStudent') 549 pnav = 4 550 form_fields = grok.AutoFields(IContactForm).select('subject', 'body', 'bcc_to') 551 label = _('Send bulk email') 552 553 def update(self, bcc_to=u''): 554 self.form_fields.get('bcc_to').field.default = bcc_to 555 return 556 557 @action('Send message now', style='primary') 558 def send(self, *args, **data): 559 try: 560 email = self.request.principal.email 561 except AttributeError: 562 email = self.config.email_admin 563 usertype = getattr(self.request.principal, 564 'user_type', 'system').title() 565 kofa_utils = getUtility(IKofaUtils) 566 success = kofa_utils.sendContactForm( 567 self.request.principal.title,email, 568 self.request.principal.title,email, # sent to the sender's address 569 self.request.principal.id,usertype, 570 self.config.name, 571 data['body'],data['subject'], 572 data['bcc_to']) 523 573 if success: 524 574 self.flash(_('Your message has been sent.')) -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/containermanagepage.pt
r15417 r16299 75 75 <input type="submit" name="remove" 76 76 tal:attributes="value view/remove_button" class="btn btn-default" 77 onclick="return confirmPost('Are you sure?')"/> 77 onclick="return window.confirm('Are you sure?')"/> 78 <input type="submit" name="send_email" 79 tal:attributes="value view/send_email_button" class="btn btn-default" 80 onclick="return window.confirm('Are you sure?')"/> 78 81 79 82 </div> -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r16266 r16299 90 90 def setUp(self): 91 91 super(StudentsFullSetup, self).setUp() 92 self.setup_logging() 92 93 93 94 # Setup a sample site for each test … … 252 253 253 254 layer = FunctionalLayer 255 256 def setup_logging(self): 257 # setup a log-handler that catches all fake mailer output 258 self.stream = StringIO() 259 handler = logging.StreamHandler(self.stream) 260 logger = logging.getLogger('test.smtp') 261 logger.addHandler(handler) 262 logger.setLevel(logging.INFO) 263 return 264 265 def get_fake_smtp_output(self): 266 # get output generated by fake mailer 267 self.stream.flush() 268 self.stream.seek(0) 269 return self.stream.read() 254 270 255 271 def test_anonymous_access(self): … … 432 448 self.assertTrue('No student found' in self.browser.contents) 433 449 return 450 451 def test_send_bulk_emails(self): 452 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 453 self.browser.open(self.manage_container_path) 454 self.browser.getLink("Add student").click() 455 self.assertEqual(self.browser.headers['Status'], '200 Ok') 456 self.assertEqual(self.browser.url, self.add_student_path) 457 self.browser.getControl(name="form.firstname").value = 'Bob' 458 self.browser.getControl(name="form.lastname").value = 'Tester' 459 self.browser.getControl(name="form.reg_number").value = '1234' 460 self.browser.getControl("Create student").click() 461 self.assertTrue('Student record created' in self.browser.contents) 462 self.browser.getLink("Manage").click() 463 self.browser.getControl(name="form.email").value = 'uli@uni.ng' 464 self.browser.getControl(name="form.sex").value = ['m'] 465 self.browser.getControl("Save").click() 466 # We can find Anna and Bob 467 self.browser.open(self.manage_container_path) 468 self.browser.getControl(name="searchtype").value = ['student_id'] 469 self.browser.getControl(name="searchterm").value = '*' 470 self.browser.getControl("Find student(s)").click() 471 self.assertTrue('Anna Tester' in self.browser.contents) 472 self.assertTrue('Bob Tester' in self.browser.contents) 473 # We can send bulk emails 474 ctrl = self.browser.getControl(name='entries') 475 ctrl.getControl(value='K1000000').selected = True 476 ctrl.getControl(value='K1000001').selected = True 477 self.browser.getControl("Send bulk", index=0).click() 478 self.assertTrue('K1000000 <aa@aa.ng>,K1000001 <uli@uni.ng>' 479 in self.browser.contents) 480 self.browser.getControl(name="form.subject").value = 'Test' 481 self.browser.getControl(name="form.body").value = 'Hello world' 482 self.browser.getControl("Send message").click() 483 self.assertTrue('Your message has been sent' in self.browser.contents) 484 self.assertMatches( 485 u'Sending email from no-reply@waeup.org to contact@waeup.org:\n' 486 u'Message:\n' 487 u'msg: MIME-Version: 1.0\n' 488 u'msg: Content-Type: text/plain; charset="us-ascii"\n' 489 u'msg: Content-Transfer-Encoding: 7bit\n' 490 u'msg: From: Manager <no-reply@waeup.org>\n' 491 u'msg: To: Manager <contact@waeup.org>\n' 492 u'msg: Bcc: K1000000 <aa@aa.ng>,K1000001 <uli@uni.ng>\n' 493 u'msg: Reply-To: Manager <contact@waeup.org>\n' 494 u'msg: Subject: Test\n' 495 u'msg: \n' 496 u'msg: Hello world\n' 497 u'msg: \n' 498 u'msg: ---\n' 499 u'msg: Manager (id: zope.mgr)\n' 500 u'msg: Sample University\n' 501 u'msg: \n', 502 self.get_fake_smtp_output() 503 ) 434 504 435 505 def test_add_graduated_students(self):
Note: See TracChangeset for help on using the changeset viewer.