Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | class OriginVisit(BaseModel): | ||||
"""Should not be set before calling 'origin_visit_add()'.""" | """Should not be set before calling 'origin_visit_add()'.""" | ||||
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'] | ||||
ov['origin'] = self.origin.to_dict() | |||||
return ov | return ov | ||||
@classmethod | @classmethod | ||||
def from_dict(cls, d): | def from_dict(cls, d): | ||||
"""Parses the date from a string, and accepts missing visit ids.""" | """Parses the date from a string, and accepts missing visit ids.""" | ||||
d = d.copy() | d = d.copy() | ||||
date = d.pop('date') | date = d.pop('date') | ||||
return cls( | return cls( | ||||
▲ Show 20 Lines • Show All 241 Lines • Show Last 20 Lines |