BookDataModel: fix absorbing data from array and partial date fields
This commit is contained in:
parent
7fb079cb43
commit
6f191acb27
1 changed files with 20 additions and 5 deletions
|
@ -155,12 +155,27 @@ class BookDataModel(ObjectMixin, BookWyrmModel):
|
||||||
for data_field in self._meta.get_fields():
|
for data_field in self._meta.get_fields():
|
||||||
if not hasattr(data_field, "activitypub_field"):
|
if not hasattr(data_field, "activitypub_field"):
|
||||||
continue
|
continue
|
||||||
data_value = getattr(other, data_field.name)
|
canonical_value = getattr(self, data_field.name)
|
||||||
if not data_value:
|
other_value = getattr(other, data_field.name)
|
||||||
|
if not other_value:
|
||||||
continue
|
continue
|
||||||
if not getattr(self, data_field.name):
|
if isinstance(data_field, fields.ArrayField):
|
||||||
setattr(self, data_field.name, data_value)
|
if new_values := list(set(other_value) - set(canonical_value)):
|
||||||
absorbed_fields[data_field.name] = data_value
|
# append at the end (in no particular order)
|
||||||
|
setattr(self, data_field.name, canonical_value + new_values)
|
||||||
|
absorbed_fields[data_field.name] = new_values
|
||||||
|
elif isinstance(data_field, fields.PartialDateField):
|
||||||
|
if (
|
||||||
|
(not canonical_value)
|
||||||
|
or (other_value.has_day and not canonical_value.has_day)
|
||||||
|
or (other_value.has_month and not canonical_value.has_month)
|
||||||
|
):
|
||||||
|
setattr(self, data_field.name, other_value)
|
||||||
|
absorbed_fields[data_field.name] = other_value
|
||||||
|
else:
|
||||||
|
if not canonical_value:
|
||||||
|
setattr(self, data_field.name, other_value)
|
||||||
|
absorbed_fields[data_field.name] = other_value
|
||||||
return absorbed_fields
|
return absorbed_fields
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue