mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
SealedDate renames, pt. 1
• SealedDateField -> PartialDateModel • SealedDateFormField -> PartialDateFormField • SealedDateDescriptor -> PartialDateDescriptor
This commit is contained in:
parent
c120fa8c87
commit
0e4c5ed439
3 changed files with 13 additions and 12 deletions
|
@ -22,7 +22,7 @@ from bookwyrm.connectors import get_image
|
|||
from bookwyrm.utils.sanitizer import clean
|
||||
from bookwyrm.utils.sealed_date import (
|
||||
SealedDate,
|
||||
SealedDateField,
|
||||
PartialDateModel,
|
||||
from_partial_isoformat,
|
||||
)
|
||||
from bookwyrm.settings import MEDIA_FULL_URL
|
||||
|
@ -553,7 +553,7 @@ class DateTimeField(ActivitypubFieldMixin, models.DateTimeField):
|
|||
return None
|
||||
|
||||
|
||||
class PartialDateField(ActivitypubFieldMixin, SealedDateField):
|
||||
class PartialDateField(ActivitypubFieldMixin, PartialDateModel):
|
||||
"""activitypub-aware partial date field"""
|
||||
|
||||
def field_to_activity(self, value) -> str:
|
||||
|
|
|
@ -98,14 +98,14 @@ class SealedDateTest(unittest.TestCase):
|
|||
)
|
||||
|
||||
|
||||
class SealedDateFormFieldTest(unittest.TestCase):
|
||||
class PartialDateFormFieldTest(unittest.TestCase):
|
||||
"""test form support for SealedDate objects"""
|
||||
|
||||
# pylint: disable=missing-function-docstring
|
||||
|
||||
def setUp(self):
|
||||
self._dt = datetime.datetime(2022, 11, 21, 17, 1, 0, tzinfo=timezone.utc)
|
||||
self.field = sealed_date.SealedDateFormField()
|
||||
self.field = sealed_date.PartialDateFormField()
|
||||
|
||||
def test_prepare_value(self):
|
||||
sealed = sealed_date.SealedDate.from_datetime(self._dt)
|
||||
|
|
|
@ -16,6 +16,7 @@ from django.utils import timezone
|
|||
|
||||
__all__ = [
|
||||
"SealedDate",
|
||||
"PartialDateModel",
|
||||
"from_partial_isoformat",
|
||||
]
|
||||
|
||||
|
@ -25,7 +26,7 @@ _westmost_tz = timezone.get_fixed_timezone(timedelta(hours=-12))
|
|||
Sealed = TypeVar("Sealed", bound="SealedDate") # TODO: use Self in Python >= 3.11
|
||||
|
||||
# TODO: migrate SealedDate: `datetime` => `date`
|
||||
# TODO: migrate SealedDateField: `DateTimeField` => `DateField`
|
||||
# TODO: migrate PartialDateModel: `DateTimeField` => `DateField`
|
||||
|
||||
|
||||
class SealedDate(datetime):
|
||||
|
@ -111,7 +112,7 @@ def from_partial_isoformat(value: str) -> SealedDate:
|
|||
return SealedDate.from_date_parts(year, month, day)
|
||||
|
||||
|
||||
class SealedDateFormField(DateField):
|
||||
class PartialDateFormField(DateField):
|
||||
"""date form field with support for SealedDate"""
|
||||
|
||||
def prepare_value(self, value: Any) -> str:
|
||||
|
@ -152,10 +153,10 @@ _SetType = datetime
|
|||
_GetType = Optional[SealedDate]
|
||||
|
||||
|
||||
class SealedDateDescriptor:
|
||||
"""descriptor for SealedDateField.
|
||||
class PartialDateDescriptor:
|
||||
"""descriptor for PartialDateModel.
|
||||
|
||||
Encapsulates the "two columns, one field" for SealedDateField.
|
||||
Encapsulates the "two columns, one field" for PartialDateModel.
|
||||
"""
|
||||
|
||||
_SEAL_TYPES: dict[Type[_SetType], str] = {
|
||||
|
@ -214,13 +215,13 @@ class SealedDateDescriptor:
|
|||
return [("DAY", "Day seal"), ("MONTH", "Month seal"), ("YEAR", "Year seal")]
|
||||
|
||||
|
||||
class SealedDateField(models.DateTimeField): # type: ignore
|
||||
class PartialDateModel(models.DateTimeField): # type: ignore
|
||||
"""a date field for Django models, using SealedDate as values"""
|
||||
|
||||
descriptor_class = SealedDateDescriptor
|
||||
descriptor_class = PartialDateDescriptor
|
||||
|
||||
def formfield(self, **kwargs): # type: ignore
|
||||
kwargs.setdefault("form_class", SealedDateFormField)
|
||||
kwargs.setdefault("form_class", PartialDateFormField)
|
||||
return super().formfield(**kwargs)
|
||||
|
||||
# pylint: disable-next=arguments-renamed
|
||||
|
|
Loading…
Reference in a new issue