From 695d925c9e7a766770e7964c71cc244581925758 Mon Sep 17 00:00:00 2001 From: Sam Clements Date: Fri, 1 Feb 2013 15:13:18 +0000 Subject: [PATCH] Post versioning (Part of #52) --- tentd/blueprints/posts.py | 13 ++-- tentd/documents/post.py | 99 ++++++++++++++++++++-------- tentd/flask.py | 4 ++ tentd/tests/blueprints/test_posts.py | 24 +++---- tentd/tests/documents/test_entity.py | 5 +- tentd/tests/documents/test_posts.py | 30 +++++++-- 6 files changed, 121 insertions(+), 54 deletions(-) diff --git a/tentd/blueprints/posts.py b/tentd/blueprints/posts.py index faada81..f090437 100644 --- a/tentd/blueprints/posts.py +++ b/tentd/blueprints/posts.py @@ -32,20 +32,17 @@ def post(self): TODO: Separate between apps creating a new post and a notification from a non-followed entity. """ - new_post = Post() - new_post.entity = g.entity - new_post.schema = request.json['schema'] - new_post.content = request.json['content'] - - new_post.save() + post = Post(entity=g.entity, schema=request.json.pop('schema')) + post.new_version(**request.json) + post.save() # TODO: Do this asynchronously? for to_notify in g.entity.followers: notification_link = follow.get_notification_link(to_notify) - requests.post(notification_link, data=jsonify(new_post.to_json())) + requests.post(notification_link, data=jsonify(post.to_json())) # TODO: Handle failed notifications somehow - return jsonify(new_post) + return jsonify(post) @posts.route_class('/', endpoint='post') class PostsView(MethodView): diff --git a/tentd/documents/post.py b/tentd/documents/post.py index 5606f71..667efbe 100644 --- a/tentd/documents/post.py +++ b/tentd/documents/post.py @@ -2,11 +2,46 @@ __all__ = ['Post'] +from datetime import datetime + from mongoengine import * from tentd.documents import db, EntityMixin from tentd.utils import time_to_string, json_attributes +class Version(db.EmbeddedDocument): + """A specific version of a Post + + TODO: 'mentions' + TODO: 'licenses' + TODO: 'attachments' + TODO: 'app' + TODO: 'views' + TODO: 'permissions' + """ + meta = { + 'allow_inheritance': False, + } + + #: The time the post was published + published_at = DateTimeField(default=datetime.now, required=True) + + #: The time we received the post from the publishing server + received_at = DateTimeField(default=datetime.now, required=True) + + #: The content of the post + content = DictField(required=True) + + def __repr__(self): + return '