From 3f4677a976328661d70e386efd66c1c2d66fa740 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sun, 8 Jul 2018 23:25:51 -0400 Subject: [PATCH] Show comment posted time in the event's local time --- events/models/events.py | 11 +++++++++++ .../templates/get_together/events/show_event.html | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/events/models/events.py b/events/models/events.py index cf10e44..7f9e98b 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -106,6 +106,13 @@ class Event(models.Model): else: return settings.TIME_ZONE + def localize_datetime(self, val): + if val is not None: + event_tz = pytz.timezone(self.tz) + return timezone.make_naive(val.astimezone(event_tz), event_tz) + else: + return None + @property def local_start_time(self, val=None): if val is not None: @@ -290,6 +297,10 @@ class EventComment(MPTTModel): status = models.SmallIntegerField(choices=STATUSES, default=APPROVED, db_index=True) parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True, on_delete=models.SET_NULL) + @property + def local_created_time(self): + return self.event.localize_datetime(self.created_time) + def __str__(self): return '%s at %s' % (self.author, self.created_time) diff --git a/get_together/templates/get_together/events/show_event.html b/get_together/templates/get_together/events/show_event.html index b677a95..a2edb2a 100644 --- a/get_together/templates/get_together/events/show_event.html +++ b/get_together/templates/get_together/events/show_event.html @@ -228,7 +228,7 @@ {% for badge in node.author.user.account.badges.all %}{% endfor %} {{node.author}} - {{ node.created_time }} + {{ node.local_created_time }}