Merge pull request #2316 from redshiftss/bugfix/reading-status-future

Make it so that finishing a book cannot happen in the future
This commit is contained in:
Mouse Reeve 2022-10-14 12:17:42 -07:00 committed by GitHub
commit b02ad2ec68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
""" using django model forms """
import datetime
from django import forms
from django.forms import widgets
from django.utils.translation import gettext_lazy as _
@ -7,7 +8,6 @@ from bookwyrm import models
from bookwyrm.models.user import FeedFilterChoices
from .custom_form import CustomForm
# pylint: disable=missing-class-docstring
class FeedStatusTypesForm(CustomForm):
class Meta:
@ -58,6 +58,21 @@ class ReadThroughForm(CustomForm):
self.add_error(
"stopped_date", _("Reading stopped date cannot be before start date.")
)
current_time = datetime.datetime.now()
if (
stopped_date is not None
and current_time.timestamp() < stopped_date.timestamp()
):
self.add_error(
"stopped_date", _("Reading stopped date cannot be in the future.")
)
if (
finish_date is not None
and current_time.timestamp() < finish_date.timestamp()
):
self.add_error(
"finish_date", _("Reading finished date cannot be in the future.")
)
class Meta:
model = models.ReadThrough