aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db
diff options
context:
space:
mode:
authorJessica Tallon <jessica@megworld.co.uk>2014-07-16 17:59:03 +0100
committerJessica Tallon <jessica@megworld.co.uk>2014-07-22 23:13:16 +0100
commitd8f55f2b412507d4c75ebd249a824fdaee66c6dd (patch)
tree1d4adf0e30dd636528302f9256dd8f65c3c36f53 /mediagoblin/db
parent0679545f192d8d45a4d98c65bf731e236d73b418 (diff)
downloadmediagoblin-d8f55f2b412507d4c75ebd249a824fdaee66c6dd.tar.lz
mediagoblin-d8f55f2b412507d4c75ebd249a824fdaee66c6dd.tar.xz
mediagoblin-d8f55f2b412507d4c75ebd249a824fdaee66c6dd.zip
Add unseralize for API objects
Diffstat (limited to 'mediagoblin/db')
-rw-r--r--mediagoblin/db/models.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index 0507161e..8ea16b80 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -499,6 +499,19 @@ class MediaEntry(Base, MediaEntryMixin):
return context
+ def unserialize(self, data):
+ """ Takes API objects and unserializes on existing MediaEntry """
+ if "displayName" in data:
+ self.title = data["displayName"]
+
+ if "content" in data:
+ self.description = data["content"]
+
+ if "license" in data:
+ self.license = data["license"]
+
+ return True
+
class FileKeynames(Base):
"""
keywords for various places.
@@ -658,6 +671,24 @@ class MediaComment(Base, MediaCommentMixin):
return context
+ def unserialize(self, data):
+ """ Takes API objects and unserializes on existing comment """
+ # Do initial checks to verify the object is correct
+ required_attributes = ["content", "inReplyTo"]
+ for attr in required_attributes:
+ if attr not in data:
+ return False
+
+ # Validate inReplyTo has ID
+ if "id" not in data["inReplyTo"]:
+ return False
+
+ self.media_entry = data["inReplyTo"]["id"]
+ self.content = data["content"]
+ return True
+
+
+
class Collection(Base, CollectionMixin):
"""An 'album' or 'set' of media by a user.