Пример #1
0
def addPage():
    """
    Return the Add Item page that allows signedin user to add items
    """
    if request.method == 'POST':
        if 'id' in login_session:
            newItem = Item()
            if request.form['category']:
                newItem.categoryId = session.query(Category)\
                    .filter(Category.name == request.form['category']).one().id
            if request.form['name']:
                newItem.name = request.form['name']
            if request.form['description']:
                newItem.description = request.form['description']
            newItem.userId = login_session['id']

            session.add(newItem)
            session.commit()

        flash("new item has been added")

        return redirect('/', code=302)
    else:
        return render_template('addItem.html')