diff --git a/server/.gitignore b/server/.gitignore index 49e471a..7cf0cc2 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,2 +1,3 @@ users.py *.pyc +brmbar.db diff --git a/server/brmbar-server b/server/brmbar-server index 4d96545..a94d502 100755 --- a/server/brmbar-server +++ b/server/brmbar-server @@ -1,14 +1,18 @@ #!/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 users import users +import sqlite3 +import os app = Flask('BrmBar') @app.route('/') 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/') def code(code): @@ -52,12 +56,29 @@ def action(user, item): pass return Response('OK', content_type = 'text/plain') -@app.route('/admin/') -def admin(): - return render_template('admin.html') +@app.route('/items/') +def items(): + 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') -def admin_barcodegeneratortxt(): +@app.route('/items/', methods=['POST']) +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.append('Credit 20;C0020') ret.append('Credit 50;C0050') @@ -80,5 +101,23 @@ def log(): def stats(): return render_template('stats.html') +@app.route('/static/items/') +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__': - app.run(host = '0.0.0.0', port = 45678) + app.run(host = '0.0.0.0', port = 45678, debug = True) diff --git a/server/items.sql b/server/items.sql new file mode 100644 index 0000000..416ad9b --- /dev/null +++ b/server/items.sql @@ -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); diff --git a/server/schema.sql b/server/schema.sql new file mode 100644 index 0000000..f9ec992 --- /dev/null +++ b/server/schema.sql @@ -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 +); diff --git a/server/static/items/4029764001807.jpg b/server/static/items/4029764001807.jpg new file mode 100644 index 0000000..5b22437 Binary files /dev/null and b/server/static/items/4029764001807.jpg differ diff --git a/server/static/items/4029764001821.jpg b/server/static/items/4029764001821.jpg new file mode 100644 index 0000000..9b6eb3d Binary files /dev/null and b/server/static/items/4029764001821.jpg differ diff --git a/server/static/items/5449000000286.jpg b/server/static/items/5449000000286.jpg new file mode 100644 index 0000000..5fa1ca5 Binary files /dev/null and b/server/static/items/5449000000286.jpg differ diff --git a/server/static/items/8593837223176.jpg b/server/static/items/8593837223176.jpg new file mode 100644 index 0000000..5037d6b Binary files /dev/null and b/server/static/items/8593837223176.jpg differ diff --git a/server/static/items/8593837223213.jpg b/server/static/items/8593837223213.jpg new file mode 100644 index 0000000..17e56e0 Binary files /dev/null and b/server/static/items/8593837223213.jpg differ diff --git a/server/static/items/8593837223220.jpg b/server/static/items/8593837223220.jpg new file mode 100644 index 0000000..ba00634 Binary files /dev/null and b/server/static/items/8593837223220.jpg differ diff --git a/server/static/items/8594033171902.jpg b/server/static/items/8594033171902.jpg new file mode 100644 index 0000000..6b42d7d Binary files /dev/null and b/server/static/items/8594033171902.jpg differ diff --git a/server/static/items/missing.jpg b/server/static/items/missing.jpg new file mode 100644 index 0000000..efd220c Binary files /dev/null and b/server/static/items/missing.jpg differ diff --git a/server/static/style.css b/server/static/style.css new file mode 100644 index 0000000..dffd1e2 --- /dev/null +++ b/server/static/style.css @@ -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; +} \ No newline at end of file diff --git a/server/templates/admin.html b/server/templates/admin.html deleted file mode 100644 index 56f47de..0000000 --- a/server/templates/admin.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "base.html" %} -{% block title %}Admin{% endblock %} -{% block content %} - -

barcode generator input

- -{% endblock %} diff --git a/server/templates/base.html b/server/templates/base.html index e6439e5..6fc8eff 100644 --- a/server/templates/base.html +++ b/server/templates/base.html @@ -1,12 +1,13 @@ BrmBar: {% block title %}{% endblock %} - + +

BrmBar: {{ self.title() }}

{% block content %}{% endblock %} diff --git a/server/templates/index.html b/server/templates/index.html index f2b16a7..4b9969d 100644 --- a/server/templates/index.html +++ b/server/templates/index.html @@ -1,5 +1,13 @@ {% extends "base.html" %} {% block title %}Welcome{% endblock %} {% block content %} -welcome + +{% for item in items %} +
+
+{{ item.name|safe }}
+{{ item.price }} Kc +
+{% endfor %} + {% endblock %} diff --git a/server/templates/items.html b/server/templates/items.html new file mode 100644 index 0000000..35a4055 --- /dev/null +++ b/server/templates/items.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} +{% block title %}Items{% endblock %} +{% block content %} + +
+ + + +{% for item in items %} + +{% endfor %} +
imagecodeitempriceaction
{{ item.code|safe }}{{ item.name|safe }}{{ item.price }}
+
+ +{% endblock %}