From 7da4921d32bfbc6fc79766bc0ac3db8c484f06f1 Mon Sep 17 00:00:00 2001 From: Matthias Portzel Date: Wed, 12 Jan 2022 11:08:56 -0500 Subject: [PATCH] Fix bugs around editing and time * Pre-fill the timezone with the offset in hours (correct), instead of minutes, like the DB stores * Only change the timezone in JS if you're not editing * Redirect back to a Thought after editing it --- main/models.py | 5 ++++- main/templates/whispermaphone/post.html | 2 ++ main/views.py | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/main/models.py b/main/models.py index c808725..9b32837 100644 --- a/main/models.py +++ b/main/models.py @@ -3,8 +3,8 @@ import uuid import magic -from django.db import models from django import forms +from django.db import models from django.utils import timezone from django.utils.text import normalize_newlines from django.core.exceptions import ValidationError @@ -37,6 +37,9 @@ class Thought(models.Model): offset_hours = "+" + str(offset_hours) return str(offset_hours) + def get_absolute_url(self): + return f"/?show={str(self.uuid)}" + # Honestly I'm so sick of this problem that writing out a comment here to explain why it is necessary is beyond me. # I'm calling this CharField and not MySpecialLineNormalizingCharField diff --git a/main/templates/whispermaphone/post.html b/main/templates/whispermaphone/post.html index b68b78f..7581daf 100644 --- a/main/templates/whispermaphone/post.html +++ b/main/templates/whispermaphone/post.html @@ -129,6 +129,8 @@ timezoneOffsetEl.setAttribute("type", "hidden"); // The text box needs to be in hours, UTC offset (e.g. -8) // .getTimezoneOffset() returns minutes behind UTC + {% if not editing %} timezoneOffsetEl.value = -(new Date()).getTimezoneOffset() / 60; + {% endif %} {% endblock %} diff --git a/main/views.py b/main/views.py index f099b82..484ae0c 100644 --- a/main/views.py +++ b/main/views.py @@ -86,6 +86,7 @@ def post(request): editing = request.GET.get("editing", None) try: editing_thought = Thought.objects.get(uuid=editing) + editing_thought.timezone_offset = - editing_thought.timezone_offset / 60 except Thought.DoesNotExist: editing_thought = None @@ -151,6 +152,8 @@ def post(request): thought.save() # Redirect to the same page, so that we make a GET request to /post + if editing_thought: + return redirect(editing_thought) return redirect("post") return render(request, "whispermaphone/post.html", {