Wire up FE uploads to TO form
This commit is contained in:
parent
8eba9a097d
commit
f5c8424b46
@ -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))
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
@ -114,7 +114,7 @@ def form_step_one_add_pdf(portfolio_id=None, task_order_id=None):
|
||||
@task_orders_bp.route("/task_orders/<task_order_id>/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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -4,7 +4,7 @@
|
||||
<uploadinput
|
||||
inline-template
|
||||
{% if not field.errors %}
|
||||
v-bind:initial-data='{{ field.data | tojson }}'
|
||||
v-bind:initial-data='{{ field.filename.data | tojson }}'
|
||||
{% else %}
|
||||
v-bind:initial-errors='true'
|
||||
{% endif %}
|
||||
@ -43,6 +43,8 @@
|
||||
aria-label="Task Order Upload"
|
||||
v-bind:value="attachment"
|
||||
type="file">
|
||||
<input type="hidden" name="{{ field.filename.name }}" id="{{ field.filename.name }}" ref="attachmentFilename">
|
||||
<input type="hidden" name="{{ field.object_name.name }}" id="{{ field.object_name.name }}" ref="attachmentObjectName">
|
||||
</div>
|
||||
{% for error in field.errors %}
|
||||
<span v-show="showErrors" class="usa-input__message">{{error}}</span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user