Changeset 1174 in main


Ignore:
Timestamp:
06/06/12 07:31:09 (7 years ago)
Author:
zali
Message:

function send_mail : mail translation (text/html only) according to the language of , either the recipient or the sender , if there are more than one recipient

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/mail.py

    r864 r1174  
    3232 
    3333from django.conf import settings 
     34from django.utils import translation 
     35from django.utils.translation import ugettext_lazy as _ 
    3436from django.core.mail import EmailMultiAlternatives 
    3537from django.db.models import Model, Q 
     
    165167def do_send_mail(subject, recipients, ctx, template, blacklist=()): 
    166168    if recipients: 
     169        ctx = unserialize(ctx) 
     170        language=ctx["sponsor"].get_profile().language 
    167171        if len(recipients) == 1: 
    168             email = User.objects.get(id=recipients.pop()).email 
     172            r_id = recipients.pop() 
     173            language = User.objects.get(id=r_id).get_profile().language 
     174            email = User.objects.get(id=r_id).email 
    169175            if not email or email in blacklist: 
    170176                return 
     
    176182            if not emails: 
    177183                return 
    178         ctx = unserialize(ctx) 
     184 
    179185        ctx["site"] = Site.objects.get_current() 
    180         html_content = render_to_string(template + ".html", ctx) 
    181         message = render_to_string(template + ".txt", ctx) 
     186        translation.activate(language) 
     187        html_content =translation.gettext(render_to_string(template + ".html", ctx)) 
     188        message = translation.gettext(render_to_string(template + ".txt", ctx)) 
    182189        msg = EmailMultiAlternatives(subject, message, settings.EMAIL_OPENPLM, 
    183190            emails) 
Note: See TracChangeset for help on using the changeset viewer.