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
This commit is contained in:
parent
1ad106d05d
commit
7da4921d32
|
@ -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
|
||||
|
|
|
@ -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 %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -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", {
|
||||
|
|
Loading…
Reference in New Issue