Ignore:
Timestamp:
14 Jul 2021, 11:39:09 (3 years ago)
Author:
Henrik Bettermann
Message:

Send email to student after single record creation.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/applicants
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py

    r16545 r16551  
    2222from hurry.query import Eq, Text
    2323from hurry.query.query import Query
     24from urllib import urlencode
    2425from zope.component import getUtility, createObject, getAdapter
    2526from zope.component.interfaces import IFactory
     
    171172        return
    172173
    173     def createStudent(self, view=None, graduated=False):
     174    def createStudent(self, view=None, graduated=False, send_email=False):
    174175        """Create a student, fill with base data, create an application slip,
    175         copy applicant data and files.
     176        copy applicant data and files, send an email (optional).
    176177        """
    177178        site = grok.getSite()
     
    266267            view=view)
    267268        self._saveApplicationPDF(student, applicant_slip, view=view)
     269        if view and send_email:
     270            kofa_utils = getUtility(IKofaUtils)
     271            pw = self.application_number
     272            args = {'login':student.student_id, 'password':pw}
     273            login_url = view.url(grok.getSite()) + '/login?%s' % urlencode(args)
     274            rpw_url = view.url(grok.getSite(), 'changepw')
     275            kofa_utils.informNewStudent(
     276                IUserAccount(student), pw, login_url, rpw_url)
    268277        return True, _('Student ${a} created', mapping = {'a':student.student_id})
    269278
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r16545 r16551  
    730730
    731731    def update(self):
    732         success, msg = self.context.createStudent(view=self)
     732        success, msg = self.context.createStudent(view=self, send_email=True)
    733733        if success:
    734734            self.flash(msg)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r16545 r16551  
    14111411        return
    14121412
     1413    def test_create_student(self):
     1414        # Managers can contact student
     1415        IWorkflowState(self.applicant).setState('admitted')
     1416        self.applicant.certificate = self.certificate
     1417        self.applicant.course_admitted = self.certificate
     1418        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1419        self.browser.open(self.manage_path)
     1420        self.fill_correct_values()
     1421        image = open(SAMPLE_IMAGE, 'rb')
     1422        ctrl = self.browser.getControl(name='form.passport')
     1423        file_ctrl = ctrl.mech_control
     1424        file_ctrl.add_file(image, filename='myphoto.jpg')
     1425        self.browser.getControl("Save").click()
     1426        self.browser.open(self.view_path)
     1427        self.browser.getLink("Create student").click()
     1428        self.assertTrue('Student K1000000 created' in self.browser.contents)
     1429        self.assertMatches(
     1430            'Sending email from no-reply@waeup.org to xx@yy.zz:'
     1431            '\nMessage:'
     1432            '\nmsg: MIME-Version: 1.0'
     1433            '\nmsg: Content-Type: text/plain; charset="us-ascii"'
     1434            '\nmsg: Content-Transfer-Encoding: 7bit'
     1435            '\nmsg: From: Administrator <no-reply@waeup.org>'
     1436            '\nmsg: To: John Anthony Tester <xx@yy.zz>'
     1437            '\nmsg: Reply-To: Administrator <contact@waeup.org>'
     1438            '\nmsg: Subject: Your new Kofa student account'
     1439            '\nmsg:'
     1440            '\nmsg: Dear John Anthony Tester,'
     1441            '\nmsg:'
     1442            '\nmsg: Your student record of the Student Registration and Information Portal of'
     1443            '\nmsg: Sample University has been created for you.'
     1444            '\nmsg:'
     1445            '\nmsg: Your user name: K1000000'
     1446            '\nmsg: Your password: %s'
     1447            '\nmsg: Login: http://localhost/app/login?login=K1000000&password=%s'
     1448            '\nmsg:'
     1449            '\nmsg: Or request a new secure password here: http://localhost/app/changepw'
     1450            '\nmsg:'
     1451            '\nmsg: Regards'
     1452            '\nmsg:' % (self.applicant.application_number, self.applicant.application_number),
     1453            self.get_fake_smtp_output()
     1454            )
     1455        return
    14131456
    14141457class ApplicantRegisterTests(ApplicantsFullSetup):
Note: See TracChangeset for help on using the changeset viewer.