edit_readthrough: set start_date/finish_date iff present in request

Fixes: #3164
This commit is contained in:
Adeodato Simó 2024-07-28 05:57:57 -03:00
parent 812221456b
commit 041f2fc413
2 changed files with 6 additions and 9 deletions

View file

@ -1,6 +1,5 @@
""" test for app action functionality """ """ test for app action functionality """
import json import json
from unittest import expectedFailure
from unittest.mock import patch from unittest.mock import patch
import dateutil import dateutil
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
@ -170,7 +169,6 @@ class StatusViews(TestCase):
self.assertEqual(status.rating, 4.0) self.assertEqual(status.rating, 4.0)
self.assertIsNone(status.edited_date) self.assertIsNone(status.edited_date)
@expectedFailure # https://github.com/bookwyrm-social/bookwyrm/issues/3164
def test_create_status_progress(self, *_): def test_create_status_progress(self, *_):
"""create a status that updates a readthrough""" """create a status that updates a readthrough"""
start_date = timezone.make_aware(dateutil.parser.parse("2024-07-27")) start_date = timezone.make_aware(dateutil.parser.parse("2024-07-27"))
@ -200,7 +198,7 @@ class StatusViews(TestCase):
readthrough.refresh_from_db() readthrough.refresh_from_db()
self.assertEqual(1, readthrough.progress) self.assertEqual(1, readthrough.progress)
self.assertEqual(start_date, readthrough.start_date) self.assertEqual(start_date, readthrough.start_date) # not overwritten
def test_create_status_wrong_user(self, *_): def test_create_status_wrong_user(self, *_):
"""You can't compose statuses for someone else""" """You can't compose statuses for someone else"""

View file

@ -201,12 +201,11 @@ def edit_readthrough(request):
# TODO: remove this, it duplicates the code in the ReadThrough view # TODO: remove this, it duplicates the code in the ReadThrough view
readthrough = get_object_or_404(models.ReadThrough, id=request.POST.get("id")) readthrough = get_object_or_404(models.ReadThrough, id=request.POST.get("id"))
readthrough.start_date = load_date_in_user_tz_as_utc( if start_date := request.POST.get("start_date"):
request.POST.get("start_date"), request.user readthrough.start_date = load_date_in_user_tz_as_utc(start_date, request.user)
)
readthrough.finish_date = load_date_in_user_tz_as_utc( if finish_date := request.POST.get("finish_date"):
request.POST.get("finish_date"), request.user readthrough.finish_date = load_date_in_user_tz_as_utc(finish_date, request.user)
)
progress = request.POST.get("progress") progress = request.POST.get("progress")
try: try: