commit
b63da3ad54
@ -1,7 +1,10 @@
|
|||||||
|
from datetime import datetime
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from werkzeug.datastructures import FileStorage
|
||||||
from wtforms.validators import ValidationError, StopValidation
|
from wtforms.validators import ValidationError, StopValidation
|
||||||
import pendulum
|
import pendulum
|
||||||
from datetime import datetime
|
|
||||||
from atst.utils.localization import translate
|
from atst.utils.localization import translate
|
||||||
|
|
||||||
|
|
||||||
@ -103,7 +106,7 @@ def RequiredIf(criteria_function, message=translate("forms.validators.is_require
|
|||||||
|
|
||||||
def FileLength(max_length=50000000, message=None):
|
def FileLength(max_length=50000000, message=None):
|
||||||
def _file_length(_form, field):
|
def _file_length(_form, field):
|
||||||
if field.data is None:
|
if field.data is None or not isinstance(field.data, FileStorage):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
content = field.data.read()
|
content = field.data.read()
|
||||||
|
@ -42,7 +42,12 @@ def edit(portfolio_id, task_order_id=None):
|
|||||||
def update(portfolio_id, task_order_id=None):
|
def update(portfolio_id, task_order_id=None):
|
||||||
form_data = {**http_request.form, **http_request.files}
|
form_data = {**http_request.form, **http_request.files}
|
||||||
|
|
||||||
form = TaskOrderForm(form_data)
|
form = None
|
||||||
|
if task_order_id:
|
||||||
|
task_order = TaskOrders.get(task_order_id)
|
||||||
|
form = TaskOrderForm(form_data, obj=task_order)
|
||||||
|
else:
|
||||||
|
form = TaskOrderForm(form_data)
|
||||||
|
|
||||||
if form.validate():
|
if form.validate():
|
||||||
task_order = None
|
task_order = None
|
||||||
|
@ -26,24 +26,27 @@ export default {
|
|||||||
|
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
|
hasInitialData: !!this.initialData,
|
||||||
attachment: this.initialData || null,
|
attachment: this.initialData || null,
|
||||||
showErrors: this.initialErrors,
|
showErrors: this.initialErrors,
|
||||||
|
changed: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
showUploadInput: function() {
|
|
||||||
this.showUpload = true
|
|
||||||
},
|
|
||||||
addAttachment: function(e) {
|
addAttachment: function(e) {
|
||||||
this.attachment = e.target.value
|
this.attachment = e.target.value
|
||||||
this.showErrors = false
|
this.showErrors = false
|
||||||
|
this.changed = true
|
||||||
},
|
},
|
||||||
removeAttachment: function(e) {
|
removeAttachment: function(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
this.attachment = null
|
this.attachment = null
|
||||||
this.$refs.attachmentInput.value = null
|
if (this.$refs.attachmentInput) {
|
||||||
|
this.$refs.attachmentInput.value = null
|
||||||
|
}
|
||||||
this.showErrors = false
|
this.showErrors = false
|
||||||
|
this.changed = true
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -56,5 +59,8 @@ export default {
|
|||||||
hasAttachment: function() {
|
hasAttachment: function() {
|
||||||
return !!this.attachment
|
return !!this.attachment
|
||||||
},
|
},
|
||||||
|
hideInput: function() {
|
||||||
|
return this.hasInitialData && !this.changed
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
{{ field.label }}
|
{{ field.label }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ field.description }}
|
{{ field.description }}
|
||||||
<div class="upload-widget">
|
<div v-if="!hideInput" class="upload-widget">
|
||||||
<label class="upload-label" for="{{ field.name }}">
|
<label class="upload-label" for="{{ field.name }}">
|
||||||
<span class="upload-button">
|
<span class="upload-button">
|
||||||
Browse
|
Browse
|
||||||
|
@ -100,3 +100,6 @@ class TestFileLength:
|
|||||||
|
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
validator(dummy_form, dummy_field)
|
validator(dummy_form, dummy_field)
|
||||||
|
|
||||||
|
dummy_field.data = "random string"
|
||||||
|
assert validator(dummy_form, dummy_field)
|
||||||
|
@ -145,7 +145,7 @@ def test_task_orders_update_pdf(
|
|||||||
def test_task_orders_update_delete_pdf(client, user_session, portfolio, pdf_upload):
|
def test_task_orders_update_delete_pdf(client, user_session, portfolio, pdf_upload):
|
||||||
user_session(portfolio.owner)
|
user_session(portfolio.owner)
|
||||||
task_order = TaskOrderFactory.create(pdf=pdf_upload)
|
task_order = TaskOrderFactory.create(pdf=pdf_upload)
|
||||||
data = {"number": "0123456789", "pdf": None}
|
data = {"number": "0123456789", "pdf": ""}
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_for(
|
url_for(
|
||||||
"task_orders.update", portfolio_id=portfolio.id, task_order_id=task_order.id
|
"task_orders.update", portfolio_id=portfolio.id, task_order_id=task_order.id
|
||||||
|
Loading…
x
Reference in New Issue
Block a user