Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | def check_author(self, attribute, value): | ||||
"""If the author is `None`, checks the date is `None` too.""" | """If the author is `None`, checks the date is `None` too.""" | ||||
if self.author is None and self.date is not None: | if self.author is None and self.date is not None: | ||||
raise ValueError('release date must be None if author is None.') | raise ValueError('release date must be None if author is None.') | ||||
def to_dict(self): | def to_dict(self): | ||||
rel = attr.asdict(self) | rel = attr.asdict(self) | ||||
rel['date'] = self.date.to_dict() if self.date is not None else None | rel['date'] = self.date.to_dict() if self.date is not None else None | ||||
rel['target_type'] = rel['target_type'].value | rel['target_type'] = rel['target_type'].value | ||||
if rel['metadata'] is None: | |||||
del rel['metadata'] | |||||
return rel | return rel | ||||
@classmethod | @classmethod | ||||
def from_dict(cls, d): | def from_dict(cls, d): | ||||
d = d.copy() | d = d.copy() | ||||
if d.get('author'): | if d.get('author'): | ||||
d['author'] = Person.from_dict(d['author']) | d['author'] = Person.from_dict(d['author']) | ||||
if d.get('date'): | if d.get('date'): | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |