def map_of(*pargs, **kwargs): the_map = {'markers': list()} all_args = list() for arg in pargs: if type(arg) is list: all_args.extend(arg) else: all_args.append(arg) for arg in all_args: if isinstance(arg, DAObject): markers = arg.map_info() if markers: for marker in markers: if 'icon' in marker and type(marker['icon']) is not dict: marker['icon'] = {'url': url_finder(marker['icon'])} if 'info' in marker and marker['info']: marker['info'] = markdown_to_html(marker['info'], trim=True) the_map['markers'].append(marker) if 'center' in kwargs: the_center = kwargs['center'] if callable(getattr(the_center, 'map_info', None)): markers = the_center.map_info() if markers: the_map['center'] = markers[0] if 'center' not in the_map and len(the_map['markers']): the_map['center'] = the_map['markers'][0] if len(the_map['markers']) or 'center' in the_map: return '[MAP ' + codecs.encode( json.dumps(the_map).encode('utf-8'), 'base64').decode().replace( '\n', '') + ']' return '(Unable to display map)'
def map_of(*pargs, **kwargs): """Inserts into markup a Google Map representing the objects passed as arguments.""" the_map = {'markers': list()} all_args = list() for arg in pargs: if type(arg) is list: all_args.extend(arg) else: all_args.append(arg) for arg in all_args: if isinstance(arg, DAObject): markers = arg._map_info() if markers: for marker in markers: if 'icon' in marker and type(marker['icon']) is not dict: marker['icon'] = {'url': url_finder(marker['icon'])} if 'info' in marker and marker['info']: marker['info'] = markdown_to_html(marker['info'], trim=True) the_map['markers'].append(marker) if 'center' in kwargs: the_center = kwargs['center'] if callable(getattr(the_center, '_map_info', None)): markers = the_center._map_info() if markers: the_map['center'] = markers[0] if 'center' not in the_map and len(the_map['markers']): the_map['center'] = the_map['markers'][0] if len(the_map['markers']) or 'center' in the_map: return '[MAP ' + codecs.encode(json.dumps(the_map).encode('utf-8'), 'base64').decode().replace('\n', '') + ']' return '(Unable to display map)'
def map_of(*pargs, **kwargs): the_map = {"markers": list()} all_args = list() for arg in pargs: if type(arg) is list: all_args.extend(arg) else: all_args.append(arg) for arg in all_args: if isinstance(arg, DAObject): markers = arg.map_info() if markers: for marker in markers: if "icon" in marker and type(marker["icon"]) is not dict: marker["icon"] = {"url": url_finder(marker["icon"])} if "info" in marker and marker["info"]: marker["info"] = markdown_to_html(marker["info"], trim=True) the_map["markers"].append(marker) if "center" in kwargs: the_center = kwargs["center"] if callable(getattr(the_center, "map_info", None)): markers = the_center.map_info() if markers: the_map["center"] = markers[0] if "center" not in the_map and len(the_map["markers"]): the_map["center"] = the_map["markers"][0] if len(the_map["markers"]) or "center" in the_map: return "[MAP " + codecs.encode(json.dumps(the_map).encode("utf-8"), "base64").decode().replace("\n", "") + "]" return "(Unable to display map)"
def send_email(to=None, sender=None, cc=None, bcc=None, template=None, body=None, html=None, subject="", attachments=[]): from flask_mail import Message if type(to) is not list: to = [to] if len(to) == 0: return False if template is not None: if subject is None or subject == '': subject = template.subject body_html = '<html><body>' + markdown_to_html( template.content) + '</body></html>' if body is None: body = html2text.html2text(body_html) if html is None: html = body_html if body is None and html is None: body = "" email_stringer = lambda x: email_string(x, include_name=False) msg = Message(subject, sender=email_stringer(sender), recipients=email_stringer(to), cc=email_stringer(cc), bcc=email_stringer(bcc), body=body, html=html) success = True for attachment in attachments: attachment_list = list() if type(attachment) is DAFileCollection: subattachment = getattr(attachment, 'pdf', None) if subattachment is None: subattachment = getattr(attachment, 'rtf', None) if subattachment is None: subattachment = getattr(attachment, 'tex', None) if subattachment is not None: attachment_list.append(subattachment) else: success = False elif type(attachment) is DAFile: attachment_list.append(attachment) elif type(attachment) is DAFileList: attachment_list.extend(attachment.elements) else: success = False if success: for the_attachment in attachment_list: if the_attachment.ok: file_info = file_finder(str(the_attachment.number)) if ('path' in file_info): failed = True with open(file_info['path'], 'r') as fp: msg.attach(file_info['filename'], file_info['mimetype'], fp.read()) failed = False if failed: success = False else: success = False appmail = mail_variable() if not appmail: success = False if success: try: appmail.send(msg) except Exception as errmess: logmessage("Sending mail failed: " + str(errmess)) success = False return (success)
def send_email(to=None, sender=None, cc=None, bcc=None, template=None, body=None, html=None, subject="", attachments=[]): """Sends an e-mail and returns whether sending the e-mail was successful.""" from flask_mail import Message if type(to) is not list: to = [to] if len(to) == 0: return False if template is not None: if subject is None or subject == '': subject = template.subject body_html = '<html><body>' + markdown_to_html(template.content) + '</body></html>' if body is None: body = html2text.html2text(body_html) if html is None: html = body_html if body is None and html is None: body = "" email_stringer = lambda x: email_string(x, include_name=False) msg = Message(subject, sender=email_stringer(sender), recipients=email_stringer(to), cc=email_stringer(cc), bcc=email_stringer(bcc), body=body, html=html) success = True for attachment in attachments: attachment_list = list() if type(attachment) is DAFileCollection: subattachment = getattr(attachment, 'pdf', None) if subattachment is None: subattachment = getattr(attachment, 'rtf', None) if subattachment is None: subattachment = getattr(attachment, 'tex', None) if subattachment is not None: attachment_list.append(subattachment) else: success = False elif type(attachment) is DAFile: attachment_list.append(attachment) elif type(attachment) is DAFileList: attachment_list.extend(attachment.elements) else: success = False if success: for the_attachment in attachment_list: if the_attachment.ok: file_info = file_finder(str(the_attachment.number)) if ('path' in file_info): failed = True with open(file_info['path'], 'r') as fp: msg.attach(the_attachment.filename, file_info['mimetype'], fp.read()) failed = False if failed: success = False else: success = False # appmail = mail_variable() # if not appmail: # success = False if success: try: # appmail.send(msg) logmessage("Starting to send") async_mail(msg) logmessage("Finished sending") except Exception as errmess: logmessage("Sending mail failed: " + str(errmess)) success = False return(success)
def send_email( to=None, sender=None, cc=None, bcc=None, template=None, body=None, html=None, subject="", attachments=[] ): from flask_mail import Message if type(to) is not list: to = [to] if len(to) == 0: return False if template is not None: if subject is None or subject == "": subject = template.subject body_html = "<html><body>" + markdown_to_html(template.content) + "</body></html>" if body is None: body = html2text.html2text(body_html) if html is None: html = body_html if body is None and html is None: body = "" email_stringer = lambda x: email_string(x, include_name=False) msg = Message( subject, sender=email_stringer(sender), recipients=email_stringer(to), cc=email_stringer(cc), bcc=email_stringer(bcc), body=body, html=html, ) success = True for attachment in attachments: attachment_list = list() if type(attachment) is DAFileCollection: subattachment = getattr(attachment, "pdf", None) if subattachment is None: subattachment = getattr(attachment, "rtf", None) if subattachment is None: subattachment = getattr(attachment, "tex", None) if subattachment is not None: attachment_list.append(subattachment) else: success = False elif type(attachment) is DAFile: attachment_list.append(attachment) elif type(attachment) is DAFileList: attachment_list.extend(attachment.elements) else: success = False if success: for the_attachment in attachment_list: if the_attachment.ok: file_info = file_finder(str(the_attachment.number)) if "path" in file_info: failed = True with open(file_info["path"], "r") as fp: msg.attach(file_info["filename"], file_info["mimetype"], fp.read()) failed = False if failed: success = False else: success = False appmail = mail_variable() if not appmail: success = False if success: try: appmail.send(msg) except Exception as errmess: logmessage("Sending mail failed: " + str(errmess)) success = False return success