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 django.http import HttpResponse
from .models import Announcement, Reaction from .models import Announcement, Reaction
from datetime import datetime from datetime import datetime
from django.utils import timezone
def announcements(request): def announcements(request):
...@@ -10,8 +11,9 @@ def announcements(request): ...@@ -10,8 +11,9 @@ def announcements(request):
# build response string # build response string
response = "Widget's Announcement Board <br><br>" + "Announcements:" response = "Widget's Announcement Board <br><br>" + "Announcements:"
for announcement in announcementList: for announcement in announcementList:
# string formatting for date-time # timezone conversion and string formatting for date-time
datetime = announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p") localdatetime = timezone.localtime(announcement.pub_datetime)
datetime = localdatetime.strftime("%m/%d/%Y, %I:%M %p")
# list of reactions for announcement # list of reactions for announcement
reactions = announcement.reaction_set.all() reactions = announcement.reaction_set.all()
......
from django.http import HttpResponse from django.http import HttpResponse
from .models import ForumPost from .models import ForumPost
from django.utils import timezone
def forum(request): def forum(request):
...@@ -10,24 +11,26 @@ def forum(request): ...@@ -10,24 +11,26 @@ def forum(request):
forum_view = "Widget's Forum <br> <br> Forum Posts:<br>" forum_view = "Widget's Forum <br> <br> Forum Posts:<br>"
for post in forum: for post in forum:
post_replies = post.reply_set.all() post_replies = post.reply_set.all()
localdatetime = timezone.localtime(post.pub_datetime)
forum_view += """ forum_view += """
{} by {} posted {}: <br> {} by {} posted {}: <br>
{} <br> {} <br>
""".format( """.format(
post.title, post.title,
post.author, post.author,
post.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"), localdatetime.strftime("%m/%d/%Y, %I:%M %p"),
post.body, post.body,
) )
for reply in post_replies: for reply in post_replies:
localdatetime = timezone.localtime(reply.pub_datetime)
if reply.forum == post: if reply.forum == post:
forum_view += """ forum_view += """
Reply by {} posted {}: <br> Reply by {} posted {}: <br>
{} <br> {} <br>
""".format( """.format(
reply.author, reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"), localdatetime.strftime("%m/%d/%Y, %I:%M %p"),
reply.body, reply.body,
) )
forum_view += "<br>" 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