hide ids from delete button

This commit is contained in:
Pavol Rusnak 2011-06-21 01:01:57 +02:00
parent b6a9e950f5
commit b762c4fe26
2 changed files with 13 additions and 12 deletions

View file

@ -96,19 +96,20 @@ def items():
items = [dict(code = row[0], name = row[1], price = row[2]) for row in cur.fetchall()] items = [dict(code = row[0], name = row[1], price = row[2]) for row in cur.fetchall()]
return render_template('items.html', items = items) return render_template('items.html', items = items)
@app.route('/items/', methods=['POST']) @app.route('/items/', methods = ['POST'])
def items_post(): def items_post():
f = request.form f = request.form
if f['action'] == 'add': for (k, v) in f.iteritems():
if f['code'] and f['name'] and f['price']: if k == 'add' and v == 'add':
g.db.execute('INSERT INTO items (code, name, price) VALUES (?, ?, ?)', (f['code'], f['name'], f['price'])) if f['code'] and f['name'] and f['price']:
g.db.execute('INSERT INTO items (code, name, price) VALUES (?, ?, ?)', (f['code'], f['name'], f['price']))
g.db.commit()
return redirect('/items/')
if k.startswith('delete:') and v == 'delete':
code = k[7:]
g.db.execute('DELETE FROM items WHERE code = ?', (code, ))
g.db.commit() g.db.commit()
return redirect('/items/') return redirect('/items/')
if f['action'].startswith('delete:'):
code = int(f['action'][7:])
g.db.execute('DELETE FROM items WHERE code = ?', (code, ))
g.db.commit()
return redirect('/items/')
abort(400) abort(400)
@app.route('/barcodes.txt') @app.route('/barcodes.txt')

View file

@ -5,9 +5,9 @@
<form action="" method="post"> <form action="" method="post">
<table> <table>
<tr><th>image</th><th>code</th><th>item</th><th>price</th><th>action</th></tr> <tr><th>image</th><th>code</th><th>item</th><th>price</th><th>action</th></tr>
<tr><td></td><td><input name="code" size="14"/></td><td><input name="name" size="30"/></td><td><input name="price" size="2"/></td><td><input type="submit" name="action" value="add"/></tr> <tr><td></td><td><input name="code" size="14"/></td><td><input name="name" size="30"/></td><td><input name="price" size="2"/></td><td><input type="submit" name="add" value="add"/></tr>
{% for item in items %} {% for item in items %}
<tr><td><img src="/static/items/{{ item.code|safe }}.jpg" width="64" height="64"/></td><td>{{ item.code|safe }}</td><td>{{ item.name|safe }}</td><td>{{ item.price }}</td><td><input type="submit" name="action" value="delete:{{ item.code }}"/></tr> <tr><td><img src="/static/items/{{ item.code|safe }}.jpg" width="64" height="64"/></td><td>{{ item.code|safe }}</td><td>{{ item.name|safe }}</td><td>{{ item.price }}</td><td><input type="submit" name="delete:{{ item.code }}" value="delete"/></tr>
{% endfor %} {% endfor %}
</table> </table>
</form> </form>