[minor] expand partial links when sending email
This commit is contained in:
parent
61c3d2fd42
commit
58f6dfe50a
6 changed files with 34 additions and 18 deletions
|
|
@ -59,11 +59,12 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received =
|
|||
|
||||
d.communication_medium = communication_medium
|
||||
|
||||
if send_email:
|
||||
send_comm_email(d, name, sent_via, print_html, attachments, send_me_a_copy)
|
||||
|
||||
comm.ignore_permissions = True
|
||||
comm.insert()
|
||||
|
||||
if send_email:
|
||||
d = comm.doc
|
||||
send_comm_email(d, name, sent_via, print_html, attachments, send_me_a_copy)
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_customer_supplier(args=None):
|
||||
|
|
@ -98,7 +99,7 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s
|
|||
d.content = sent_via.get_content(d)
|
||||
|
||||
footer = set_portal_link(sent_via, d)
|
||||
|
||||
|
||||
from webnotes.utils.email_lib.smtp import get_email
|
||||
mail = get_email(d.recipients, sender=d.sender, subject=d.subject,
|
||||
msg=d.content, footer=footer)
|
||||
|
|
|
|||
|
|
@ -190,12 +190,17 @@ class Bean:
|
|||
def prepare_for_save(self, method):
|
||||
self.check_if_latest(method)
|
||||
|
||||
self.update_timestamps_and_docstatus()
|
||||
self.update_parent_info()
|
||||
|
||||
if self.doc.fields.get("__islocal"):
|
||||
# set name before validate
|
||||
self.doc.set_new_name()
|
||||
self.run_method('before_insert')
|
||||
|
||||
if method != "cancel":
|
||||
self.extract_images_from_text_editor()
|
||||
self.check_links()
|
||||
|
||||
self.update_timestamps_and_docstatus()
|
||||
self.update_parent_info()
|
||||
|
||||
def update_parent_info(self):
|
||||
idx_map = {}
|
||||
|
|
@ -286,11 +291,6 @@ class Bean:
|
|||
if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, perm_to_check, self.doc):
|
||||
self.to_docstatus = 0
|
||||
self.prepare_for_save("save")
|
||||
if self.doc.fields.get("__islocal"):
|
||||
# set name before validate
|
||||
self.doc.set_new_name()
|
||||
self.run_method('before_insert')
|
||||
|
||||
if not self.ignore_validate:
|
||||
self.run_method('validate')
|
||||
if not self.ignore_mandatory:
|
||||
|
|
|
|||
|
|
@ -213,7 +213,6 @@ class Document:
|
|||
return r
|
||||
else:
|
||||
if not webnotes.conn.exists(self.doctype, self.name):
|
||||
print self.fields
|
||||
webnotes.msgprint(webnotes._("Cannot update a non-exiting record, try inserting.") + ": " + self.doctype + " / " + self.name,
|
||||
raise_exception=1)
|
||||
|
||||
|
|
|
|||
|
|
@ -916,3 +916,19 @@ def get_disk_usage():
|
|||
return 0
|
||||
err, out = execute_in_shell("du -hsm {files_path}".format(files_path=files_path))
|
||||
return cint(out.split("\n")[-2].split("\t")[0])
|
||||
|
||||
import re
|
||||
# compiled regex for efficiency of expand_partial_links
|
||||
# returns a set of tuples of length 4
|
||||
link_regex = re.compile('(href|src){1}([\s]*=[\s]*[\'"]?)([^\'" >]+)([\'"]?)')
|
||||
|
||||
def expand_partial_links(html):
|
||||
from webnotes.utils import get_url
|
||||
url_tuples = link_regex.findall(html)
|
||||
for parts in sorted(url_tuples, key=lambda *x: len(x[0][2]), reverse=True):
|
||||
if all(parts) and not parts[2].startswith("http"):
|
||||
new_parts = list(parts)
|
||||
new_parts[2] = get_url(new_parts[2])
|
||||
html = html.replace("".join(parts), "".join(new_parts))
|
||||
|
||||
return html
|
||||
|
|
@ -10,7 +10,7 @@ Allows easy adding of Attachments of "File" objects
|
|||
import webnotes
|
||||
from webnotes import conf
|
||||
from webnotes import msgprint
|
||||
from webnotes.utils import cint
|
||||
from webnotes.utils import cint, expand_partial_links
|
||||
|
||||
def get_email(recipients, sender='', msg='', subject='[No Subject]', text_content = None, footer=None):
|
||||
"""send an html email as multipart with attachments and all"""
|
||||
|
|
@ -51,13 +51,13 @@ class EMail:
|
|||
self.html_set = False
|
||||
|
||||
def set_html(self, message, text_content = None, footer=None):
|
||||
|
||||
"""Attach message in the html portion of multipart/alternative"""
|
||||
message = message + self.get_footer(footer)
|
||||
message = expand_partial_links(message)
|
||||
|
||||
# this is the first html part of a multi-part message,
|
||||
# convert to text well
|
||||
if not self.html_set:
|
||||
if not self.html_set:
|
||||
if text_content:
|
||||
self.set_text(text_content)
|
||||
else:
|
||||
|
|
@ -65,7 +65,7 @@ class EMail:
|
|||
|
||||
self.set_part_html(message)
|
||||
self.html_set = True
|
||||
|
||||
|
||||
def set_text(self, message):
|
||||
"""
|
||||
Attach message in the text portion of multipart/alternative
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ def extract_images_from_html(doc, fieldname):
|
|||
content = re.sub('<img\s*src=\s*["\'](data:[^"\']*)["\']', _save_file, content)
|
||||
if webnotes.flags.has_dataurl:
|
||||
doc.fields[fieldname] = content
|
||||
|
||||
|
||||
def save_file(fname, content, dt, dn, decode=False):
|
||||
if decode:
|
||||
if isinstance(content, unicode):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue