Handle empty values
This commit is contained in:
parent
e40c6c67a3
commit
3f3b90e3c7
@ -3,9 +3,8 @@ from flask import current_app as app
|
|||||||
|
|
||||||
from atst.database import db
|
from atst.database import db
|
||||||
from atst.models.task_order import TaskOrder, Source, FundingType
|
from atst.models.task_order import TaskOrder, Source, FundingType
|
||||||
from atst.models.attachment import Attachment
|
|
||||||
from .exceptions import NotFoundError
|
from .exceptions import NotFoundError
|
||||||
from atst.utils import drop, update_obj
|
from atst.utils import update_obj
|
||||||
|
|
||||||
|
|
||||||
class TaskOrders(object):
|
class TaskOrders(object):
|
||||||
@ -53,7 +52,7 @@ class TaskOrders(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update(cls, task_order, dct):
|
def update(cls, task_order, dct):
|
||||||
updated = update_obj(task_order, dct)
|
updated = update_obj(task_order, dct, ignore_vals=lambda v: v in ["", None])
|
||||||
db.session.add(updated)
|
db.session.add(updated)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return updated
|
return updated
|
||||||
|
@ -33,9 +33,9 @@ def getattr_path(obj, path, default=None):
|
|||||||
return _obj
|
return _obj
|
||||||
|
|
||||||
|
|
||||||
def update_obj(obj, dct):
|
def update_obj(obj, dct, ignore_vals=lambda v: v is None):
|
||||||
for k, v in dct.items():
|
for k, v in dct.items():
|
||||||
if hasattr(obj, k) and v is not None:
|
if hasattr(obj, k) and not ignore_vals(v):
|
||||||
setattr(obj, k, v)
|
setattr(obj, k, v)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@ -255,6 +255,17 @@ def test_task_order_info_present_in_extended_form(fv_data, e_fv_data):
|
|||||||
assert form.task_order.clin_0001.data
|
assert form.task_order.clin_0001.data
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_ignores_empty_values(fv_data, e_fv_data):
|
||||||
|
request = RequestFactory.create()
|
||||||
|
user = UserFactory.create()
|
||||||
|
data = {
|
||||||
|
**fv_data, **e_fv_data, "task_order-funding_type": ""
|
||||||
|
}
|
||||||
|
SaveFinancialVerificationDraft(
|
||||||
|
TrueValidator, TrueValidator, user, request, data, is_extended=True
|
||||||
|
).execute()
|
||||||
|
|
||||||
|
|
||||||
def test_simple_form_does_not_generate_task_order(fv_data):
|
def test_simple_form_does_not_generate_task_order(fv_data):
|
||||||
request = RequestFactory.create()
|
request = RequestFactory.create()
|
||||||
user = UserFactory.create()
|
user = UserFactory.create()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user