Ejemplo n.º 1
0
def newOption(category_name):
    log = str(login_session.has_key('username'))
    category = get_cat_by_name(category_name)
    if request.method == 'POST':
        # check if required fields are filled
        if request.form['name'] == '' or request.form['description'] == '':
            warning = "Fill both name and description to add  option"
            return render_template('new-option.html',
                                   category=category,
                                   categories=get_cats(),
                                   log=log,
                                   warning=warning)
        # create new option
        else:
            user_id = login_session['user_id']
            anotherOption = Option(name=request.form['name'],
                                   description=request.form['description'],
                                   cat_id=category.id,
                                   user_id=user_id)
            session.add(anotherOption)
            session.commit()
            return redirect(url_for('category', category_name=category.name))
    else:
        return render_template('new-option.html',
                               category=category,
                               categories=get_cats(),
                               log=log)
Ejemplo n.º 2
0
def category(category_name):
    log = str(login_session.has_key('username'))
    category = get_cat_by_name(category_name)
    options = get_options_by_cat(category)
    return render_template('category.html',
                           meta_title=meta_title,
                           meta_desc=meta_desc,
                           log=log,
                           categories=get_cats(),
                           category=category,
                           options=options)
Ejemplo n.º 3
0
def option(category_name, option_id):
    log = str(login_session.has_key('username'))
    category = get_cat_by_name(category_name)
    option = get_option_by_id(option_id)
    links = get_links_by_opId(option_id)
    return render_template('option.html',
                           meta_title=meta_title,
                           meta_desc=meta_desc,
                           log=log,
                           categories=get_cats(),
                           category=category,
                           option=option,
                           links=links)
Ejemplo n.º 4
0
def editOption(category_name, option_id):
    log = str(login_session.has_key('username'))
    user_id = login_session['user_id']
    category = get_cat_by_name(category_name)
    option = get_option_by_id(option_id)
    links = get_links_by_opId(option_id)
    # check if obj in db
    if category and option:
        if request.method == 'POST':
            f = request.form
            if f['name'] == '' or f['description'] == '':
                warning = "You need both Research Option' and 'Description'"
                return render_template('edit-option.html',
                                       log=log,
                                       meta_title=meta_title,
                                       meta_desc=meta_desc,
                                       categories=get_cats(),
                                       category=category,
                                       option=option,
                                       links=links,
                                       warning=warning)
            else:
                update_option(option, f)
                category = session.query(Category).filter_by(
                    id=option.cat_id).one()
                flash(option.name + ' has updated')
                return redirect(
                    url_for('option',
                            category_name=category.name,
                            option_id=option.id))
        # show option page
        else:
            return render_template('edit-option.html',
                                   meta_title=meta_title,
                                   meta_desc=meta_desc,
                                   log=log,
                                   categories=get_cats(),
                                   category=category,
                                   option=option,
                                   links=links)
Ejemplo n.º 5
0
def categoryJSON(category_name):
    category = get_cat_by_name(category_name)
    options = get_options_by_cat(category)
    return jsonify(Options=[i.serialize for i in options])