Skip to content

Commit

Permalink
Consolidate all email footers into code.
Browse files Browse the repository at this point in the history
As discussed by @jennyq and @eschipul in
tendenci#654, Tendenci footers need to be in
code to support ongoing costs of outgoing email for hosted customers as well as
ongoing Tendenci development.
  • Loading branch information
BenSturmfels committed Mar 18, 2018
1 parent 2ecb5bc commit ff7e092
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 18 deletions.
7 changes: 4 additions & 3 deletions tendenci/apps/base/utils.py
Expand Up @@ -30,7 +30,7 @@
from django.core.files.storage import default_storage
from django.core.validators import validate_email as _validate_email
from django.contrib.humanize.templatetags.humanize import intcomma
from django.template.loader import get_template, render_to_string
from django.template.loader import get_template
from django.template import TemplateDoesNotExist
from django.contrib.admin.utils import NestedObjects
from django.utils.functional import allow_lazy
Expand All @@ -48,6 +48,7 @@
from simple_salesforce import Salesforce

from tendenci.apps.base.models import ChecklistItem
from tendenci.apps.emails import footers
from tendenci.apps.site_settings.utils import get_setting
from tendenci.apps.theme.utils import get_theme_root

Expand Down Expand Up @@ -943,10 +944,10 @@ def get_latest_version():

def add_tendenci_footer(email_content, content_type='html'):
if content_type == 'text':
footer = render_to_string('email_footer.txt')
footer = footers.text_footer()
return email_content + '\n\n' + footer
else:
footer = render_to_string('email_footer.html')
footer = footers.html_footer()
if email_content.find('</body>') != -1:
return email_content.replace("</body>", footer + "\n</body>")
else:
Expand Down
Expand Up @@ -11,6 +11,7 @@
from django.template import Context, Template
from django.conf import settings

from tendenci.apps.emails import footers

class Command(BaseCommand):
"""
Expand Down Expand Up @@ -266,7 +267,7 @@ def email_member(notice, membership, global_context):

body = fieldify(body)

body = body + ' <br /><br />{% include "email_footer.html" %}'
body = body + ' <br /><br />' + footers.html_footer()

context = Context(context)
template = Template(body)
Expand Down
3 changes: 2 additions & 1 deletion tendenci/apps/corporate_memberships/models.py
Expand Up @@ -56,6 +56,7 @@
from tendenci.apps.base.utils import truncate_words
from tendenci.apps.perms.utils import has_perm
from tendenci.apps.files.models import File
from tendenci.apps.emails import footers


FIELD_CHOICES = (
Expand Down Expand Up @@ -1845,7 +1846,7 @@ def get_content(self, corporate_membership=None, recipient=None, **kwargs):
Return self.email_content with footer appended and replace shortcode
(context) variables
"""
content = self.email_content + '\n<br /><br />\n{% include "email_footer.html" %}'
content = self.email_content + '\n<br /><br />\n' + footers.html_footer()
context = self.get_default_context(corporate_membership, recipient, **kwargs)

return self.build_notice(content, context=context, **kwargs)
Expand Down
@@ -1,4 +1,5 @@
{% load i18n %}
{% load email_tags %}

{% trans "Greetings:" %}<br /><br />
{% blocktrans with display_name=site_display_name %}Corporate Membership Notices were distributed on {{ display_name }}.{% endblocktrans %}
Expand Down Expand Up @@ -37,4 +38,4 @@

<P>{% trans "Time submitted:" %} {% now "D d M Y P" %}</P>

{% include email_footer.html %}
{% html_footer %}
27 changes: 27 additions & 0 deletions tendenci/apps/emails/footers.py
@@ -0,0 +1,27 @@
from django.utils.translation import ugettext as _

def html_footer():
"""Return the contents of the HTML email footer.
This footer provides important exposure for the Tendenci project, for which
most of the development costs are funded by hosted Tendenci subscriptions.
This footer is implemented in code, rather than templates, so that it can't
be trivially removed by hosted customers. If you need to remove this footer,
please maintain a fork the tendenci repository. For discussion on this, see:
https://github.com/tendenci/tendenci/pull/654/
"""
return (
'<p align="center">' +
_('This e-mail was generated by Tendenci&reg; - The Open Source AMS') +
' <a href="https://www.tendenci.com">www.tendenci.com</a>' +
'</p>')


def text_footer():
"""Return the contents of the text-only email footer."""
return (
_('This e-mail was generated by Tendenci - The Open Source AMS') +
' https://www.tendenci.com')
13 changes: 13 additions & 0 deletions tendenci/apps/emails/templatetags/email_tags.py
@@ -1,5 +1,6 @@
from django.template import Library

from tendenci.apps.emails import footers

register = Library()

Expand All @@ -26,3 +27,15 @@ def emails_current_app(context, email=None):
"app_object": email,
})
return context


@register.simple_tag
def html_footer():
"""Make the HTML email footer available in templates."""
return footers.html_footer()


@register.simple_tag
def text_footer():
"""Make the text email footer available in templates."""
return footers.text_footer()
Expand Up @@ -8,6 +8,7 @@
from django.template import TemplateDoesNotExist
from django.template import Context, Template

from tendenci.apps.emails import footers

class Command(BaseCommand):
"""
Expand Down Expand Up @@ -263,7 +264,7 @@ def email_member(notice, membership, global_context):

body = fieldify(body)

body = body + ' <br /><br />{% include "email_footer.html" %}'
body = body + ' <br /><br />' + footers.html_footer()

context = Context(context)
template = Template(body)
Expand Down
@@ -1,4 +1,5 @@
{% load i18n %}
{% load email_tags %}

{% trans "Greetings:" %}<br /><br />
{% blocktrans %}Membership Notices were distributed on {{ site_display_name }}.{% endblocktrans %}
Expand Down Expand Up @@ -37,4 +38,4 @@

<P>{% trans "Time submitted:" %} {% now "D d M Y P" %}</P>

{% include email_footer.html %}
{% html_footer %}
@@ -1,4 +1,5 @@
{% load i18n %}
{% load email_tags %}

{% blocktrans with action.creator.first_name as act_create and action.name as act_name and action.attempted as act_attempt and action.failed as act_fail and action.sent as act_sent %}Greetings {{ act_create }}: <br /><br />

Expand All @@ -17,4 +18,4 @@
{{ SITE_GLOBAL_SITEDISPLAYNAME }} <br />
<p>{% trans "Time Submitted:" %} {% now "D d M Y P" %}</p>

{% include email_footer.html %}
{% html_footer %}
3 changes: 2 additions & 1 deletion tendenci/apps/recurring_payments/utils.py
Expand Up @@ -9,6 +9,7 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from dateutil.relativedelta import relativedelta
from tendenci.apps.emails import footers
from tendenci.apps.emails.models import Email
from tendenci.apps.site_settings.utils import get_setting
from tendenci.apps.profiles.models import Profile
Expand Down Expand Up @@ -38,7 +39,7 @@ def __init__(self):
self.email.sender = get_setting('site', 'global', 'siteemailnoreplyaddress')
self.email.sender_display = self.site_display_name
self.email.reply_to = self.reply_to_email
self.email_footer = render_to_string("email_footer.html")
self.email_footer = footers.html_footer()

self.admin_emails = self.get_admin_emails()

Expand Down
7 changes: 0 additions & 7 deletions tendenci/templates/email_footer.html

This file was deleted.

1 change: 0 additions & 1 deletion tendenci/templates/email_footer.txt

This file was deleted.

0 comments on commit ff7e092

Please sign in to comment.