예제 #1
0
def update(id):
    post = Post.getOneById(id)
    post['body'] = ','.join(post['body'])
    tags = list(Post.getAllTags())
    for i in range(len(tags)):
        tags[i] = tags[i]['tag']
    if request.method == 'POST':
        title = request.form['title']
        description = request.form['description']
        body = request.form['body']
        tag = request.form['tag']
        videoURL = request.form['videoURL']
        status = "No Good"
        message = "Error: item not inserted"

        if not title or not description or not tag or (not body
                                                       and not videoURL):
            return {"status": status, "message": message}

        try:
            post_updated = Post.update(id, title, description, body, tag,
                                       videoURL)
            if post_updated:
                status = "OK"
                message = "Success!!!"
            return jsonify({
                "status": status,
                "message": message,
                "body": body,
                "tag": tag,
                "videoURL": videoURL,
                "timestamp": datetime.datetime.now()
            })
        except PostErrors.PostError as e:
            return e.message
    else:
        return render_template('posts/edit.html', post=post, tags=tags)
예제 #2
0
def view(id):
    post = Post.getOneById(id)
    if post:
        css = [{'prefix': 'css/compiled/', 'name': 'resource'}]
        return render_template('resource.html', post=post, css=css)