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.body, 'class=bigtext') }}
{{ render_field(form.closingtext) }} {{ render_field(form.closingtext) }}
</dl> </dl>
{% if err %}
<p>
{% for error in err %}
{{ error }}<br>
{% endfor %}
</p>
{% endif %}
<p><input type=submit value="Submit"></p> <p><input type=submit value="Submit"></p>
</form> </form>
</body> </body>

View File

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

View File

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