From 89068c2bdb367d9ab61d942248367279121fadca Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 23 Nov 2015 17:27:32 +0000 Subject: [PATCH] Fix #5354 & #5355 - Fix Graveyard.serialize Graveyard.serialize raised an exception as the deleted datetime objects where not being converted to strings for json encoding. It also didn't deal with the case when there was an actor, it now calls the actor's serialize method as it should. Thanks to Alyeph who provided the patches for both of these. --- mediagoblin/db/models.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 430d081d..c380c918 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -389,11 +389,14 @@ class LocalUser(User): 'admin' if self.has_privilege(u'admin') else 'user', self.username) + def get_public_id(self, host): + return "acct:{0}@{1}".format(self.username, host) + def serialize(self, request): user = { - "id": "acct:{0}@{1}".format(self.username, request.host), + "id": self.get_public_id(request.host), "preferredUsername": self.username, - "displayName": "{0}@{1}".format(self.username, request.host), + "displayName": self.get_public_id(request.host).split(":", 1)[1], "links": { "self": { "href": request.urlgen( @@ -1563,15 +1566,19 @@ class Graveyard(Base): ) def serialize(self, request): - return { + deleted = UTC.localize(self.deleted).isoformat() + context = { "id": self.public_id, "objectType": self.object_type, - "actor": self.actor(), - "published": self.deleted, - "updated": self.deleted, - "deleted": self.deleted + "published": deleted, + "updated": deleted, + "deleted": deleted, } + if self.actor_id is not None: + context["actor"] = self.actor().serialize(request) + + return context MODELS = [ LocalUser, RemoteUser, User, MediaEntry, Tag, MediaTag, Comment, TextComment, Collection, CollectionItem, MediaFile, FileKeynames, MediaAttachmentFile, -- 2.25.1