예제 #1
0
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
예제 #2
0
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
예제 #3
0
def comment(user_obj, comment_str, obj_id, coll_name):
    """
    Shortcut function for instantiating and commenting
    on an arbitrary object

    :param user_obj:
    :param comment_str:
    :param obj_id:
    :param coll_name:
    :return comment_obj_id:
    """
    comment_obj = Comment()
    comment_obj.user_id = user_obj._id
    comment_obj.comment = comment_str
    comment_obj.coll_name = coll_name
    comment_obj.obj_id = obj_id
    return save(comment_obj)
예제 #4
0
def save(comment_obj):
    """
    Saves a comment object on the database

    :param comment_obj:
    """
    id = Comment.collection().insert(comment_obj.serialize())
    return id