def save(comment_obj): """ Saves a comment object on the database :param comment_obj: """ id = Comment.collection().insert(comment_obj.serialize()) return id
def get(comment_id): """ Return the comment object given the id :param comment_id: """ dic = Comment.collection().find_one({ "_id": coerce_bson_id(comment_id) }) return Comment.unserialize(dic) if dic is not None else None
def get_all(obj_id, collection_name, limit=None): """ Get all comments on a given object :param obj_id: :param collection_name: :param limit: """ comments = Comment.collection().find({ "obj_id": str(obj_id), "coll_name": collection_name }).sort("timestamp_utc", pymongo.DESCENDING) comment_obj_lis = [Comment.unserialize(x) for x in comments] return comment_obj_lis