mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-29 15:31:28 +00:00
Serialize custom types
This commit is contained in:
parent
af902923ab
commit
5f34337fb4
|
@ -33,7 +33,6 @@ class JobStatus(Enum):
|
||||||
"""
|
"""
|
||||||
Status of a job.
|
Status of a job.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CREATED = "CREATED"
|
CREATED = "CREATED"
|
||||||
RUNNING = "RUNNING"
|
RUNNING = "RUNNING"
|
||||||
FINISHED = "FINISHED"
|
FINISHED = "FINISHED"
|
||||||
|
@ -44,8 +43,7 @@ class Job(BaseModel):
|
||||||
"""
|
"""
|
||||||
Job class.
|
Job class.
|
||||||
"""
|
"""
|
||||||
|
uid: UUID = uuid.uuid4()
|
||||||
uid: str = uuid.uuid4().urn
|
|
||||||
name: str
|
name: str
|
||||||
description: str
|
description: str
|
||||||
status: JobStatus
|
status: JobStatus
|
||||||
|
@ -118,10 +116,10 @@ class Jobs:
|
||||||
)
|
)
|
||||||
with WriteUserData(UserDataFiles.JOBS) as user_data:
|
with WriteUserData(UserDataFiles.JOBS) as user_data:
|
||||||
try:
|
try:
|
||||||
user_data.append(job.dict())
|
user_data.append(json.loads(job.json()))
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
user_data = []
|
user_data = []
|
||||||
user_data.append(job.dict())
|
user_data.append(json.loads(job.json()))
|
||||||
return job
|
return job
|
||||||
|
|
||||||
def remove(self, job: Job) -> None:
|
def remove(self, job: Job) -> None:
|
||||||
|
@ -162,7 +160,7 @@ class Jobs:
|
||||||
|
|
||||||
with WriteUserData(UserDataFiles.JOBS) as user_data:
|
with WriteUserData(UserDataFiles.JOBS) as user_data:
|
||||||
user_data = [x for x in user_data if x["uid"] != job.uid]
|
user_data = [x for x in user_data if x["uid"] != job.uid]
|
||||||
user_data.append(job.dict())
|
user_data.append(json.loads(job.json()))
|
||||||
|
|
||||||
return job
|
return job
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue