Display latex errors as applicable

This commit is contained in:
Sage Vaillancourt 2021-07-27 23:39:30 -04:00
parent b8ddd290a7
commit e200399366
3 changed files with 22 additions and 9 deletions

View File

@ -61,6 +61,13 @@
{{ render_field(form.body, 'class=bigtext') }}
{{ render_field(form.closingtext) }}
</dl>
{% if err %}
<p>
{% for error in err %}
{{ error }}<br>
{% endfor %}
</p>
{% endif %}
<p><input type=submit value="Submit"></p>
</form>
</body>

View File

@ -47,20 +47,25 @@ class CLData():
f.write(open(proj_dir + "/writing_templates/base.tex", "r").read())
f.close()
com = "pdflatex -halt-on-error -jobname=outputs/" + unique_id + " " + unique_file
output_arg="-jobname=outputs/" + unique_id + " " + unique_file
com = "pdflatex -halt-on-error " + output_arg
print("COM: '" + com + "'")
try:
subprocess.check_call(['bash', '-c', com])
result = subprocess.run(['bash', '-c', com], stdout=subprocess.PIPE, text=True)
if result.returncode == 0:
threading.Timer(60 * 30, cleanup, [output_dir + unique_id]).start()
return send_from_directory(
return (send_from_directory(
output_dir,
unique_id + ".pdf",
attachment_filename=self.username.replace(" ", "") + "_CoverLetter.pdf",
as_attachment=True
)
except subprocess.CalledProcessError:
return None
), None)
else:
errors = result.stdout.split("\n")
del errors[:13]
del errors[-2:]
return (None, errors)
def cleanup(unique):
print(unique)

View File

@ -61,11 +61,12 @@ def index():
body=form.body.data,
)
resp = data.generate_pdf()
(resp, err) = data.generate_pdf()
# Save entered data as cookies on user's machine
if not resp:
if err:
resp = make_response(render_template('writing.html',
form=form,
err=err,
))
for pair in data.get_pairs():
resp.set_cookie(pair[0], urllib.parse.quote(pair[1]))