Beispiel #1
0
def add_like(user_obj, user_checkpoint_obj):
    """
    Instantiates a new CheckpointLike record between a user and a Checkpoint,
    returns it if it already exists
    """

    checkpoint_obj = user_checkpoint_obj.checkpoint

    like_obj = get_like_w_attr(user_obj, checkpoint_obj)
    if not get_like_w_attr(user_obj, checkpoint_obj) is None:
        return like_obj

    from db import CheckpointLike, db

    like_obj = CheckpointLike()
    like_obj.checkpoint_id = user_checkpoint_obj.checkpoint.id
    like_obj.timestamp = datetime.datetime.now()
    like_obj.user_id = user_obj.id

    db.session.add(like_obj)
    db.session.commit()

    # add notification
    add_notification(NOTIFICATION_TYPE, user_obj, user_checkpoint_obj.user, like_obj.id, user_checkpoint_obj.id)

    return like_obj
Beispiel #2
0
def add_comment(user_obj, user_checkpoint_obj, comment_txt):
    """
    Instantiates a new comment for a user on a Checkpoint
    """
    
    from db import db, Comment
    
    checkpoint_obj = user_checkpoint_obj.checkpoint
    
    comment = Comment()
    comment.checkpoint_id = checkpoint_obj.id
    comment.user_id = user_obj.id
    comment.comment = comment_txt
    comment.timestamp = datetime.datetime.now() 

    db.session.add(comment)
    db.session.commit()
    
    add_notification(NOTIFICATION_TYPE, user_obj, user_checkpoint_obj.user, comment.id, user_checkpoint_obj.id)
    
    return comment
Beispiel #3
0
def add_share(user_from, user_to, user_checkpoint):
    """
    Adds a share record to the database (if it does not exists)
    """
    share = get_share_w_attr(user_from, user_to, user_checkpoint)
    
    if share is None:
    
        from db import db, Share
        now = datetime.datetime.now()
        
        share = Share()
        share.user_from_id = user_from.id
        share.user_to_id = user_to.id
        share.user_checkpoint_id = user_checkpoint.id
        share.timestamp = now
        
        db.session.add(share)
        db.session.commit()
    
    #add notification
    add_notification(NOTIFICATION_TYPE, user_from, user_to, share.id, user_checkpoint.id)
    
    return share