Show comment posted time in the event's local time

This commit is contained in:
Michael Hall 2018-07-08 23:25:51 -04:00
parent 6291ff26e9
commit 3f4677a976
2 changed files with 12 additions and 1 deletions

View file

@ -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)

View file

@ -228,7 +228,7 @@
<span class="gt-profile-badges">{% for badge in node.author.user.account.badges.all %}<img class="mr-0 gt-profile-badge" src="{{badge.img_url}}" title="{{badge.name}}" width="16px" height="16px">{% endfor %}</span>
<a href="{% url 'show-profile' node.author.id %}" title="{{node.author}}'s profile">{{node.author}}</a>
</div>
<span>{{ node.created_time }}</span>
<span>{{ node.local_created_time }}</span>
</div>
</div>
<div class="row">