aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/models.py
diff options
context:
space:
mode:
authorJessica Tallon <tsyesika@tsyesika.se>2015-11-23 17:27:32 +0000
committerJessica Tallon <tsyesika@tsyesika.se>2015-11-23 17:27:32 +0000
commit89068c2bdb367d9ab61d942248367279121fadca (patch)
treeb9a7f45529eb88c958b0e38b6dbeabb3f898a080 /mediagoblin/db/models.py
parentfb071a38fed27e3bf2406bba77ef8a2679a82963 (diff)
downloadmediagoblin-89068c2bdb367d9ab61d942248367279121fadca.tar.lz
mediagoblin-89068c2bdb367d9ab61d942248367279121fadca.tar.xz
mediagoblin-89068c2bdb367d9ab61d942248367279121fadca.zip
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.
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r--mediagoblin/db/models.py21
1 files 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,