Add letter upload form which redirects to blank preview page

Added a form to upload a single letter. Currently this only uses the
form to validate that a file is submitted and that the file is a PDF. If
either of these validations fail, the form will display an error.
Otherwise, we redirect to a new preview page which just has the filename
as the heading for now.
This commit is contained in:
Katie Smith
2019-09-06 10:39:23 +01:00
parent f04512a31d
commit c577416866
8 changed files with 155 additions and 6 deletions

View File

@@ -1,6 +1,10 @@
from flask import render_template
import uuid
from flask import redirect, render_template, request, url_for
from app import current_service
from app.main import main
from app.main.forms import PDFUploadForm
from app.utils import user_has_permissions
@@ -8,3 +12,31 @@ from app.utils import user_has_permissions
@user_has_permissions('send_messages')
def uploads(service_id):
return render_template('views/uploads/index.html')
@main.route("/services/<service_id>/upload-letter", methods=['GET', 'POST'])
@user_has_permissions('send_messages')
def upload_letter(service_id):
form = PDFUploadForm()
if form.validate_on_submit():
upload_id = uuid.uuid4()
return redirect(
url_for(
'main.uploaded_letter_preview',
service_id=current_service.id,
file_id=upload_id,
original_filename=form.file.data.filename,
)
)
return render_template('views/uploads/choose-file.html', form=form)
@main.route("/services/<service_id>/preview-letter/<file_id>")
@user_has_permissions('send_messages')
def uploaded_letter_preview(service_id, file_id):
original_filename = request.args.get('original_filename')
return render_template('views/uploads/preview.html', original_filename=original_filename)