def newCategory():
    if request.method == 'POST':
        category = Category(name=request.form['name'],
                            user_id=login_session['user_id'])
        session.add(category)
        session.commit()
        flash('Category <b>%s</b> added' % category.name)
        return redirect(url_for('viewCategory', category_id=category.id))
    return render_template('newcategory.html')
Esempio n. 2
0
def editCategory(category_id, category):
    if request.method == 'POST':
        category.name = request.form['name']
        session.add(category)
        session.commit()
        flash('Category <b>%s</b> has been edited' % category.name)
        return redirect(url_for('editCategories'))
    else:
        return render_template('editcategory.html', category=category)
Esempio n. 3
0
def createUser(login_session):
    """
    Adds a new user in the database
    """
    newUser = User(name=login_session['username'],
                   email=login_session['email'],
                   picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    return newUser.id
Esempio n. 4
0
def editItem(category_id, category, item_id, item):
    if request.method == 'POST':
        item.name = request.form['name']
        item.description = request.form['description']
        if len(request.form.getlist('random-img')) > 0:
            item.picture = get_image.randomImage(item.name)
        else:
            item.picture = request.form['picture']
        item.category_id = request.form['category']
        session.add(item)
        session.commit()
        flash('Item <b>%s</b> has been edited' % item.name)
        return redirect(
            url_for('viewItem', category_id=category_id, item_id=item_id))
    else:
        return render_template('edititem.html', item=item)
Esempio n. 5
0
def newItem():
    if request.method == 'POST':
        name = request.form['name']
        if len(request.form.getlist('random-img')) > 0:
            picture = get_image.randomImage(name)
        else:
            picture = request.form['picture']
        item = Item(name=name,
                    description=request.form['description'],
                    picture=picture,
                    category_id=request.form['category'],
                    user_id=login_session['user_id'])
        session.add(item)
        session.commit()
        flash('Item <b>%s</b> added' % item.name)
        return redirect(url_for('viewCategory', category_id=item.category_id))
    else:
        if request.referrer and 'category' in request.referrer:
            referrer = int(request.referrer.split("/")[4])
            return render_template('newitem.html', ref=referrer)
        else:
            return render_template('newitem.html')