summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-09-14 19:56:10 -0600
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-09-14 19:56:10 -0600
commit15926128629c4f8a606a89fada44487471e5f2ec (patch)
tree6133fd58265188e066c8f5f60d06fca9228f3147
parentb4d29815802adb1b01e1c7e3e4c7ad43d5f7276e (diff)
downloadaskbot-15926128629c4f8a606a89fada44487471e5f2ec.tar.gz
askbot-15926128629c4f8a606a89fada44487471e5f2ec.tar.bz2
askbot-15926128629c4f8a606a89fada44487471e5f2ec.zip
Start to improve email presentation, created base_mail.html template and
converted welcome messages, added support to strip messages tags correctly with beautifulsoup
-rw-r--r--askbot/mail/__init__.py17
-rw-r--r--askbot/skins/default/templates/email/base_mail.html53
-rw-r--r--askbot/skins/default/templates/email/welcome_lamson_off.html10
-rw-r--r--askbot/skins/default/templates/email/welcome_lamson_on.html11
-rw-r--r--askbot/tests/__init__.py1
-rw-r--r--askbot/tests/email_parsing_tests.py25
6 files changed, 101 insertions, 16 deletions
diff --git a/askbot/mail/__init__.py b/askbot/mail/__init__.py
index 9002e501..23075b22 100644
--- a/askbot/mail/__init__.py
+++ b/askbot/mail/__init__.py
@@ -17,6 +17,8 @@ from askbot import const
from askbot.conf import settings as askbot_settings
from askbot.utils import url_utils
from askbot.utils.file_utils import store_file
+
+from bs4 import BeautifulSoup
#todo: maybe send_mail functions belong to models
#or the future API
def prefix_the_subject_line(subject):
@@ -78,6 +80,19 @@ def thread_headers(post, orig_post, update):
return headers
+def clean_html_email(email_body):
+ '''needs more clenup might not work for other email templates
+ that does not use table layout'''
+
+ remove_linejump = lambda s: s.replace('\n', '')
+
+ soup = BeautifulSoup(email_body)
+ table_tds = soup.find('body')
+ phrases = map(lambda s: s.strip(),
+ filter(bool, table_tds.get_text().split('\n')))
+
+ return '\n\n'.join(phrases)
+
def send_mail(
subject_line = None,
body_text = None,
@@ -106,7 +121,7 @@ def send_mail(
subject_line = prefix_the_subject_line(subject_line)
msg = mail.EmailMultiAlternatives(
subject_line,
- strip_tags(body_text),
+ clean_html_email(body_text),
from_email,
recipient_list,
headers = headers
diff --git a/askbot/skins/default/templates/email/base_mail.html b/askbot/skins/default/templates/email/base_mail.html
index 1a507a64..dfd252f2 100644
--- a/askbot/skins/default/templates/email/base_mail.html
+++ b/askbot/skins/default/templates/email/base_mail.html
@@ -3,12 +3,12 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
- <title>{%block title%}{%endblock%}</title>
+ <title>{% block title%}{%endblock%}</title>
<style type="text/css">
/* Based on The MailChimp Reset INLINE: Yes. */
/* Client-specific Styles */
#outlook a {padding:0;} /* Force Outlook to provide a "view in browser" menu link. */
- body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;}
+ body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0; font-family:arial, sans-serif;font-size:13px;}
/* Prevent Webkit and Windows Mobile platforms from changing default font sizes.*/
.ExternalClass {width:100%;} /* Force Hotmail to display emails at full width */
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}
@@ -111,7 +111,6 @@
/* Put CSS for high density (hdpi) Android layouts in here */
}
/* end Android targeting */
-
</style>
<!-- Targeting Windows Mobile -->
@@ -134,15 +133,51 @@
<![endif]-->
</head>
<body>
-<!-- Wrapper/Container Table: Use a wrapper table to control the width and the background color consistently of your email. Use this approach instead of setting attributes on the body tag. -->
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable">
<tr>
- <td valign="top">
- {%block content%}
- {%endblock%}
+ <td>
+ <table border="0" align="center" cellspacing="0" cellpadding="0" style="background-color:#E7E8E8;">
+ <tr height="20">
+ <td valign="top">
+ </td>
+ </tr>
+ <tr>
+ <td valign="top">
+ <table border="0" align="center" cellspacing="0" cellpadding="0" style="background-color: #fff;" width=80%>
+ <tr>
+ <td valign="top">
+ <table border="0" align="center" cellspacing="0" cellpadding="0" width=80%>
+ <tr>
+ <td valign="top">
+ <h1>{%block headline%}{%endblock%}</h1>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top">
+ {%block content%}
+ {%endblock%}
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" class="footer">
+ <hr>
+ {%block footer%}
+ {%endblock%}
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr height="20">
+ <td valign="top">
+ </td>
+ </tr>
+ </table>
</td>
</tr>
-</table>
-<!-- End of wrapper table -->
+ </table>
</body>
</html>
diff --git a/askbot/skins/default/templates/email/welcome_lamson_off.html b/askbot/skins/default/templates/email/welcome_lamson_off.html
index d1b9854d..c5c9384c 100644
--- a/askbot/skins/default/templates/email/welcome_lamson_off.html
+++ b/askbot/skins/default/templates/email/welcome_lamson_off.html
@@ -1,11 +1,15 @@
+{% extends "email/base_mail.html" %}
{% import "email/macros.html" as macros %}
{# site_name - is short name of the site, email_code - address portion
of the reply email used for this message, we scan to the last appearance
of the email code to detect the response signature that will appear under #}
-<p style="{{ macros.heading_style() }}">
- {% trans %}Welcome to {{ site_name }}!{% endtrans %}
-</p>
+{%block title%} {% trans %}Welcome to {{ site_name }}!{% endtrans %} {%endblock%}
+{%block headline%} {% trans %}Welcome to {{ site_name }}!{% endtrans %} {%endblock%}
+{%block content%}
<p>
{% trans %}We look forward to your Questions!{% endtrans %}
</p>
+{%endblock%}
+{%block footer %}
{% include "email/footer.html" %}
+{%endblock%}
diff --git a/askbot/skins/default/templates/email/welcome_lamson_on.html b/askbot/skins/default/templates/email/welcome_lamson_on.html
index 0efa7096..3e47f44f 100644
--- a/askbot/skins/default/templates/email/welcome_lamson_on.html
+++ b/askbot/skins/default/templates/email/welcome_lamson_on.html
@@ -1,15 +1,20 @@
+{% extends "email/base_mail.html"%}
{% import "email/macros.html" as macros %}
+{%block title%}{% trans %}Welcome to {{ site_name }}!{% endtrans %}{% endblock %}
+{%block headline%}{% trans %}Welcome to {{ site_name }}!{% endtrans %}{% endblock %}
+
+{%block content %}
{# site_name - is short name of the site, email_code - address portion
of the reply email used for this message, we scan to the last appearance
of the email code to detect the response signature that will appear under #}
-<p style="{{ macros.heading_style() }}">
- {% trans %}Welcome to {{ site_name }}!{% endtrans %}
-</p>
<p>
{% trans %}Important: <em>Please reply</em> to this message, without editing it. We need this to determine your email signature and that the email address is valid and was typed correctly.{% endtrans %}
</p>
<p>
{% trans %}Until we receive the response from you, you will not be able ask or answer questions on {{ site_name }} by email.{% endtrans %}
</p>
+{% endblock %}
+{%block footer %}
{% include "email/footer.html" %}
<p style="{{ macros.fine_print_style() }}">{{ email_code }}</p>{# important #}
+{% endblock %}
diff --git a/askbot/tests/__init__.py b/askbot/tests/__init__.py
index 1b25e064..4e096052 100644
--- a/askbot/tests/__init__.py
+++ b/askbot/tests/__init__.py
@@ -15,3 +15,4 @@ from askbot.tests.markup_test import *
from askbot.tests.misc_tests import *
from askbot.tests.post_model_tests import *
from askbot.tests.reply_by_email_tests import *
+from askbot.tests.email_parsing_tests import *
diff --git a/askbot/tests/email_parsing_tests.py b/askbot/tests/email_parsing_tests.py
new file mode 100644
index 00000000..905bff0a
--- /dev/null
+++ b/askbot/tests/email_parsing_tests.py
@@ -0,0 +1,25 @@
+from django.conf import settings as django_settings
+from askbot.skins.loaders import get_template
+from django.template import Context
+from askbot import mail
+from askbot import models
+from askbot.tests import utils
+
+class EmailParseTests(utils.AskbotTestCase):
+
+ def setUp(self):
+ self.template_name = 'email/welcome_lamson_on.html'
+ self.context = {'site_name': 'askbot.com',
+ 'email_code': 'DwFwndQty'}
+ template = get_template(self.template_name)
+ self.rendered_template = template.render(Context(self.context))
+ self.expected_output = 'Welcome to askbot.com!\n\nImportant: Please reply to this message, without editing it. We need this to determine your email signature and that the email address is valid and was typed correctly.\n\nUntil we receive the response from you, you will not be able ask or answer questions on askbot.com by email.\n\nSincerely,askbot.com Administrator\n\nDwFwndQty'
+
+ def test_clean_email_body(self):
+ cleaned_body = mail.clean_html_email(self.rendered_template)
+ print "EXPECTED BODY"
+ print self.expected_output
+ print '=================================================='
+ print cleaned_body
+ print "CLEANED BODY"
+ self.assertEquals(cleaned_body, self.expected_output)