Exemple #1
0
def createItem():
    if 'username' not in login_session:
        return redirect(url_for('showLogin'))
    if request.method == 'POST':
        category = session.query(Category).filter_by(
            name=request.form['item-category']).first()
        newItem = Item()
        newItem.name = request.form['item-name']
        newItem.description = request.form['description']
        newItem.category = category
        newItem.user_id = getUserID(login_session['email'])
        try:
            with store_context(fs_store):
                if request.files['item_photo']:
                    newItem.picture.from_file(request.files['item_photo'])
                else:
                    newItem.picture.from_file(urlopen(dummy_item_photo))
                session.add(newItem)
                session.commit()
        except Exception:
            session.rollback()
            raise
        return redirect(url_for('showCategories'))
    else:
        categories = session.query(Category).order_by(asc(Category.name))
        return render_template('create_item.html', categories=categories,
                               login_session=login_session)
Exemple #2
0
def createItem():
    if 'username' not in login_session:
        return redirect(url_for('showLogin'))
    if request.method == 'POST':
        category = session.query(Category).filter_by(
            name=request.form['item-category']).first()
        newItem = Item()
        newItem.name = request.form['item-name']
        newItem.description = request.form['description']
        newItem.category = category
        newItem.user_id = getUserID(login_session['email'])
        try:
            with store_context(fs_store):
                if request.files['item_photo']:
                    newItem.picture.from_file(request.files['item_photo'])
                else:
                    newItem.picture.from_file(urlopen(dummy_item_photo))
                session.add(newItem)
                session.commit()
        except Exception:
            session.rollback()
            raise
        return redirect(url_for('showCategories'))
    else:
        categories = session.query(Category).order_by(asc(Category.name))
        return render_template('create_item.html',
                               categories=categories,
                               login_session=login_session)
def addItem():
	if request.method == 'POST':
		if request.form['name'] and request.form['description']:
			newItem = Item()
			newItem.name = request.form['name']
			newItem.description = request.form['description']
			newItem.category = session.query(Category).filter_by(id=request.form['category']).one()
			session.add(newItem)
			session.commit()
			flash('new item added!')
			return redirect(url_for('showItems', category_id=request.form['category']))
	else:
		isLoggedIn = 'username' in login_session
		categories = session.query(Category).all()
		return render_template('newItem.html', categories=categories, isLoggedIn=isLoggedIn)
Exemple #4
0
        item.picture_data = None

    picture = request.files['picture']
    picture_data = None

    if picture:
        if not allowed_file(picture.filename):
            flash("The picture must be a JPEG or PNG file.", "danger")
            return render_template('edit_item.html', categories=categories, item=item, nonce=createNonce())

        picture_data = picture.read()
        print "Content-Length: %s" % picture.content_length

    item.name = name
    item.description = description
    item.category = category

    if picture_data:
        item.picture = picture.filename
        item.picture_data = picture_data

    session.add(item)
    session.commit()
    flash("Your changes have been saved.", "success")

    return redirect(url_for('listItems', category_id=category.id))

@app.route('/item/<int:item_id>/delete/', methods=['GET','POST'])
@login_required
def deleteItem(item_id):
    """Delete the item with the given id.
Exemple #5
0
    picture_data = None

    if picture:
        if not allowed_file(picture.filename):
            flash("The picture must be a JPEG or PNG file.", "danger")
            return render_template('edit_item.html',
                                   categories=categories,
                                   item=item,
                                   nonce=createNonce())

        picture_data = picture.read()
        print "Content-Length: %s" % picture.content_length

    item.name = name
    item.description = description
    item.category = category

    if picture_data:
        item.picture = picture.filename
        item.picture_data = picture_data

    session.add(item)
    session.commit()
    flash("Your changes have been saved.", "success")

    return redirect(url_for('listItems', category_id=category.id))


@app.route('/item/<int:item_id>/delete/', methods=['GET', 'POST'])
@login_required
def deleteItem(item_id):