From 98596dd072597c5d9c474e882f57407817d049f5 Mon Sep 17 00:00:00 2001 From: xray7224 Date: Mon, 2 Sep 2013 19:25:24 +0100 Subject: [PATCH] Support for the comments endpoint --- mediagoblin/db/models.py | 12 ++++++++++-- mediagoblin/federation/routing.py | 5 +++++ mediagoblin/federation/views.py | 26 ++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 91efc0b6..4377f60f 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -455,7 +455,9 @@ class MediaEntry(Base, MediaEntryMixin): }, "fullImage":{ "url": request.host_url + self.original_url[1:], - } + }, + "published": self.created.isoformat(), + "updated": self.created.isoformat(), } if show_comments: @@ -465,7 +467,13 @@ class MediaEntry(Base, MediaEntryMixin): # we only want to include replies if there are any. context["replies"] = { "totalItems": total, - "items": comments + "items": comments, + "url": request.urlgen( + "mediagoblin.federation.object.comments", + objectType=self.objectType, + uuid=self.slug, + qualified=True + ), } return context diff --git a/mediagoblin/federation/routing.py b/mediagoblin/federation/routing.py index 9c870588..16184866 100644 --- a/mediagoblin/federation/routing.py +++ b/mediagoblin/federation/routing.py @@ -48,3 +48,8 @@ add_route( "/api//", "mediagoblin.federation.views:object" ) +add_route( + "mediagoblin.federation.object.comments", + "/api///comments", + "mediagoblin.federation.views:object_comments" + ) diff --git a/mediagoblin/federation/views.py b/mediagoblin/federation/views.py index 01082942..ab67e457 100644 --- a/mediagoblin/federation/views.py +++ b/mediagoblin/federation/views.py @@ -39,8 +39,8 @@ def inbox(request): """ Handles the user's inbox - /api/user//inbox """ raise NotImplemented("Yet to implement looking up user's inbox") -@oauth_required -def object(request): +#@oauth_required +def object(request, raw_obj=False): """ Lookup for a object type """ objectType = request.matchdict["objectType"] uuid = request.matchdict["uuid"] @@ -55,4 +55,26 @@ def object(request): error = "Can't find a {0} with ID = {1}".format(objectType, uuid) return json_response({"error": error}, status=404) + if raw_obj: + return media + return json_response(media.serialize(request)) + +def object_comments(request): + """ Looks up for the comments on a object """ + media = object(request, raw_obj=True) + response = media + if isinstance(response, MediaEntry): + comments = response.serialize(request) + comments = comments.get("replies", { + "totalItems": 0, + "items": [], + "url": request.urlgen( + "mediagoblin.federation.object.comments", + objectType=media.objectType, + uuid=media.slug, + qualified=True) + }) + response = json_response(comments) + + return response -- 2.25.1