Esempio n. 1
0
def update(id):
    """
    Update a user's Post
    """

    # Load the user's post out of the database
    post = Post.get_user_post(user, id)

    # Check if post is valid
    if not post:
        abort(403)

    # Check if random token correct if enabled
    if app.config['USE_RANDOM_TOKEN'] and \
            ('random_token' not in request.args or
            request.args.get('random_token') != post.random_token):
            abort(403)

    # Update the random token if the server is using random_token
    if app.config['USE_RANDOM_TOKEN'] and 'post[random_token]' in request.form:
        post.random_token = request.form['post[random_token]']

    # Update the `burn_after` date if `seconds_until_burn` is sent
    if 'post[seconds_until_burn]' in request.form:
        post.burn_after = datetime.today() + \
            timedelta(seconds=int(request.form['post[seconds_until_burn]']))

    # Update the Privly application if the `privly_application` string is sent
    if 'post[privly_application]' in request.form:
        post.privly_application = request.form['post[privly_application]']

    # Update `content` or `structured_content` if either is set
    if 'post[content]' in request.form:
        post.content = request.form['post[content]']
    if 'post[structured_content]' in request.form:
        post.structured_content = request.form['post[structured_content]']

    post.updated = datetime.now()

    # Save and update
    post.save()

    return helpers.jsonify(post)
Esempio n. 2
0
def update(id):
    """
    Update a user's Post
    """

    # Load the user's post out of the database
    post = Post.get_user_post(user, id)

    # Check if post is valid
    if not post:
        abort(403)

    # Check if random token correct if enabled
    if app.config['USE_RANDOM_TOKEN'] and \
            ('random_token' not in request.args or
            request.args.get('random_token') != post.random_token):
        abort(403)

    # Update the random token if the server is using random_token
    if app.config['USE_RANDOM_TOKEN'] and 'post[random_token]' in request.form:
        post.random_token = request.form['post[random_token]']

    # Update the `burn_after` date if `seconds_until_burn` is sent
    if 'post[seconds_until_burn]' in request.form:
        post.burn_after = datetime.today() + \
            timedelta(seconds=int(request.form['post[seconds_until_burn]']))

    # Update the Privly application if the `privly_application` string is sent
    if 'post[privly_application]' in request.form:
        post.privly_application = request.form['post[privly_application]']

    # Update `content` or `structured_content` if either is set
    if 'post[content]' in request.form:
        post.content = request.form['post[content]']
    if 'post[structured_content]' in request.form:
        post.structured_content = request.form['post[structured_content]']

    post.updated = datetime.now()

    # Save and update
    post.save()

    return helpers.jsonify(post)
Esempio n. 3
0
def destroy(id):
    """
    Deletes a user's Post
    """
    # Load the user's post out of the database
    post = Post.get_user_post(user, id)

    # Is the post invalid?
    if not post:
        abort(403)

    # Check if random token correct if enabled
    if app.config['USE_RANDOM_TOKEN'] and \
        ('random_token' not in request.args or
        request.args.get('random_token') != post.random_token):
        abort(403)

    post.delete()

    return helpers.jsonify(success=True)
Esempio n. 4
0
def destroy(id):
    """
    Deletes a user's Post
    """
    # Load the user's post out of the database
    post = Post.get_user_post(user, id)

    # Is the post invalid?
    if not post:
        abort(403)

    # Check if random token correct if enabled
    if app.config['USE_RANDOM_TOKEN'] and \
        ('random_token' not in request.args or
        request.args.get('random_token') != post.random_token):
        abort(403)

    post.delete()

    return helpers.jsonify(success=True)