From 45e687fcf8873a687a890f45f85bc75fb09502c5 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 19 Nov 2014 10:49:42 +0000 Subject: [PATCH] Fix #1023 - Make timestamps in API timezone aware --- mediagoblin/db/mixin.py | 7 +++++-- mediagoblin/db/models.py | 15 +++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index e8285e0c..7b1b1195 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -31,6 +31,7 @@ import uuid import re from datetime import datetime +from pytz import UTC from werkzeug.utils import cached_property from mediagoblin import mg_globals @@ -447,12 +448,14 @@ class ActivityMixin(object): return self.content def serialize(self, request): + published = UTC.localize(self.published) + updated = UTC.localize(self.updated) obj = { "id": self.id, "actor": self.get_actor.serialize(request), "verb": self.verb, - "published": self.published.isoformat(), - "updated": self.updated.isoformat(), + "published": published.isoformat(), + "updated": updated.isoformat(), "content": self.content, "url": self.get_url(request), "object": self.get_object.serialize(request), diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 5a6a8240..4e733fa3 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -42,6 +42,7 @@ from mediagoblin.tools.files import delete_media_files from mediagoblin.tools.common import import_component import six +from pytz import UTC _log = logging.getLogger(__name__) @@ -212,8 +213,10 @@ class User(Base, UserMixin): def serialize(self, request): + published = UTC.localize(self.created) user = { "id": "acct:{0}@{1}".format(self.username, request.host), + "oublished": published.isoformat(), "preferredUsername": self.username, "displayName": "{0}@{1}".format(self.username, request.host), "objectType": self.object_type, @@ -524,6 +527,8 @@ class MediaEntry(Base, MediaEntryMixin): def serialize(self, request, show_comments=True): """ Unserialize MediaEntry to object """ author = self.get_uploader + published = UTC.localize(self.created) + updated = UTC.localize(self.created) context = { "id": self.id, "author": author.serialize(request), @@ -535,8 +540,8 @@ class MediaEntry(Base, MediaEntryMixin): "fullImage":{ "url": request.host_url + self.original_url[1:], }, - "published": self.created.isoformat(), - "updated": self.created.isoformat(), + "published": published.isoformat(), + "updated": updated.isoformat(), "pump_io": { "shared": False, }, @@ -1209,11 +1214,13 @@ class Generator(Base): ) def serialize(self, request): + published = UTC.localize(self.published) + updated = UTC.localize(self.updated) return { "id": self.id, "displayName": self.name, - "published": self.published.isoformat(), - "updated": self.updated.isoformat(), + "published": published.isoformat(), + "updated": updated.isoformat(), "objectType": self.object_type, } -- 2.25.1