示例#1
0
def comment(message_id):
    form = FeedPostForm()
    message = Message.getMessage(message_id)
    if not message:
        abort(404)

    if message and message.parent:
        abort(404)

    if form.validate_on_submit() and session.get('username'):
        # process post
        from_user = User.getByName(session.get('username'))
        post = form.post.data

        # process write
        comment_ = Message(
            from_user=from_user.id,
            text=post,
            parent=message_id,
            message_type=MESSAGE_TYPE.get(COMMENT),
        )

        comment_.save_database()
        return redirect(url_for('feed_blueprint.comment', message_id=message_id))

    return render_template('feed/message.html',
                           message=message,
                           form=form
                           )
示例#2
0
def like(message_id):
    message = Message.getMessage(message_id)

    if not message:
        abort(404)

    if message and message.parent:
        abort(404)

    from_user = User.getByName(session.get('username'))

    # check if first like or not
    existing_like = Database.find('messages', {
                                                "parent": message_id,
                                                "from_user": from_user.id,
                                                "message_type": MESSAGE_TYPE.get(LIKE)
                                            }).count()

    if not existing_like:
        # write like
        like_ = Message(
            from_user=from_user.id,
            to_user=message.from_user,
            parent=message_id,
            message_type=MESSAGE_TYPE.get(LIKE)
        )

        like_.save_database()

    return redirect(url_for('feed_blueprint.comment', message_id=message.id))