Fix User and MediaEntry serialize and add serialize to models which need it
authorJessica Tallon <jessica@megworld.co.uk>
Tue, 4 Nov 2014 10:39:01 +0000 (10:39 +0000)
committerJessica Tallon <jessica@megworld.co.uk>
Tue, 4 Nov 2014 10:42:31 +0000 (10:42 +0000)
mediagoblin/db/models.py

index 294200d83bb87ed136cb5c4187d6f773296001da..5a6a82404c4a6ecc70bd927be52e25cffcafee42 100644 (file)
@@ -251,7 +251,7 @@ class User(Base, UserMixin):
         if self.url:
             user.update({"url": self.url})
         if self.location:
-            user.update({"location": self.get_location.seralize(request)})
+            user.update({"location": self.get_location.serialize(request)})
 
         return user
 
@@ -528,7 +528,7 @@ class MediaEntry(Base, MediaEntryMixin):
             "id": self.id,
             "author": author.serialize(request),
             "objectType": self.object_type,
-            "url": self.url_for_self(request.urlgen),
+            "url": self.url_for_self(request.urlgen, qualified=True),
             "image": {
                 "url": request.host_url + self.thumb_url[1:],
             },
@@ -844,6 +844,18 @@ class Collection(Base, CollectionMixin):
             creator=self.creator,
             title=safe_title)
 
+    def serialize(self, request):
+        # Get all serialized output in a list
+        items = []
+        for item in self.get_collection_items():
+            items.append(item.serialize(request))
+
+        return {
+            "totalItems": self.items,
+            "url": self.url_for_self(request.urlgen, qualified=True),
+            "items": items,
+        }
+
 
 class CollectionItem(Base, CollectionItemMixin):
     __tablename__ = "core__collection_items"
@@ -880,6 +892,9 @@ class CollectionItem(Base, CollectionItemMixin):
             collection=self.collection,
             entry=self.media_entry)
 
+    def serialize(self, request):
+        return self.get_media_entry.serialize(request)
+
 
 class ProcessingMetaData(Base):
     __tablename__ = 'core__processing_metadata'