Only set attrs in the setter
This commit is contained in:
parent
9182b1078c
commit
fb95033dbe
@ -84,8 +84,7 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
|||||||
|
|
||||||
@csp_estimate.setter
|
@csp_estimate.setter
|
||||||
def csp_estimate(self, new_csp_estimate):
|
def csp_estimate(self, new_csp_estimate):
|
||||||
if not self._set_attachment_type(new_csp_estimate, "_csp_estimate"):
|
self._csp_estimate = self._set_attachment(new_csp_estimate, "_csp_estimate")
|
||||||
raise TypeError("Could not set csp_estimate with invalid type")
|
|
||||||
|
|
||||||
@hybrid_property
|
@hybrid_property
|
||||||
def pdf(self):
|
def pdf(self):
|
||||||
@ -93,23 +92,17 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
|||||||
|
|
||||||
@pdf.setter
|
@pdf.setter
|
||||||
def pdf(self, new_pdf):
|
def pdf(self, new_pdf):
|
||||||
if not self._set_attachment_type(new_pdf, "_pdf"):
|
self._pdf = self._set_attachment(new_pdf, "_pdf")
|
||||||
raise TypeError("Could not set pdf with invalid type")
|
|
||||||
|
|
||||||
def _set_attachment_type(self, new_attachment, property):
|
def _set_attachment(self, new_attachment, property):
|
||||||
if isinstance(new_attachment, Attachment):
|
if isinstance(new_attachment, Attachment):
|
||||||
setattr(self, property, new_attachment)
|
return new_attachment
|
||||||
return True
|
|
||||||
elif isinstance(new_attachment, FileStorage):
|
elif isinstance(new_attachment, FileStorage):
|
||||||
setattr(
|
return Attachment.attach(new_attachment, "task_order", self.id)
|
||||||
self, property, Attachment.attach(new_attachment, "task_order", self.id)
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
elif not new_attachment and hasattr(self, property):
|
elif not new_attachment and hasattr(self, property):
|
||||||
setattr(self, property, None)
|
return None
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
return False
|
raise TypeError("Could not set attachment with invalid type")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_submitted(self):
|
def is_submitted(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user