Skip to content
Snippets Groups Projects
Verified Commit f82cf376 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Fix getting date

parent 30d0e737
No related branches found
No related tags found
1 merge request!176Resolve "DateTimeField Announcement.valid_from received a naive datetime"
Pipeline #998 failed
......@@ -166,9 +166,9 @@ class AnnouncementForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
if "instance" not in kwargs:
kwargs["initial"] = {
"valid_from_date": timezone.datetime.now(),
"valid_from_date": timezone.now(),
"valid_from_time": time(0, 0),
"valid_until_date": timezone.datetime.now(),
"valid_until_date": timezone.now(),
"valid_until_time": time(23, 59),
}
else:
......@@ -197,7 +197,7 @@ class AnnouncementForm(forms.ModelForm):
valid_from = timezone.datetime.combine(from_date, from_time)
valid_until = timezone.datetime.combine(until_date, until_time)
if valid_until < timezone.datetime.now():
if valid_until < timezone.now():
raise ValidationError(
_("You are not allowed to create announcements which are only valid in the past.")
)
......
......@@ -283,7 +283,7 @@ class Announcement(ExtensibleModel):
link = models.URLField(blank=True, verbose_name=_("Link"))
valid_from = models.DateTimeField(
verbose_name=_("Date and time from when to show"), default=timezone.datetime.now
verbose_name=_("Date and time from when to show"), default=timezone.now
)
valid_until = models.DateTimeField(
verbose_name=_("Date and time until when to show"),
......@@ -308,7 +308,7 @@ class Announcement(ExtensibleModel):
@classmethod
def for_person_at_time(cls, person: Person, when: Optional[datetime] = None) -> List:
""" Get all announcements for one person at a certain time """
when = when or timezone.datetime.now()
when = when or timezone.now()
# Get announcements by time
announcements = cls.objects.filter(valid_from__lte=when, valid_until__gte=when)
......
......@@ -154,4 +154,4 @@ def school_information_processor(request: HttpRequest) -> dict:
def now_tomorrow() -> datetime:
""" Return current time tomorrow """
return timezone.datetime.now() + timedelta(days=1)
return timezone.now() + timedelta(days=1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment