Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | class OriginVisit(BaseModel): | ||||
def to_dict(self): | def to_dict(self): | ||||
"""Serializes the date as a string and omits the visit id if it is | """Serializes the date as a string and omits the visit id if it is | ||||
`None`.""" | `None`.""" | ||||
ov = super().to_dict() | ov = super().to_dict() | ||||
if ov["visit"] is None: | if ov["visit"] is None: | ||||
del ov["visit"] | del ov["visit"] | ||||
return ov | return ov | ||||
@classmethod | |||||
def from_dict(cls, d): | |||||
"""Parses the date from a string, and accepts missing visit ids.""" | |||||
if isinstance(d["date"], str): | |||||
d = d.copy() | |||||
d["date"] = dateutil.parser.parse(d["date"]) | |||||
return super().from_dict(d) | |||||
@attr.s(frozen=True) | @attr.s(frozen=True) | ||||
class OriginVisitStatus(BaseModel): | class OriginVisitStatus(BaseModel): | ||||
"""Represents a visit update of an origin at a given point in time. | """Represents a visit update of an origin at a given point in time. | ||||
""" | """ | ||||
origin = attr.ib(type=str, validator=type_validator()) | origin = attr.ib(type=str, validator=type_validator()) | ||||
▲ Show 20 Lines • Show All 387 Lines • Show Last 20 Lines |