2012-11-23 89 views
1

对于我目前的satchmo商店,我想发送html电子邮件,而不是所有的txt电子邮件。通过satchmo_store帐户注册码的外观,所有电子邮件都被硬编码并使用.txt格式而不是html格式。 例如mail.pysatchmo mail.py发送html电子邮件,而不是文本电子邮件

"""Sends mail related to accounts.""" 

from django.conf import settings 
from django.utils.translation import ugettext 
from satchmo_store.mail import send_store_mail 
from satchmo_store.shop.models import Config 
from satchmo_store.shop.signals import registration_sender 

import logging 
log = logging.getLogger('satchmo_store.accounts.mail') 

# TODO add html email template 
def send_welcome_email(email, first_name, last_name): 
    """Send a store new account welcome mail to `email`.""" 

    shop_config = Config.objects.get_current() 
    subject = ugettext("Welcome to %(shop_name)s") 
    c = { 
     'first_name': first_name, 
     'last_name': last_name, 
     'site_url': shop_config.site and shop_config.site.domain or 'localhost', 
     'login_url': settings.LOGIN_URL, 
    } 
    send_store_mail(subject, c, 'registration/welcome.txt', [email], 
        format_subject=True, sender=registration_sender) 

我知道你可以改变的最后一行,以便以下,使其工作:

send_store_mail(
    subject=subject, 
    context=c, 
    template='registration/welcome.txt', 
    recipients_list=[email], 
    format_subject=True, 
    sender=registration_sender, 
    template_html='registration/welcome.html') 

然而,这将是在不触及代码在我的最佳利益Satchmo应用程序在不久的将来升级。

有没有人知道什么是理想的方式来覆盖此功能或启用HTML电子邮件的所有注册相关的功能,而无需触摸satchmo应用程序?

在此先感谢。

回答

1

我已经做的Satchmo内部类似的变化在以下方式:

应该可以从安装的Satchmo相关的文件复制到你的Django应用程序。如果您根据this recommendation设置Satchmo商店,那可能意味着将satchmo/apps/satchmo_store/accounts/mail.py复制到/localsite/accounts/mail.py。这个想法是自动加载本地副本,而不是原来的。

在您本地的mail.py副本中,您可以替换send_store_email()函数。保留备忘录,以便在Satchmo升级时记住您的更改。原始文件很可能仍然是相同的,并且即使在将来的版本中,您的覆盖也可以工作。

在其他情况下,当你必须改变一些类的行为时,你也可以改变原始类的子类,只改变相关的方法,同时保留原来的名字。

+0

谢谢,贝壳。我设法为注册函数创建了view.py和form.py和mail.py的本地副本,并为注册函数添加了替换url,并且完美地工作。我想我只需要确保这是为稍后的升级而注意的,所以我将不得不稍后更新本地注册功能。再次感谢。 – jack

相关问题