Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | class Origin(BaseModel): | ||||
object_type: Final = "origin" | object_type: Final = "origin" | ||||
url = attr.ib(type=str, validator=type_validator()) | url = attr.ib(type=str, validator=type_validator()) | ||||
@attr.s(frozen=True) | @attr.s(frozen=True) | ||||
class OriginVisit(BaseModel): | class OriginVisit(BaseModel): | ||||
"""Represents a visit of an origin at a given point in time, by a | """Represents an origin visit with a given type at a given point in time, by a | ||||
SWH loader.""" | SWH loader.""" | ||||
object_type: Final = "origin_visit" | object_type: Final = "origin_visit" | ||||
origin = attr.ib(type=str, validator=type_validator()) | origin = attr.ib(type=str, validator=type_validator()) | ||||
date = attr.ib(type=datetime.datetime, validator=type_validator()) | date = attr.ib(type=datetime.datetime, validator=type_validator()) | ||||
type = attr.ib(type=str, validator=type_validator()) | type = attr.ib(type=str, validator=type_validator()) | ||||
"""Should not be set before calling 'origin_visit_add()'.""" | """Should not be set before calling 'origin_visit_add()'.""" | ||||
visit = attr.ib(type=Optional[int], validator=type_validator(), default=None) | visit = attr.ib(type=Optional[int], validator=type_validator(), default=None) | ||||
status = attr.ib(type=Optional[str], validator=type_validator(), default=None) | |||||
snapshot = attr.ib(type=Optional[Sha1Git], validator=type_validator(), default=None) | |||||
metadata = attr.ib( | |||||
type=Optional[Dict[str, object]], validator=type_validator(), default=None | |||||
) | |||||
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 | ||||
▲ Show 20 Lines • Show All 414 Lines • Show Last 20 Lines |