Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if 'inline width' in status.extras and field.number in status.extras['inline width']:
inline_width = status.extras['inline width'][field.number]
else:
inline_width = None
if embedded:
extra_class = ' input-embedded'
if hasattr(field, 'datatype') and field.datatype == 'date':
extra_class += ' date-embedded'
if inline_width is not None:
extra_style = ' style="min-width: ' + unicode(inline_width) + '"'
else:
extra_style = ''
extra_checkbox = ' checkbox-embedded'
extra_radio = 'radio-embedded'
if field.number in status.labels:
label_text = strip_quote(to_text(markdown_to_html(status.labels[field.number], trim=False, status=status, strip_newlines=True), dict(), list(), status).strip())
else:
label_text = 'no label'
if label_text != 'no label':
title_text = ' title="' + label_text + '"'
else:
title_text = ''
else:
extra_style = ''
extra_class = ''
extra_checkbox = ''
extra_radio = ''
title_text = ''
if hasattr(field, 'choicetype'):
if field.choicetype in ['compute', 'manual']:
pairlist = list(status.selectcompute[field.number])
else:
master_output += ' <section class="tab-pane active col-lg-6 col-md-7 col-sm-9" id="question" role="tabpanel">\n'
output = ""
if the_progress_bar and status.question.question_type != "signature":
output += the_progress_bar
if status.question.question_type == "signature":
output += ' <div id="sigpage" class="sigpage">\n <div id="sigheader" class="sigshowsmallblock sigheader">\n <div class="siginnerheader">\n <a class="btn btn-sm btn-warning signav-left signavbutton sigclear">' + word('Clear') + '</a>\n <a class="btn btn-sm btn-primary signav-right signavbutton sigsave">' + continue_label + '</a>\n <div class="sigtitle">'
if status.questionText:
output += markdown_to_html(status.questionText, trim=True)
else:
output += word('Sign Your Name')
output += '</div>\n </div>\n </div>\n <div id="sigtoppart" class="sigtoppart">\n <div class="sigerrormessage signotshowing" id="errormess">' + word("You must sign your name to continue.") + '</div>\n'
if status.questionText:
output += ' <div class="sighidesmall">' + markdown_to_html(status.questionText, trim=True) + '</div>\n'
output += ' </div>'
if status.subquestionText:
output += '\n <div class="sigmidpart">\n ' + markdown_to_html(status.subquestionText) + '\n </div>'
else:
output += '\n <div class="sigmidpart"></div>'
output += '\n <div id="sigcontent"><p style="text-align:center;border-style:solid;border-width:1px">' + word('Loading. Please wait . . . ') + '</p></div>\n <div id="sigbottompart" class="sigbottompart">\n '
if (status.underText):
output += markdown_to_html(status.underText, trim=True)
output += "\n </div>"
output += """
<div class="form-actions sighidesmall sigbuttons">
<a class="btn btn-primary">""" + continue_label + """</a>
<a class="btn btn-warning">""" + word('Clear') + """</a>
</div>
"""
output += ' </div>\n <form method="POST" id="dasigform" action="' + root + '"><input value="' + escape_id(status.question.fields[0].saveas) + '" name="_save_as" type="hidden"><input value="" name="_the_image" id="_the_image" type="hidden"><input value="0" name="_success" id="_success" type="hidden">'
output += tracker_tag(status)
output += ' </form>\n'
output += ' <div class="sigshowsmallblock"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>'</section>
def markdown_to_docx(text, question, tpl):
if get_config('new markdown to docx', False):
source_code = docassemble.base.filter.markdown_to_html(text, do_terms=False)
source_code = re.sub("\n", ' ', source_code)
source_code = re.sub(">\s+<", '><', source_code)
soup = BeautifulSoup('' + source_code + '', 'html.parser')
parser = SoupParser(tpl)
for elem in soup.find_all(recursive=False):
parser.traverse(elem)
output = text_type(parser)
# logmessage(output)
return docassemble.base.filter.docx_template_filter(output, question=question)
else:
return inline_markdown_to_docx(text, question, tpl)
output += ' \n \n'
elif status.question.question_type == "fields":
enctype_string = ""
fieldlist = list()
checkboxes = list()
files = list()
hiddens = dict()
ml_info = dict()
note_fields = dict()
checkbox_validation = False
if status.subquestionText:
sub_question_text = markdown_to_html(status.subquestionText, status=status, indent=18, embedder=embed_input)
field_list = status.get_field_list()
for field in field_list:
if hasattr(field, 'datatype') and field.datatype == 'note':
note_fields[field.number] = ' <div class="row"><div class="col-md-12">' + markdown_to_html(status.extras['note'][field.number], status=status, embedder=embed_input) + '</div></div>\n'
for field in field_list:
if is_empty_mc(status, field):
if hasattr(field, 'datatype'):
hiddens[field.saveas] = field.datatype
else:
hiddens[field.saveas] = True
if hasattr(field, 'datatype'):
datatypes[field.saveas] = field.datatype
if field.datatype == 'object_checkboxes':
datatypes[safeid(from_safeid(field.saveas) + ".gathered")] = 'boolean'
continue
if not status.extras['ok'][field.number]:
continue
if status.extras['required'][field.number]:
req_tag = ' required'
else:
output += ' <div id="sigpage" class="sigpage">\n <div id="sigheader" class="sigshowsmallblock sigheader">\n <div class="siginnerheader">\n <a class="btn btn-sm btn-warning signav-left signavbutton sigclear">' + word('Clear') + '</a>\n <a class="btn btn-sm btn-primary signav-right signavbutton sigsave">' + continue_label + '</a>\n <div class="sigtitle">'
if status.questionText:
output += markdown_to_html(status.questionText, trim=True)
else:
output += word('Sign Your Name')
output += '</div>\n </div>\n </div>\n <div id="sigtoppart" class="sigtoppart">\n <div class="sigerrormessage signotshowing" id="errormess">' + word("You must sign your name to continue.") + '</div>\n'
if status.questionText:
output += ' <div class="sighidesmall">' + markdown_to_html(status.questionText, trim=True) + '</div>\n'
output += ' </div>'
if status.subquestionText:
output += '\n <div class="sigmidpart">\n ' + markdown_to_html(status.subquestionText) + '\n </div>'
else:
output += '\n <div class="sigmidpart"></div>'
output += '\n <div id="sigcontent"><p style="text-align:center;border-style:solid;border-width:1px">' + word('Loading. Please wait . . . ') + '</p></div>\n <div id="sigbottompart" class="sigbottompart">\n '
if (status.underText):
output += markdown_to_html(status.underText, trim=True)
output += "\n </div>"
output += """
<div class="form-actions sighidesmall sigbuttons">
<a class="btn btn-primary">""" + continue_label + """</a>
<a class="btn btn-warning">""" + word('Clear') + """</a>
</div>
"""
output += ' </div>\n <form method="POST" id="dasigform" action="' + root + '"><input value="' + escape_id(status.question.fields[0].saveas) + '" name="_save_as" type="hidden"><input value="" name="_the_image" id="_the_image" type="hidden"><input value="0" name="_success" id="_success" type="hidden">'
output += tracker_tag(status)
output += ' </form>\n'
output += ' <div class="sigshowsmallblock"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>'
elif status.question.question_type in ["yesno", "yesnomaybe"]:
#varnames[safeid('_field_' + str(status.question.fields[0].number))] = status.question.fields[0].saveas
datatypes[status.question.fields[0].saveas] = status.question.fields[0].datatype
output += indent_by(audio_text, 12) + ' <form method="POST" id="daform" action="' + root + '">\n <fieldset>\n'
output += ' <div class="page-header"><h3>' + decoration_text + markdown_to_html(status.questionText, trim=True, status=status, strip_newlines=True) + '<div class="daclear"></div></h3></div>\n'</fieldset></form>
else:
ischecked = ''
inner_fieldlist.append(help_wrap('<input value="' + unicode(pair['key']) + '" type="radio" name="' + escape_id(saveas_string) + '" id="' + escape_id(saveas_string) + '_' + str(id_index) + '" class="to-labelauty radio-icon' + extra_radio + '" data-labelauty="' + my_escape(the_icon) + formatted_item + '|' + my_escape(the_icon) + formatted_item + '" alt="' + formatted_item + '">', helptext))
else:
inner_fieldlist.append(help_wrap('<div>' + the_icon + markdown_to_html(unicode(pair['label']), status=status) + '</div>', helptext))
id_index += 1
if embedded:
output += '<span class="embed-radio-wrapper">' + " ".join(inner_fieldlist) + '</span>'
else:
output += "".join(inner_fieldlist)
else:
if embedded:
emb_text = 'class="input-embedded" '
if inline_width is not None:
emb_text += 'style="min-width: ' + unicode(inline_width) + '" '
label_text = strip_quote(to_text(markdown_to_html(status.labels[field.number], trim=False, status=status, strip_newlines=True), dict(), list(), status).strip())
if label_text != 'no label':
emb_text += 'title="' + label_text + '" '
else:
output += '<p class="sr-only">' + word('Select box') + '</p>'
if hasattr(field, 'datatype') and field.datatype == 'combobox':
emb_text = 'class="form-control combobox" '
else:
emb_text = 'class="form-control" '
if embedded:
output += '<span class="inline-error-wrapper">'
output += '<select id="' + escape_id(saveas_string) + '">'
if hasattr(field, 'datatype') and field.datatype == 'combobox' and not embedded:
if placeholdertext == '':
output += '<option value="">' + word('Select one') + '</option>'
else:
output += '<option value="">' + unicode(status.hints[field.number].replace('\n', ' ')) + '</option>'</select></span>
if embedded:
output += '<span class="inline-error-wrapper">'
output += '<select id="' + escape_id(saveas_string) + '">'
if hasattr(field, 'datatype') and field.datatype == 'combobox' and not embedded:
if placeholdertext == '':
output += '<option value="">' + word('Select one') + '</option>'
else:
output += '<option value="">' + unicode(status.hints[field.number].replace('\n', ' ')) + '</option>'
else:
if placeholdertext == '':
output += '<option value="">' + word('Select...') + '</option>'
else:
output += '<option value="">' + unicode(status.hints[field.number].replace('\n', ' ')) + '</option>'
for pair in pairlist:
if True or pair['key'] is not None:
formatted_item = markdown_to_html(unicode(pair['label']), status=status, trim=True, do_terms=False)
output += '<option is="" in="" value="' + unicode(pair['key']) + '">'
if embedded:
output += '</option></select></span> '
else:
output += ' '
elif hasattr(field, 'datatype'):
if field.datatype == 'boolean':
label_text = markdown_to_html(status.labels[field.number], trim=True, status=status, strip_newlines=True, escape=(not embedded), do_terms=False)
if hasattr(field, 'inputtype') and field.inputtype in ['yesnoradio', 'noyesradio']:
inner_fieldlist = list()
id_index = 0
if embedded:
output += '<span class="embed-radio-wrapper">'</span>
the_icon = icon_html(status, pair['image']) + ' '
else:
the_icon = ''
helptext = pair.get('help', None)
if ('default' in pair and pair['default']) or (defaultvalue is not None and type(defaultvalue) in [str, unicode, int, bool, float] and unicode(pair['key']) == unicode(defaultvalue)):
ischecked = ' checked="checked"'
else:
ischecked = ''
if embedded:
inner_fieldlist.append('<input value="' + unicode(pair['key']) + '" type="radio" name="' + escape_id(saveas_string) + '" id="' + escape_id(saveas_string) + '_' + str(id_index) + '" class="radio-embedded"> <label for="' + escape_id(saveas_string) + '_' + str(id_index) + '">' + the_icon + formatted_item + '</label>')
else:
inner_fieldlist.append(help_wrap('<input value="' + unicode(pair['key']) + '" type="radio" name="' + escape_id(saveas_string) + '" id="' + escape_id(saveas_string) + '_' + str(id_index) + '" class="to-labelauty radio-icon' + extra_radio + '" data-labelauty="' + my_escape(the_icon) + formatted_item + '|' + my_escape(the_icon) + formatted_item + '" alt="' + formatted_item + '">', helptext))
id_index += 1
else:
for pair in [dict(key='False', label=status.question.yes()), dict(key='True', label=status.question.no()), dict(key='None', label=status.question.maybe())]:
formatted_item = markdown_to_html(unicode(pair['label']), status=status, trim=True, escape=(not embedded), do_terms=False)
if 'image' in pair:
the_icon = icon_html(status, pair['image']) + ' '
else:
the_icon = ''
helptext = pair.get('help', None)
if ('default' in pair and pair['default']) or (defaultvalue is not None and type(defaultvalue) in [str, unicode, int, bool, float] and unicode(pair['key']) == unicode(defaultvalue)):
ischecked = ' checked="checked"'
else:
ischecked = ''
if embedded:
inner_fieldlist.append('<input value="' + unicode(pair['key']) + '" type="radio" name="' + escape_id(saveas_string) + '" id="' + escape_id(saveas_string) + '_' + str(id_index) + '" class="radio-embedded"> <label for="' + escape_id(saveas_string) + '_' + str(id_index) + '">' + the_icon + formatted_item + '</label>')
else:
inner_fieldlist.append(help_wrap('<input value="' + unicode(pair['key']) + '" type="radio" name="' + escape_id(saveas_string) + '" id="' + escape_id(saveas_string) + '_' + str(id_index) + '" class="to-labelauty radio-icon' + extra_radio + '" data-labelauty="' + my_escape(the_icon) + formatted_item + '|' + my_escape(the_icon) + formatted_item + '" alt="' + formatted_item + '">', helptext))
id_index += 1
if embedded:
output += " ".join(inner_fieldlist) + ''
def as_html(status, url_for, debug, root, validation_rules, field_error, the_progress_bar):
decorations = list()
uses_audio_video = False
audio_text = ''
video_text = ''
datatypes = dict()
varnames = dict()
onchange = list()
if 'script' in status.extras and status.extras['script'] is not None:
status.extra_scripts.append(status.extras['script'])
if 'css' in status.extras and status.extras['css'] is not None:
status.extra_css.append(status.extras['css'])
if status.continueLabel:
continue_label = markdown_to_html(status.continueLabel, trim=True, do_terms=False)
else:
continue_label = word('Continue')
# if status.question.script is not None:
# status.extra_scripts.append(status.question.script)
if status.audiovideo is not None:
uses_audio_video = True
audio_urls = get_audio_urls(status.audiovideo)
if len(audio_urls):
audio_text += '<div>\n' + audio_control(audio_urls) + '</div>\n'
video_urls = get_video_urls(status.audiovideo)
if len(video_urls):
video_text += '<div>\n' + video_control(video_urls) + '</div>\n'
if status.using_screen_reader and 'question' in status.screen_reader_links:
audio_text += '<div>\n' + audio_control(status.screen_reader_links['question'], preload="none") + '</div>\n'
if status.decorations is not None:
#sys.stderr.write("yoo1\n")
elif type(defaultvalue) is dict and unicode(pair['key']) in defaultvalue and defaultvalue[unicode(pair['key'])]:
ischecked = ' checked'
elif (hasattr(defaultvalue, 'elements') and type(defaultvalue.elements) is dict) and unicode(pair['key']) in defaultvalue.elements and defaultvalue.elements[unicode(pair['key'])]:
ischecked = ' checked'
elif pair['key'] is defaultvalue:
ischecked = ' checked'
elif type(defaultvalue) in [str, unicode, int, bool, float] and unicode(pair['key']) == unicode(defaultvalue):
ischecked = ' checked'
else:
ischecked = ''
if embedded:
inner_fieldlist.append('<input value="True" type="checkbox" name="' + inner_field + '" id="' + escape_id(saveas_string) + '_' + str(id_index) + '" class="checkbox-embedded dafield' + str(field.number) + ' non-nota-checkbox"> <label for="' + escape_id(saveas_string) + '_' + str(id_index) + '">' + the_icon + formatted_item + '</label>')
else:
inner_fieldlist.append(help_wrap('<input value="True" type="checkbox" name="' + inner_field + '" id="' + escape_id(saveas_string) + '_' + str(id_index) + '" class="' + 'dafield' + str(field.number) + ' non-nota-checkbox to-labelauty checkbox-icon' + extra_checkbox + '" data-labelauty="' + my_escape(the_icon) + formatted_item + '|' + my_escape(the_icon) + formatted_item + '" alt="' + formatted_item + '">', helptext))
else:
inner_fieldlist.append(help_wrap('<div>' + markdown_to_html(pair['label'], status=status) + '</div>', helptext))
id_index += 1
if hasattr(field, 'nota') and 'nota' in status.extras and status.extras['nota'][field.number] is not False:
if defaultvalue_set and defaultvalue is None:
ischecked = ' checked'
else:
ischecked = ''
if status.extras['nota'][field.number] is True:
formatted_item = word("None of the above")
else:
formatted_item = markdown_to_html(unicode(status.extras['nota'][field.number]), status=status, trim=True, escape=(not embedded), do_terms=False)
if embedded:
inner_fieldlist.append('<input name="_ignore' + str(field.number) + '" type="checkbox" id="_ignore' + str(field.number) + '" class="dafield' + str(field.number) + ' checkbox-embedded nota-checkbox"> <label for="_ignore' + str(field.number) + '">' + formatted_item + '</label>')
else:
inner_fieldlist.append('<input name="_ignore' + str(field.number) + '" type="checkbox" class="' + 'dafield' + str(field.number) + ' nota-checkbox to-labelauty checkbox-icon' + extra_checkbox + '" data-labelauty="' + formatted_item + '|' + formatted_item + '" alt="' + formatted_item + '">')
if embedded:
output += u' '.join(inner_fieldlist) + ''