diff --git a/atst/forms/task_order.py b/atst/forms/task_order.py index fca7bcfd..3ab8684c 100644 --- a/atst/forms/task_order.py +++ b/atst/forms/task_order.py @@ -5,6 +5,7 @@ from wtforms.fields import ( FileField, FormField, StringField, + HiddenField ) from wtforms.fields.html5 import DateField from wtforms.validators import Required, Optional @@ -62,17 +63,14 @@ class CLINForm(FlaskForm): return valid +class AttachmentForm(BaseForm): + filename = HiddenField(id="attachment_filename") + object_name = HiddenField(id="attachment_object_name") + + class TaskOrderForm(BaseForm): number = StringField(label=translate("forms.task_order.number_description")) - pdf = FileField( - None, - description=translate("task_orders.form.supporting_docs_size_limit"), - validators=[ - FileAllowed(["pdf"], translate("forms.task_order.file_format_not_allowed")), - FileLength(message=translate("forms.validators.file_length")), - ], - render_kw={"accept": ".pdf,application/pdf"}, - ) + pdf = FormField(AttachmentForm, label=translate("task_orders.form.supporting_docs_size_limit"), description=translate("task_orders.form.supporting_docs_size_limit")) clins = FieldList(FormField(CLINForm)) diff --git a/atst/models/task_order.py b/atst/models/task_order.py index 247ff2c8..5b873d71 100644 --- a/atst/models/task_order.py +++ b/atst/models/task_order.py @@ -9,6 +9,7 @@ from werkzeug.datastructures import FileStorage from atst.models import Attachment, Base, mixins, types from atst.models.clin import JEDICLINType from atst.utils.clock import Clock +from atst.database import db class Status(Enum): @@ -55,6 +56,11 @@ class TaskOrder(Base, mixins.TimestampsMixin): self._pdf = self._set_attachment(new_pdf, "_pdf") def _set_attachment(self, new_attachment, attribute): + if isinstance(new_attachment, dict): + attachment = Attachment(**new_attachment) + db.session.add(attachment) + db.session.commit + return attachment if isinstance(new_attachment, Attachment): return new_attachment elif isinstance(new_attachment, FileStorage): diff --git a/atst/routes/task_orders/new.py b/atst/routes/task_orders/new.py index cb5b89f2..375fc845 100644 --- a/atst/routes/task_orders/new.py +++ b/atst/routes/task_orders/new.py @@ -114,7 +114,7 @@ def form_step_one_add_pdf(portfolio_id=None, task_order_id=None): @task_orders_bp.route("/task_orders//form/step_1", methods=["POST"]) @user_can(Permissions.CREATE_TASK_ORDER, message="update task order form") def submit_form_step_one_add_pdf(portfolio_id=None, task_order_id=None): - form_data = {**http_request.form, **http_request.files} + form_data = {**http_request.form} next_page = "task_orders.form_step_two_add_number" current_template = "task_orders/step_1.html" diff --git a/js/components/upload_input.js b/js/components/upload_input.js index 4763b010..22a7c81c 100644 --- a/js/components/upload_input.js +++ b/js/components/upload_input.js @@ -67,6 +67,8 @@ export default { await this.uploader.upload(file, this.objectName) this.attachment = e.target.value this.showErrors = false + this.$refs.attachmentFilename.value = file.name + this.$refs.attachmentObjectName.value = this.objectName } catch (err) { console.log(err) this.showErrors = true diff --git a/templates/components/upload_input.html b/templates/components/upload_input.html index cacb66c3..a7203bcc 100644 --- a/templates/components/upload_input.html +++ b/templates/components/upload_input.html @@ -4,7 +4,7 @@ + + {% for error in field.errors %} {{error}}