Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | class OriginVisit(BaseModel): | ||||
visit = attr.ib(type=Optional[int], | visit = attr.ib(type=Optional[int], | ||||
validator=attr.validators.optional([])) | validator=attr.validators.optional([])) | ||||
"""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() | ||||
ov['date'] = str(self.date) | |||||
if ov['visit'] is None: | if ov['visit'] is None: | ||||
del ov['visit'] | del ov['visit'] | ||||
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() | |||||
date = d.pop('date') | |||||
return cls( | return cls( | ||||
origin=Origin.from_dict(d['origin']), | origin=Origin.from_dict(d.pop('origin')), | ||||
date=dateutil.parser.parse(d['date']), | date=(date | ||||
if isinstance(date, datetime.datetime) | |||||
else dateutil.parser.parse(date)), | |||||
visit=d.get('visit')) | visit=d.get('visit')) | ||||
class TargetType(Enum): | class TargetType(Enum): | ||||
"""The type of content pointed to by a snapshot branch. Usually a | """The type of content pointed to by a snapshot branch. Usually a | ||||
revision or an alias.""" | revision or an alias.""" | ||||
CONTENT = 'content' | CONTENT = 'content' | ||||
DIRECTORY = 'directory' | DIRECTORY = 'directory' | ||||
▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines |