# Path: zipfelchappe/models.py
# class MailTemplate(CreateUpdateModel, TranslatedMixin):
#     """ Content override of mails that are sent on specific actions """
# 
#     ACTION_THANKYOU = 'thankyou'
# 
#     ACTION_CHOICES = (
#         (ACTION_THANKYOU, _('Thank you')),
#     )
# 
#     project = models.ForeignKey('Project', related_name='mail_templates')
# 
#     action = models.CharField(_('action'), max_length=30,
#         choices=ACTION_CHOICES, default=ACTION_THANKYOU)
# 
#     subject = models.CharField(_('subject'), max_length=200)
# 
#     template = models.TextField(_('template'))  # no richtext here
# 
#     class Meta:
#         verbose_name = _('email')
#         verbose_name_plural = _('emails')
#         unique_together = (('project', 'action'),)
# 
#     def __unicode__(self):
#         return '%s mail for %s' % (self.action, self.project)


from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from django.core.mail import send_mail
from django.template import Context, Template
from django.template.loader import render_to_string
from .models import MailTemplate



def render_mail(template, context):
    """ helper to load subject and content from template """
    subject = render_to_string('zipfelchappe/emails/%s_subject.txt' % template,
        context).strip()
    message = render_to_string('zipfelchappe/emails/%s_message.txt' % template,
        context)

    return subject, message


def send_pledge_completed_message(request, pledge, mail_template=None):
    """ Send message after backer successfully pledged to a project """

    # Try to get template from project if not explictly passed
    if mail_template is None:
        try:
            mail_template = MailTemplate.objects.get(
                project=pledge.project,
                action=MailTemplate.ACTION_THANKYOU
            ).translated

# Path: zipfelchappe/models.py
# class MailTemplate(CreateUpdateModel, TranslatedMixin):
#     """ Content override of mails that are sent on specific actions """
# 
#     ACTION_THANKYOU = 'thankyou'
# 
#     ACTION_CHOICES = (
#         (ACTION_THANKYOU, _('Thank you')),
#     )
# 
#     project = models.ForeignKey('Project', related_name='mail_templates')
# 
#     action = models.CharField(_('action'), max_length=30,
#         choices=ACTION_CHOICES, default=ACTION_THANKYOU)
# 
#     subject = models.CharField(_('subject'), max_length=200)
# 
#     template = models.TextField(_('template'))  # no richtext here
# 
#     class Meta:
#         verbose_name = _('email')
#         verbose_name_plural = _('emails')
#         unique_together = (('project', 'action'),)
# 
#     def __unicode__(self):
#         return '%s mail for %s' % (self.action, self.project)


# Path: zipfelchappe/emails.py
from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from django.core.mail import send_mail
from django.template import Context, Template
from django.template.loader import render_to_string
from .models import MailTemplate




def render_mail(template, context):
    """ helper to load subject and content from template """
    subject = render_to_string('zipfelchappe/emails/%s_subject.txt' % template,
        context).strip()
    message = render_to_string('zipfelchappe/emails/%s_message.txt' % template,
        context)

    return subject, message


def send_pledge_completed_message(request, pledge, mail_template=None):
    """ Send message after backer successfully pledged to a project """

    # Try to get template from project if not explictly passed
    if mail_template is None:
        try:
            mail_template = MailTemplate.objects.get(
                project=pledge.project,
                action=MailTemplate.ACTION_THANKYOU
            ).translated

        except MailTemplate.DoesNotExist: