Changeset 3143 for trunk


Ignore:
Timestamp:
02/02/11 17:00:26 (9 years ago)
Author:
jukka
Message:

Fixed unicode problem when sending exercises.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ExerciseMaterial.py

    r3142 r3143  
    2727from random import shuffle 
    2828from Products.LeMill import LeMillMessageFactory as _ 
     29from Products.MailHost.MailHost import MailHostError 
    2930import re 
    3031 
     
    241242 
    242243    def _sendAnswers(self, REQUEST): 
     244        ### Note for future unicode problems: self.translate returns unicode objects,  
     245        # but forms return utf-8 encoded strings. joining them together or embedding them with %s is harmful. 
     246        # when building longer strings, they should be manipulated as unicode (convert utf-8 strings with to_unicode()), but when 
     247        # sending email, the text should be utf-8 encoded str.     
    243248        mhost=self.MailHost 
    244249        body=[] 
    245250        students_name = to_unicode(REQUEST.get('your_name','')) 
    246         students_email = to_unicode(REQUEST.get('students_email','')) 
    247         teachers_email = to_unicode(REQUEST.get('teachers_email','')) 
     251        #students_email = to_unicode(REQUEST.get('students_email','')) 
     252        students_email= REQUEST.get('students_email','') 
     253        teachers_email = REQUEST.get('teachers_email','') 
    248254        captcha_c=REQUEST.get('recaptcha_challenge_field','') 
    249255        captcha_r=REQUEST.get('recaptcha_response_field','') 
    250         captcha=self.lemill_tool.validateCaptcha(captcha_c, captcha_r)         
     256        captcha=self.lemill_tool.validateCaptcha(captcha_c, captcha_r) 
     257        d={'name':students_name, 
     258            'exercise_title':to_unicode(self.Title()), 
     259            'exercise_url':to_unicode(self.absolute_url())}       
    251260        if not students_email or (teachers_email and not students_name): 
    252261            msg = self.translate("text_mail_feedback_no_information", "You have not provided enough information to send an e-mail.",domain='lemill') 
     
    259268            body.append(self.translate(u"""Hello, 
    260269%(name)s has completed the LeMill exercise '%(exercise_title)s' at %(exercise_url)s. 
    261 """,domain='lemill') % {'name':students_name, 'exercise_title':self.Title(), 'exercise_url':self.absolute_url()})  
     270""",domain='lemill') % d)  
    262271        else: 
    263272            body.append(self.translate(u"""Hello %(name)s, 
    264273You have completed the LeMill exercise '%(exercise_title)s' at %(exercise_url)s. 
    265 """,domain='lemill') % {'name':students_name, 'exercise_title':self.Title(), 'exercise_url':self.absolute_url()})  
     274""",domain='lemill') % d)  
    266275        body.append(self.translate(u"text_mail_feedback_message_body_explanation", u"If you are surprised by getting this e-mail, you can simply ignore and delete it as someone may have accidentally inserted your address as a recipient.",domain='lemill')) 
    267276        body.append('\n\n') 
    268277        body.append(self.checkExercise()) 
    269278        body.append('\n\n') 
    270         body.append(self.translate("text_mail_feedback_message_body_regards", "Best regards, LeMill", domain='lemill'))                      
     279        body.append(self.translate(u"text_mail_feedback_message_body_regards", "Best regards, LeMill", domain='lemill'))                      
    271280        body=u''.join(body) 
    272281        # Other email fields 
    273282        if students_name: 
    274             msubject=self.translate("LeMill exercise '%s' by %s", domain='lemill') % (self.Title(), students_name) 
    275         else: 
    276             msubject=self.translate("LeMill exercise '%s' feedback", domain='lemill') % self.Title() 
     283            msubject=self.translate(u"LeMill exercise '%(exercise_title)s' by %(name)s", domain='lemill') % d 
     284        else: 
     285            msubject=self.translate(u"LeMill exercise '%(exercise_title)s' feedback", domain='lemill') % d 
    277286        if teachers_email: 
    278287            mto=teachers_email 
     
    283292        # Send 
    284293        try: 
     294            body=body.encode('utf-8') 
    285295            mhost.secureSend(body, mto, "LeMill <no-reply@lemill.net>", subject=msubject, mcc=mcc, charset='utf-8') 
    286296            msg = self.translate("text_mail_feedback_message_sent", "The e-mail has been sent.",domain='lemill') 
    287297            return (msg, 'mess') 
    288         except: 
     298        except (MailHostError, AttributeError): 
    289299            msg = self.translate("The e-mail could not be sent.",domain='lemill') 
    290300            return (msg, 'warn') 
  • trunk/skins/lemill/front-page.cpt

    r3082 r3143  
    1717        <label i18n:translate="login_password">Password</label><br/> 
    1818        <input type="password" name="password" tal:attributes="name ac_password; id ac_password" /><br/> 
    19         <input type="submit" name="login_submit" value="Log in" i18n:attributes="value string:Log in" tal:attributes="tabindex tabindex/next; onclick string:javascript:return setLoginVars('$ac_name','login_name','$ac_password','pwd_empty','js_enabled','cookies_enabled');" /><br/> 
     19        <input type="submit" name="login_submit" value="Log in" i18n:attributes="value" tal:attributes="tabindex tabindex/next; onclick string:javascript:return setLoginVars('$ac_name','login_name','$ac_password','pwd_empty','js_enabled','cookies_enabled');" /><br/> 
    2020        <span class="small"><a href="mail_password_form" i18n:translate="forgot_password_link">Forgot password?</a></span><br/> 
    2121        <input type="hidden" name="came_from" value="front-page" tal:attributes="value here_url" /> 
Note: See TracChangeset for help on using the changeset viewer.