Remove last references to "seal" in partial_date.py and migration

This commit is contained in:
Adeodato Simó 2023-11-09 13:49:52 -03:00
parent edfa6b18a1
commit be9d92b1c2
No known key found for this signature in database
GPG key ID: CDF447845F1A986F
2 changed files with 13 additions and 13 deletions

View file

@ -17,9 +17,9 @@ class Migration(migrations.Migration):
field=models.CharField( field=models.CharField(
blank=True, blank=True,
choices=[ choices=[
("DAY", "Day seal"), ("DAY", "Day prec."),
("MONTH", "Month seal"), ("MONTH", "Month prec."),
("YEAR", "Year seal"), ("YEAR", "Year prec."),
], ],
editable=False, editable=False,
max_length=10, max_length=10,
@ -32,9 +32,9 @@ class Migration(migrations.Migration):
field=models.CharField( field=models.CharField(
blank=True, blank=True,
choices=[ choices=[
("DAY", "Day seal"), ("DAY", "Day prec."),
("MONTH", "Month seal"), ("MONTH", "Month prec."),
("YEAR", "Year seal"), ("YEAR", "Year prec."),
], ],
editable=False, editable=False,
max_length=10, max_length=10,

View file

@ -159,13 +159,13 @@ class PartialDateDescriptor:
Encapsulates the "two columns, one field" for PartialDateModel. Encapsulates the "two columns, one field" for PartialDateModel.
""" """
_SEAL_TYPES: dict[Type[_SetType], str] = { _PRECISION_NAMES: dict[Type[_SetType], str] = {
YearParts: "YEAR", YearParts: "YEAR",
MonthParts: "MONTH", MonthParts: "MONTH",
PartialDate: "DAY", PartialDate: "DAY",
} }
_DATE_CLASSES: dict[Any, Type[PartialDate]] = { _PARTIAL_CLASSES: dict[Any, Type[PartialDate]] = {
"YEAR": YearParts, "YEAR": YearParts,
"MONTH": MonthParts, "MONTH": MonthParts,
} }
@ -183,19 +183,19 @@ class PartialDateDescriptor:
return value return value
# use precision field to construct PartialDate. # use precision field to construct PartialDate.
seal_type = getattr(instance, self.precision_field, None) precision = getattr(instance, self.precision_field, None)
date_class = self._DATE_CLASSES.get(seal_type, PartialDate) date_class = self._PARTIAL_CLASSES.get(precision, PartialDate)
return date_class.from_datetime(value) # FIXME: drop datetimes. return date_class.from_datetime(value) # FIXME: drop datetimes.
def __set__(self, instance: models.Model, value: _SetType) -> None: def __set__(self, instance: models.Model, value: _SetType) -> None:
"""assign value, with precision where available""" """assign value, with precision where available"""
try: try:
seal_type = self._SEAL_TYPES[value.__class__] precision = self._PRECISION_NAMES[value.__class__]
except KeyError: except KeyError:
value = self.field.to_python(value) value = self.field.to_python(value)
else: else:
setattr(instance, self.precision_field, seal_type) setattr(instance, self.precision_field, precision)
instance.__dict__[self.field.attname] = value instance.__dict__[self.field.attname] = value
@ -212,7 +212,7 @@ class PartialDateDescriptor:
@property @property
def precision_choices(self) -> list[tuple[str, str]]: def precision_choices(self) -> list[tuple[str, str]]:
"""valid options for precision database field""" """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 class PartialDateModel(models.DateTimeField): # type: ignore