def transform_for_docx(text, question, tpl, width=None): if type(text) in (int, float, bool, NoneType): return text text = unicode(text) m = re.search(r'\[FILE ([^,\]]+), *([0-9\.]) *([A-Za-z]+) *\]', text) if m: amount = m.group(2) units = m.group(3).lower() if units in ['in', 'inches', 'inch']: the_width = Inches(amount) elif units in ['pt', 'pts', 'point', 'points']: the_width = Pt(amount) elif units in ['mm', 'millimeter', 'millimeters']: the_width = Mm(amount) else: the_width = Pt(amount) file_info = server.file_finder(m.group(1), convert={'svg': 'png'}, question=question) if 'fullpath' not in file_info: return '[FILE NOT FOUND]' return InlineImage(tpl, file_info['fullpath'], the_width) m = re.search(r'\[FILE ([^,\]]+)\]', text) if m: file_info = server.file_finder(m.group(1), convert={'svg': 'png'}, question=question) if 'fullpath' not in file_info: return '[FILE NOT FOUND]' return InlineImage(tpl, file_info['fullpath'], Inches(2)) return docassemble.base.filter.docx_template_filter(text)
def transform_for_docx(text, question, tpl, width=None): if type(text) in (int, float, bool, NoneType): return text text = unicode(text) m = re.search(r'\[FILE ([^,\]]+), *([0-9\.]) *([A-Za-z]+) *\]', text) if m: amount = m.group(2) units = m.group(3).lower() if units in ['in', 'inches', 'inch']: the_width = Inches(amount) elif units in ['pt', 'pts', 'point', 'points']: the_width = Pt(amount) elif units in ['mm', 'millimeter', 'millimeters']: the_width = Mm(amount) else: the_width = Pt(amount) file_info = server.file_finder(m.group(1), convert={'svg': 'png'}, question=question) if 'fullpath' not in file_info: return '[FILE NOT FOUND]' return InlineImage(tpl, file_info['fullpath'], the_width) m = re.search(r'\[FILE ([^,\]]+)\]', text) if m: file_info = server.file_finder(m.group(1), convert={'svg': 'png'}, question=question) if 'fullpath' not in file_info: return '[FILE NOT FOUND]' return InlineImage(tpl, file_info['fullpath'], Inches(2)) return docassemble.base.filter.docx_template_filter(text)
def image_for_docx(fileref, question, tpl, width=None): if fileref.__class__.__name__ in ('DAFile', 'DAFileList', 'DAFileCollection', 'DALocalFile'): file_info = dict(fullpath=fileref.path()) else: file_info = server.file_finder(fileref, convert={'svg': 'png'}, question=question) if 'fullpath' not in file_info: return '[FILE NOT FOUND]' if width is not None: m = re.search(r'^([0-9\.]+) *([A-Za-z]*)', str(width)) if m: amount = float(m.group(1)) units = m.group(2).lower() if units in ['in', 'inches', 'inch']: the_width = Inches(amount) elif units in ['pt', 'pts', 'point', 'points']: the_width = Pt(amount) elif units in ['mm', 'millimeter', 'millimeters']: the_width = Mm(amount) else: the_width = Pt(amount) else: the_width = Inches(2) else: the_width = Inches(2) return InlineImage(tpl, file_info['fullpath'], the_width)
def image_for_docx(fileref, question, tpl, width=None): if fileref.__class__.__name__ in ('DAFile', 'DAFileList', 'DAFileCollection', 'DALocalFile'): file_info = dict(fullpath=fileref.path()) else: file_info = server.file_finder(fileref, convert={'svg': 'png'}, question=question) if 'fullpath' not in file_info: return '[FILE NOT FOUND]' if width is not None: m = re.search(r'^([0-9\.]+) *([A-Za-z]*)', str(width)) if m: amount = float(m.group(1)) units = m.group(2).lower() if units in ['in', 'inches', 'inch']: the_width = Inches(amount) elif units in ['pt', 'pts', 'point', 'points']: the_width = Pt(amount) elif units in ['mm', 'millimeter', 'millimeters']: the_width = Mm(amount) else: the_width = Pt(amount) else: the_width = Inches(2) else: the_width = Inches(2) return InlineImage(tpl, file_info['fullpath'], the_width)
def image_for_docx(number, question, tpl, width=None): file_info = server.file_finder(number, convert={'svg': 'png'}, question=question) if 'fullpath' not in file_info: return '[FILE NOT FOUND]' if width is not None: m = re.search(r'^([0-9\.]+) *([A-Za-z]*)', str(width)) if m: amount = float(m.group(1)) units = m.group(2).lower() if units in ['in', 'inches', 'inch']: the_width = Inches(amount) elif units in ['pt', 'pts', 'point', 'points']: the_width = Pt(amount) elif units in ['mm', 'millimeter', 'millimeters']: the_width = Mm(amount) else: the_width = Pt(amount) else: the_width = Inches(2) else: logmessage("err 2") the_width = Inches(2) return InlineImage(tpl, file_info['fullpath'], the_width)