Fix #1023 - Make timestamps in API timezone aware
This commit is contained in:
parent
c511fc5e5e
commit
45e687fcf8
@ -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),
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user