Esempio n. 1
0
def item_create(cid = None):
  if request.method == 'POST':
    print 'To process item creation.'
    item = Item()
    item.category_id = request.form['item-category_id']
    item.name = request.form['item-name']
    item.longtext = request.form["item-longtext"]
    file = request.files["item-image"]
    print type(file)
    item.image = file.read()
    item.user_id = get_user_id_from_session()
    result = item.add()
    if result[1] == 'error':
      flash(result[2], result[1])
    else:
      item.commit()
      return redirect(url_for('item.item_display', item_id = item.id))
  else:
    if cid == None:
      flash('Please select a category.', 'error')
      return redirect_common(url_for('category.home'))

  return render_template('item.html', title = 'Create item',\
                         item = Item(category_id = cid),\
                         display = False
                        )