# pass through commit=False/True in kwargs
super(MediaEntry, self).delete(**kwargs)
+ @property
+ def objectType(self):
+ """ Converts media_type to pump-like type - don't use internally """
+ return self.media_type.split(".")[-1]
+
+ def serialize(self, request):
+ """ Unserialize MediaEntry to object """
+ author = self.get_uploader
+ url = request.urlgen(
+ "mediagoblin.user_pages.media_home",
+ user=author.username,
+ media=self.slug,
+ qualified=True
+ )
+
+ id = request.urlgen(
+ "mediagoblin.federation.object",
+ objectType=self.objectType,
+ uuid=self.uuid,
+ qualified=True
+ )
+
+ context = {
+ "id": id,
+ "author": author.serialize(request),
+ "displayName": self.title,
+ "objectType": self.objectType,
+ "url": url,
+ }
+ return context
+
class FileKeynames(Base):
"""
keywords for various places.
cascade="all, delete-orphan"))
+ def serialize(self, request):
+ """ Unserialize to python dictionary for API """
+ media = MediaEntry.query.filter_by(self.media_entry).first()
+ context = {
+ "objectType": "comment",
+ "content": self.content,
+ "inReplyTo": media.unserialize(request),
+ "author": self.get_author.unserialize(request)
+ }
+
+ return context
+
class Collection(Base, CollectionMixin):
"""An 'album' or 'set' of media by a user.
""" Handles the user's inbox - /api/user/<username>/inbox """
raise NotImplemented("Yet to implement looking up user's inbox")
-def image_object(request, media):
- """ Return image object - /api/image/<uuid> """
- author = media.get_uploader
- url = request.urlgen(
- "mediagoblin.user_pages.media_home",
- user=author.username,
- media=media.slug,
- qualified=True
- )
-
- context = {
- "author": author.serialize(request),
- "displayName": media.title,
- "objectType": "image",
- "url": url,
- }
-
- return json_response(context)
-
@oauth_required
def object(request):
""" Lookup for a object type """
error = "Can't find a {0} with ID = {1}".format(objectType, uuid)
return json_response({"error": error}, status=404)
- if objectType == "image":
- return image_object(request, media)
+ return json_response(media.serialize(request))