Commit ac174693 authored by Javi Ng's avatar Javi Ng

fixed issue with dates and times being displayed in UTC

parent 8c9cd098
from django.http import HttpResponse
from .models import Announcement, Reaction
from datetime import datetime
from django.utils import timezone
def announcements(request):
......@@ -10,8 +11,9 @@ def announcements(request):
# build response string
response = "Widget's Announcement Board <br><br>" + "Announcements:"
for announcement in announcementList:
# string formatting for date-time
datetime = announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
# timezone conversion and string formatting for date-time
localdatetime = timezone.localtime(announcement.pub_datetime)
datetime = localdatetime.strftime("%m/%d/%Y, %I:%M %p")
# list of reactions for announcement
reactions = announcement.reaction_set.all()
......
from django.http import HttpResponse
from .models import ForumPost
from django.utils import timezone
def forum(request):
......@@ -10,24 +11,26 @@ def forum(request):
forum_view = "Widget's Forum <br> <br> Forum Posts:<br>"
for post in forum:
post_replies = post.reply_set.all()
localdatetime = timezone.localtime(post.pub_datetime)
forum_view += """
{} by {} posted {}: <br>
{} <br>
""".format(
post.title,
post.author,
post.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
localdatetime.strftime("%m/%d/%Y, %I:%M %p"),
post.body,
)
for reply in post_replies:
localdatetime = timezone.localtime(reply.pub_datetime)
if reply.forum == post:
forum_view += """
Reply by {} posted {}: <br>
{} <br>
""".format(
reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
localdatetime.strftime("%m/%d/%Y, %I:%M %p"),
reply.body,
)
forum_view += "<br>"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment