diff --git a/bookwyrm/migrations/0185_auto_20231109_1657.py b/bookwyrm/migrations/0185_auto_20231109_1657.py index d8788b70d..eb3a5c56a 100644 --- a/bookwyrm/migrations/0185_auto_20231109_1657.py +++ b/bookwyrm/migrations/0185_auto_20231109_1657.py @@ -17,9 +17,9 @@ class Migration(migrations.Migration): field=models.CharField( blank=True, choices=[ - ("DAY", "Day seal"), - ("MONTH", "Month seal"), - ("YEAR", "Year seal"), + ("DAY", "Day prec."), + ("MONTH", "Month prec."), + ("YEAR", "Year prec."), ], editable=False, max_length=10, @@ -32,9 +32,9 @@ class Migration(migrations.Migration): field=models.CharField( blank=True, choices=[ - ("DAY", "Day seal"), - ("MONTH", "Month seal"), - ("YEAR", "Year seal"), + ("DAY", "Day prec."), + ("MONTH", "Month prec."), + ("YEAR", "Year prec."), ], editable=False, max_length=10, diff --git a/bookwyrm/utils/partial_date.py b/bookwyrm/utils/partial_date.py index cd2be8eb0..2bc97748c 100644 --- a/bookwyrm/utils/partial_date.py +++ b/bookwyrm/utils/partial_date.py @@ -159,13 +159,13 @@ class PartialDateDescriptor: Encapsulates the "two columns, one field" for PartialDateModel. """ - _SEAL_TYPES: dict[Type[_SetType], str] = { + _PRECISION_NAMES: dict[Type[_SetType], str] = { YearParts: "YEAR", MonthParts: "MONTH", PartialDate: "DAY", } - _DATE_CLASSES: dict[Any, Type[PartialDate]] = { + _PARTIAL_CLASSES: dict[Any, Type[PartialDate]] = { "YEAR": YearParts, "MONTH": MonthParts, } @@ -183,19 +183,19 @@ class PartialDateDescriptor: return value # use precision field to construct PartialDate. - seal_type = getattr(instance, self.precision_field, None) - date_class = self._DATE_CLASSES.get(seal_type, PartialDate) + precision = getattr(instance, self.precision_field, None) + date_class = self._PARTIAL_CLASSES.get(precision, PartialDate) return date_class.from_datetime(value) # FIXME: drop datetimes. def __set__(self, instance: models.Model, value: _SetType) -> None: """assign value, with precision where available""" try: - seal_type = self._SEAL_TYPES[value.__class__] + precision = self._PRECISION_NAMES[value.__class__] except KeyError: value = self.field.to_python(value) else: - setattr(instance, self.precision_field, seal_type) + setattr(instance, self.precision_field, precision) instance.__dict__[self.field.attname] = value @@ -212,7 +212,7 @@ class PartialDateDescriptor: @property def precision_choices(self) -> list[tuple[str, str]]: """valid options for precision database field""" - return [("DAY", "Day seal"), ("MONTH", "Month seal"), ("YEAR", "Year seal")] + return [("DAY", "Day prec."), ("MONTH", "Month prec."), ("YEAR", "Year prec.")] class PartialDateModel(models.DateTimeField): # type: ignore