Fixes in Bulk Email and Email Template

This commit is contained in:
Anand Doshi 2014-02-12 21:13:07 +05:30
parent 6f8001c9d5
commit fb8925fe8a
6 changed files with 53 additions and 20 deletions

View file

@ -2,7 +2,7 @@
{
"creation": "2012-08-02 15:17:28",
"docstatus": 0,
"modified": "2013-12-20 19:23:58",
"modified": "2014-02-12 21:11:05",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -55,7 +55,7 @@
{
"doctype": "DocField",
"fieldname": "message",
"fieldtype": "Text",
"fieldtype": "Long Text",
"label": "Message"
},
{

View file

@ -78,6 +78,19 @@ body {
padding:10px 0;
}
.left-padding {
padding-left: 10px;
}
.breadcrumb {
list-style: none;
}
.breadcrumb > li {
display: inline-block;
margin-left: 0px;
margin-right: 5px;
}
/* -------------------------------------
BODY
@ -183,6 +196,19 @@ table.footer-wrap a{
width: 100%;
}
a.no-decoration {
text-decoration: none;
color: inherit;
}
small, .small {
font-size: 85%;
}
.text-muted {
color: #999999;
}
</style>
</head>
@ -240,7 +266,7 @@ table.footer-wrap a{
</div>
<div class="print-html">{{ print_html }}</div>
<div class="print-html">{{ print_html or "" }}</div>
</body>
</html>

View file

@ -5,13 +5,13 @@
data-name="{{ post.name }}"
data-group="{{ post.website_group }}"
itemscope itemtype="http://schema.org/Article">
<a class="pull-left media-link" href="{{ post_url }}">
<a class="pull-left media-link" {% if view.name!="post" %} href="{{ post_url }}" {% endif %}>
<img class="media-object post-avatar" src="{{ post.user_image }}">
</a>
<div class="media-body">
{%- if not post.parent_post -%}
<h4 class="media-heading" itemprop="headline">
{%- if view != "post" -%}
{%- if view.name != "post" -%}
<a class="no-decoration"
href="{{ post_url }}">{{ post.title }}</a>
{%- else -%}

View file

@ -903,9 +903,16 @@ def scrub_urls(html):
def expand_relative_urls(html):
# expand relative urls
url = get_url()
if not url.endswith("/"): url += "/"
return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)',
'\g<1>\g<2>{}\g<3>\g<4>'.format(url), html)
if url.endswith("/"): url = url[:-1]
def _expand_relative_urls(match):
to_expand = list(match.groups())
if not to_expand[2].startswith("/"):
to_expand[2] = "/" + to_expand[2]
to_expand.insert(2, url)
return "".join(to_expand)
return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)', _expand_relative_urls, html)
def quote_urls(html):
def _quote_url(match):

View file

@ -47,7 +47,7 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email',
"type": doctype,
"email_field": email_field
}))
updated = updated.replace("<!--unsubscribe link here-->", unsubscribe_link)
return updated
@ -57,11 +57,6 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email',
sender = webnotes.conn.get_value('Email Settings', None, 'auto_email_id')
check_bulk_limit(len(recipients))
try:
text_content = html2text(message)
except HTMLParser.HTMLParseError:
text_content = "[See html attachment]"
formatted = get_formatted_html(subject, message)
for r in filter(None, list(set(recipients))):
@ -72,8 +67,13 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email',
if not is_unsubscribed(doc):
# add to queue
add(r, sender, subject, update_message(formatted, doc, add_unsubscribe_link),
text_content, ref_doctype, ref_docname)
updated = update_message(formatted, doc, add_unsubscribe_link)
try:
text_content = html2text(updated)
except HTMLParser.HTMLParseError:
text_content = "[See html attachment]"
add(r, sender, subject, updated, text_content, ref_doctype, ref_docname)
def add(email, sender, subject, formatted, text_content=None,
ref_doctype=None, ref_docname=None):
@ -83,7 +83,7 @@ def add(email, sender, subject, formatted, text_content=None,
e.recipient = email
try:
e.message = get_email(email, sender=e.sender, formatted=formatted, subject=subject,
text_content = text_content).as_string()
text_content=text_content).as_string()
except webnotes.ValidationError:
# bad email id - don't add to queue
return
@ -113,7 +113,7 @@ def unsubscribe():
def flush(from_test=False):
"""flush email queue, every time: called from scheduler"""
smptserver = SMTPServer()
smtpserver = SMTPServer()
auto_commit = not from_test
@ -133,7 +133,7 @@ def flush(from_test=False):
(email["name"],), auto_commit=auto_commit)
try:
if not from_test:
smptserver.sess.sendmail(email["sender"], email["recipient"], email["message"])
smtpserver.sess.sendmail(email["sender"], email["recipient"], email["message"])
webnotes.conn.sql("""update `tabBulk Email` set status='Sent' where name=%s""",
(email["name"],), auto_commit=auto_commit)

View file

@ -21,7 +21,7 @@ def send(email, as_bulk=False):
if not email.reply_to:
email.reply_to = email.sender
email.sender = smtpserver.login
smtpserver.sess.sendmail(email.sender, email.recipients + (email.cc or []),
email.as_string())