Exemple #1
0
def new():
    if request.method == 'POST':
        title = request.form['title']
        description = request.form['description']
        body = request.form['body'].strip()
        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_added = Post.new(title, description, body, tag, videoURL)
            if post_added:
                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:
        tags = list(Post.getAllTags())
        for i in range(len(tags)):
            tags[i] = tags[i]['tag']
        return render_template('posts/new.html', tags=tags)
Exemple #2
0
def all(tag):
    if tag is not None:
        posts = list(reversed(list(Post.getManyByTag(tag))))
    else:
        tag = 'all'
        posts = list(reversed(list(Post.getAll())))
    num_pages = math.ceil(len(posts) / POST_CONSTANTS.MAX_RESOURCES_PER_PAGE)
    max_pages_shown = POST_CONSTANTS.MAX_PAGES_SHOWN if num_pages >= POST_CONSTANTS.MAX_PAGES_SHOWN else num_pages
    page = 1
    if 'page' in request.args.keys():
        if int(request.args['page']) <= num_pages:
            page = int(request.args['page'])
        else:
            page = num_pages
    first_index = (page - 1) * POST_CONSTANTS.MAX_RESOURCES_PER_PAGE
    last_index = page * POST_CONSTANTS.MAX_RESOURCES_PER_PAGE
    posts = posts[first_index:last_index]
    tags = list(Post.getAllTags())
    for i in range(len(tags)):
        tags[i] = tags[i]['tag'].capitalize()
    css = [{'prefix': 'css/compiled/', 'name': 'resources'}]
    return render_template('resources.html',
                           posts=posts,
                           tags=tags,
                           css=css,
                           selectedTag=tag,
                           page=page,
                           max_per_page=POST_CONSTANTS.MAX_RESOURCES_PER_PAGE,
                           num_pages=num_pages,
                           max_pages_shown=max_pages_shown)
Exemple #3
0
def profile(user):
    user_id = user['_id']
    email = session['email']
    posts = reversed(list(Post.getAllByUserId(user_id)))
    # posts = reversed(list(Post.getAll()))
    tags = list(Post.getAllTags())
    for i in range(len(tags)):
        tags[i] = tags[i]['tag']
    return render_template('users/profile.html',
                           email=email,
                           posts=posts,
                           tags=tags)
Exemple #4
0
def tagEditor():
    tags = list(Post.getAllTags())
    for i in range(len(tags)):
        tags[i] = tags[i]['tag']
    css = [{'prefix': 'css/compiled/', 'name': 'tag-editor'}]
    return render_template('posts/tag-editor.html', tags=tags, css=css)