2012-11-23 88 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

相關問題