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
Files:
4 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):
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py

    r16431 r16551  
    359359            subject, body, config)
    360360
     361    def informNewStudent(self, user, pw, login_url, rpw_url):
     362        """Inform student that a new student account has been created.
     363        """
     364        subject = 'Your new Kofa student account'
     365        text = _(u"""Dear ${a},
     366
     367Your student record of the Student Registration and Information Portal of
     368${b} has been created for you.
     369
     370Your user name: ${c}
     371Your password: ${d}
     372Login: ${e}
     373
     374Or request a new secure password here: ${f}
     375
     376Regards
     377""")
     378        config = grok.getSite()['configuration']
     379        from_name = config.name_admin
     380        from_addr = config.email_admin
     381        rcpt_name = user.title
     382        rcpt_addr = user.email
     383
     384        text = _(text, mapping={
     385            'a': rcpt_name,
     386            'b': config.name,
     387            'c': user.name,
     388            'd': pw,
     389            'e': login_url,
     390            'f': rpw_url
     391            })
     392        body = translate(text, 'waeup.kofa',
     393            target_language=self.PORTAL_LANGUAGE)
     394        return send_mail(
     395            from_name, from_addr, rcpt_name, rcpt_addr,
     396            subject, body, config)
     397
     398
    361399    def inviteReferee(self, referee, applicant, url_info=None):
    362400        """Send invitation email to referee.
Note: See TracChangeset for help on using the changeset viewer.