mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-09 22:09:02 +08:00
Added validation to the models
This commit is contained in:
parent
68a90ec510
commit
a382b77eaa
@ -6,6 +6,10 @@
|
|||||||
class BaseModel:
|
class BaseModel:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.__dict__.update(kwargs)
|
self.__dict__.update(kwargs)
|
||||||
|
self.validate()
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
## Class representing a material that was fetched from the cluster API.
|
## Class representing a material that was fetched from the cluster API.
|
||||||
@ -19,6 +23,10 @@ class ClusterMaterial(BaseModel):
|
|||||||
self.density = None # type: str
|
self.density = None # type: str
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
if not self.guid:
|
||||||
|
raise ValueError("guid is required on ClusterMaterial")
|
||||||
|
|
||||||
|
|
||||||
## Class representing a local material that was fetched from the container registry.
|
## Class representing a local material that was fetched from the container registry.
|
||||||
class LocalMaterial(BaseModel):
|
class LocalMaterial(BaseModel):
|
||||||
@ -40,3 +48,9 @@ class LocalMaterial(BaseModel):
|
|||||||
self.definition = None # type: str
|
self.definition = None # type: str
|
||||||
self.compatible = None # type: bool
|
self.compatible = None # type: bool
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
if not self.GUID:
|
||||||
|
raise ValueError("guid is required on LocalMaterial")
|
||||||
|
if not self.id:
|
||||||
|
raise ValueError("id is required on LocalMaterial")
|
||||||
|
@ -159,8 +159,8 @@ class SendMaterialJob(Job):
|
|||||||
Logger.log("e", "Request material storage on printer: I didn't understand the printer's answer.")
|
Logger.log("e", "Request material storage on printer: I didn't understand the printer's answer.")
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
Logger.log("e", "Request material storage on printer: I didn't understand the printer's answer.")
|
Logger.log("e", "Request material storage on printer: I didn't understand the printer's answer.")
|
||||||
except TypeError:
|
except ValueError:
|
||||||
Logger.log("e", "Request material storage on printer: Printer's answer was missing GUIDs.")
|
Logger.log("e", "Request material storage on printer: Printer's answer was missing a value.")
|
||||||
|
|
||||||
## Retrieves a list of local materials
|
## Retrieves a list of local materials
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user