introduce db, some changes to UI

This commit is contained in:
Pavol Rusnak 2011-06-19 02:22:08 +02:00
parent 57f8f51b4f
commit e3c99305cc
17 changed files with 151 additions and 18 deletions

1
server/.gitignore vendored
View file

@ -1,2 +1,3 @@
users.py users.py
*.pyc *.pyc
brmbar.db

View file

@ -1,14 +1,18 @@
#!/usr/bin/python #!/usr/bin/python
from flask import Flask, render_template, Response from flask import Flask, render_template, Response, g, redirect, abort, request, send_from_directory
from re import match from re import match
from users import users from users import users
import sqlite3
import os
app = Flask('BrmBar') app = Flask('BrmBar')
@app.route('/') @app.route('/')
def index(): def index():
return render_template('index.html') cur = g.db.execute('SELECT id, code, name, price FROM items ORDER BY name')
items = [dict(id = row[0], code = row[1], name = row[2], price = row[3]) for row in cur.fetchall()]
return render_template('index.html', items = items)
@app.route('/code/<code>') @app.route('/code/<code>')
def code(code): def code(code):
@ -52,12 +56,29 @@ def action(user, item):
pass pass
return Response('OK', content_type = 'text/plain') return Response('OK', content_type = 'text/plain')
@app.route('/admin/') @app.route('/items/')
def admin(): def items():
return render_template('admin.html') cur = g.db.execute('SELECT id, code, name, price FROM items ORDER BY name')
items = [dict(id = row[0], code = row[1], name = row[2], price = row[3]) for row in cur.fetchall()]
return render_template('items.html', items = items)
@app.route('/admin/barcode-generator.txt') @app.route('/items/', methods=['POST'])
def admin_barcodegeneratortxt(): def items_post():
f = request.form
if f['action'] == 'add':
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 f['action'].startswith('delete:'):
id = int(f['action'][7:])
g.db.execute('DELETE FROM items WHERE id = ?', (id, ))
g.db.commit()
return redirect('/items/')
abort(400)
@app.route('/barcodes.txt')
def barcodestxt():
ret = [] ret = []
ret.append('Credit 20;C0020') ret.append('Credit 20;C0020')
ret.append('Credit 50;C0050') ret.append('Credit 50;C0050')
@ -80,5 +101,23 @@ def log():
def stats(): def stats():
return render_template('stats.html') return render_template('stats.html')
@app.route('/static/items/<filename>')
def download_file(filename):
if not os.path.exists('static/items/' + filename):
filename = 'missing.jpg'
return send_from_directory('static/items/', filename, mimetype='image/jpeg')
def connect_db():
return sqlite3.connect('brmbar.db')
@app.before_request
def before_request():
g.db = connect_db()
@app.after_request
def after_request(response):
g.db.close()
return response
if __name__ == '__main__': if __name__ == '__main__':
app.run(host = '0.0.0.0', port = 45678) app.run(host = '0.0.0.0', port = 45678, debug = True)

42
server/items.sql Normal file
View file

@ -0,0 +1,42 @@
INSERT INTO items(code, name, price) VALUES("4029764001807", "Club Mate 0.5L", 35);
INSERT INTO items(code, name, price) VALUES("4029764001821", "Club Mate 0.33L", 25);
INSERT INTO items(code, name, price) VALUES("5018374350930", "Tesco Baked Beans in Tomato Sauce", 20);
INSERT INTO items(code, name, price) VALUES("7622300331436", "Siesta mlecna", 10);
INSERT INTO items(code, name, price) VALUES("7622300331467", "Siesta horka", 10);
INSERT INTO items(code, name, price) VALUES("7622300331498", "Siesta oriskova", 10);
INSERT INTO items(code, name, price) VALUES("7613031880065", "Delissa oriskova", 7);
INSERT INTO items(code, name, price) VALUES("7613031880003", "Delissa vanilkova", 7);
INSERT INTO items(code, name, price) VALUES("7613031879946", "Delissa cokoladova", 7);
INSERT INTO items(code, name, price) VALUES("8593868000555", "Pivo Branik 10% svetle", 25);
INSERT INTO items(code, name, price) VALUES("8594404000329", "Pivo Gambrinus 10% svetle", 25);
INSERT INTO items(code, name, price) VALUES("8594404001241", "Pivo Radegast 10% svetle", 25);
INSERT INTO items(code, name, price) VALUES("8594001021512", "Matonni perliva 1.5L", 20);
INSERT INTO items(code, name, price) VALUES("5449000000286", "Coca-Cola 2L", 50);
INSERT INTO items(code, name, price) VALUES("8801043263108", "Shin Cup Noodle Soup", 25);
INSERT INTO items(code, name, price) VALUES("8934646229308", "Lucky Beef Flavor", 10);
INSERT INTO items(code, name, price) VALUES("8594033171902", "Big Shock tycinka", 15);
INSERT INTO items(code, name, price) VALUES("85909311", "Margot tycinka", 15);
INSERT INTO items(code, name, price) VALUES("8584004041198", "Tatranky", 8);
INSERT INTO items(code, name, price) VALUES("85917095", "Margot tycinka +20%", 17);
INSERT INTO items(code, name, price) VALUES("8593894800075", "Bebe cokoladove", 15);
INSERT INTO items(code, name, price) VALUES("5906747308803", "Pim's coko piskoty visnove", 30);
INSERT INTO items(code, name, price) VALUES("8584004010200", "Kavenky", 10);
INSERT INTO items(code, name, price) VALUES("8586011330463", "Vinea Biela", 50);
INSERT INTO items(code, name, price) VALUES("8586011330470", "Vinea Cervena", 50);
INSERT INTO items(code, name, price) VALUES("8593894911030", "Zlate oplatky liskooriskove", 17);
INSERT INTO items(code, name, price) VALUES("8593894911122", "Zlate oplatky smetanove", 17);
INSERT INTO items(code, name, price) VALUES("85951631", "Frisco brusinka", 25);
INSERT INTO items(code, name, price) VALUES("8593868110445", "Staropramen 10%", 25);
INSERT INTO items(code, name, price) VALUES("8714800011426", "Bavaria 0.0%", 25);
INSERT INTO items(code, name, price) VALUES("8594003844782", "Orangina zluta", 25);
INSERT INTO items(code, name, price) VALUES("3155930006015", "Desperados 0.33L", 40);
INSERT INTO items(code, name, price) VALUES("5060166692636", "Monster Ripper 0.5L", 35);
INSERT INTO items(code, name, price) VALUES("8585002408976", "Kure na paprice", 35);
INSERT INTO items(code, name, price) VALUES("8593837223220", "Kure na paprice", 35);
INSERT INTO items(code, name, price) VALUES("8593837223213", "Gulas", 35);
INSERT INTO items(code, name, price) VALUES("8593837223176", "Bolonska omacka", 35);
INSERT INTO items(code, name, price) VALUES("031146254903", "Big Ramen - Shin Cup Noodle Soup", 35);
INSERT INTO items(code, name, price) VALUES("031146254019", "Big Ramen - Noodle Shrimp Flavour", 35);
INSERT INTO items(code, name, price) VALUES("85933323", "Deli pistaciova", 10);
INSERT INTO items(code, name, price) VALUES("85933354", "Deli cokoladova", 10);
INSERT INTO items(code, name, price) VALUES("8594067540071", "Prave hospodske bramburky", 12);

7
server/schema.sql Normal file
View file

@ -0,0 +1,7 @@
DROP TABLE IF EXISTS items;
CREATE TABLE items (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
price INTEGER NOT NULL,
code TEXT NOT NULL
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

27
server/static/style.css Normal file
View file

@ -0,0 +1,27 @@
body {
font-family: Helvetica, Arial;
}
table {
border: 1px solid #888;
border-spacing: 0px;
}
td, th {
padding: 8px;
}
th {
background: #ddd;
}
div.block {
border: 1px solid #888;
width: 160px;
height: 180px;
float: left;
margin: 8px;
text-align: center;
font-size: 10pt;
padding-top: 8px;
}

View file

@ -1,7 +0,0 @@
{% extends "base.html" %}
{% block title %}Admin{% endblock %}
{% block content %}
<p><a href="barcode-generator.txt">barcode generator input</a></p>
{% endblock %}

View file

@ -1,12 +1,13 @@
<html> <html>
<head> <head>
<title>BrmBar: {% block title %}{% endblock %}</title> <title>BrmBar: {% block title %}{% endblock %}</title>
<link rel="icon" type="image/png" href="/static/favicon.png"> <link rel="icon" type="image/png" href="/static/favicon.png" />
<link rel="stylesheet" type="text/css" href="/static/style.css" />
</head> </head>
<body> <body>
<h1><img src="/static/favicon.png" valign="middle" /> BrmBar: {{ self.title() }}</h1> <h1><img src="/static/favicon.png" valign="middle" /> BrmBar: {{ self.title() }}</h1>
<div id="menu"> <div id="menu">
<a href="/">home</a> | <a href="/stats/">stats</a> | <a href="/log/">log</a> | <a href="/admin/">admin</a> <p><a href="/">home</a> | <a href="/stats/">stats</a> | <a href="/log/">log</a> | <a href="/items/">items</a></p>
</div> </div>
<div id="content"> <div id="content">
{% block content %}{% endblock %} {% block content %}{% endblock %}

View file

@ -1,5 +1,13 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}Welcome{% endblock %} {% block title %}Welcome{% endblock %}
{% block content %} {% block content %}
welcome
{% for item in items %}
<div class="block">
<img src="/static/items/{{ item.code|safe }}.jpg"><br/>
{{ item.name|safe }}<br/>
<strong>{{ item.price }} Kc</strong>
</div>
{% endfor %}
{% endblock %} {% endblock %}

View file

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block title %}Items{% endblock %}
{% block content %}
<form action="" method="post">
<table>
<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>
{% 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.id }}"/></tr>
{% endfor %}
</table>
</form>
{% endblock %}