Fix #1023 - Make timestamps in API timezone aware
authorJessica Tallon <jessica@megworld.co.uk>
Wed, 19 Nov 2014 10:49:42 +0000 (10:49 +0000)
committerJessica Tallon <jessica@megworld.co.uk>
Wed, 19 Nov 2014 10:49:53 +0000 (10:49 +0000)
mediagoblin/db/mixin.py
mediagoblin/db/models.py

index e8285e0cca6f71cdb85b56ab1378e3c7685523dd..7b1b119596f7a49cd21a893a72bf677dc200e23a 100644 (file)
@@ -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),
index 5a6a82404c4a6ecc70bd927be52e25cffcafee42..4e733fa3dabac32781e63954727ad6d5867fe39e 100644 (file)
@@ -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,
         }