diff --git a/flaskr/templates/writing.html b/flaskr/templates/writing.html index aab92e9..4b79068 100644 --- a/flaskr/templates/writing.html +++ b/flaskr/templates/writing.html @@ -61,6 +61,13 @@ {{ render_field(form.body, 'class=bigtext') }} {{ render_field(form.closingtext) }} + {% if err %} +

+ {% for error in err %} + {{ error }}
+ {% endfor %} +

+ {% endif %}

diff --git a/latty.py b/latty.py index 13f569c..a7b6d46 100644 --- a/latty.py +++ b/latty.py @@ -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) diff --git a/writing.py b/writing.py index 728a320..ac1fd44 100644 --- a/writing.py +++ b/writing.py @@ -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]))