Skip to content

Instantly share code, notes, and snippets.

@vvikramjhu
Created July 24, 2013 17:34
Show Gist options
  • Save vvikramjhu/6072690 to your computer and use it in GitHub Desktop.
Save vvikramjhu/6072690 to your computer and use it in GitHub Desktop.
Post data ( from firebug in firefox) ---
name
oilit0001 chicken
oilit00013 -
oilit00014 1
telephone
Source
name=&telephone=&oilit0001=chicken&oilit00013=-&oilit00014=1 .
html code ----
@app.route('/basant', methods = ['GET', 'POST'])
def basant():
if request.method =='POST':
counter = 0
details = request.form.copy()
length = (len(details) - 2 )/ 3
name = details['name']
telephone = details['telephone']
#TODO // find a better for deleting together for below lines
del details['name']
del details['telephone']
for value in details:
if len(value)== 9: # Means that the value is the item itself. the others have longer than 9 values
itemName = details['value']
size = details['value'+'3']
quantity = details['value'+'4']
g.db.execute('insert into items ( itemId , item , itemSize , itemQuant) values(?,?,?,?)',[value, itemName, size, quantity])
g.db.execute('insert into invoice (itemId, nameOfPerson, telephone, currentDate, waitTime ) values(?,?,?,?,?)',
[value , name, telephone, 5, 30 ])
g.db.commit()
# now delete all used up values from the values dict
return render_template('basant.html' , details = values)
# form = OrderForm()
# if form.validate_on_submit():
# flash(form.name.data+ ', telephone='+ form.telephone.data )
# return redirect('/basantOrders')
return render_template('basant.html',title = 'Enter Details')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment