from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
app.config['DEBUG'] = True

# Note: We don't need to call run() since our application is embedded within
# the App Engine WSGI application server.

# "supervisor" or "ra"
role = "ra" 

@app.route('/', methods=["GET", "POST"])
def login():
	error = ""
	if request.method == "POST":
		username = request.form['user']
		password = request.form['password']
		if username == "supervisor":
			if password == "supervisor":
				role = "supervisor"
				return redirect(url_for('hello'))
			else:
				error = "Password does not match username!"
		if username == "attendant":
			if password == "room":
				role = "ra"
				return redirect(url_for('scanner'))
			else:
				error = "Password does not match username!"
		else:
			error = "No such user!"
	return render_template('login.html', error=error)

@app.route('/dashboard')
def hello():
    return render_template('dashboard.html')

@app.route('/inventory/')
def inventory():
	return render_template('inventory.html')

@app.route('/inventory/<item>')
def item(item):
	item = item
	return render_template('item.html', item=item)

@app.route('/logs')
def logs():
	return render_template('logs.html')

@app.route('/scanner')
def scanner():
	return render_template('scanner.html')

@app.route('/storeroom')
def storeroom():
	return render_template('storeroom.html', role=role)

@app.route('/cart')
def cart():
	return render_template('cart.html', role=role)

@app.route('/tasks')
def tasks():
	return render_template('tasks.html')
	
@app.route('/user', methods=["GET"])
def user():
	return render_template('user.html')

@app.route('/icons')
def icons():
	return render_template('icons.html')

@app.route('/maps')
def maps():
	return render_template('maps.html')

@app.route('/notifications')
def notifications():
	return render_template('notifications.html')

@app.route('/table')
def table():
	return render_template('table.html')

@app.route('/template')
def template():
	return render_template('template.html')

@app.route('/typography')
def typography():
	return render_template('typography.html')

@app.route('/upgrade.html')
def upgrade():
	return render_template('upgrade.html')

@app.errorhandler(404)
def page_not_found(e):
    """Return a custom 404 error."""
    return 'Sorry, nothing at this URL.', 404



## testing
if __name__ == '__main__':
	app.run(debug=True, host='0.0.0.0')
@@ -65,29 +65,152 @@
 _for
-%0Aapp = Flask(__name__
+, flash%0Afrom flask.ext.cache import Cache%0Afrom datetime import datetime%0A%0Aapp = Flask(__name__)%0Acache = Cache(app, config=%7B'CACHE_TYPE':'simple'%7D
 )%0Aap
@@ -389,17 +389,26 @@
 e = %22ra%22
- 
+%0Acart = %5B%5D
 %0A%0A@app.r
@@ -1440,50 +1440,371 @@
 ')%0A%0A
-@app.route('/storeroom')%0Adef storeroom():%0A
+# RA shelf view%0A@app.route('/shelves/%3Ctag_id%3E', methods=%5B'GET', 'POST'%5D)%0A@cache.cached(timeout=50)%0Adef shelf(tag_id):%0A%09if request.method == 'GET':%0A%09%09# TODO: query for items in tag%0A%09%09return render_template('storeroom.html', role=role, cart_qty = cart.size())%0A%09else: %0A%09%09item = request.form%5B'item'%5D%0A%09%09qty = request.form%5B'qty'%5D%0A%09%09cart.add(%7B'item':item, 'qty': qty%7D)%0A%09
 %09ret
@@ -1842,35 +1842,60 @@
 html', role=role
+, cart_qty = cart.size()
 )%0A%0A
+%0A
 @app.route('/car
@@ -1895,74 +1895,588 @@
 e('/
-cart')%0Adef cart():%0A%09return render_template('cart.html', role=role)
+shelves/%3Ctag_id%3E/cart', methods=%5B'GET', 'POST'%5D)%0Adef cart(tag_id):%0A%09if request.method == 'GET':%0A%09%09return render_template('cart.html', role=role, cart=cart)%0A%09else:%0A%09%09now = datetime.now()%0A%09%09form = request.form%0A%09%09items = d.getlist%5B'item'%5D%0A%09%09qtys = d.getlist%5B'qty'%5D%0A%09%09for i in range(0, d.size()):%0A%09%09%09# HARDCODED: Username%0A%09%09%09query = %22INSERT INTO Logs (datetime, user, item, qty, type, tag_id) VALUES ('%22+now+%22', 'ra', %22+items%5Bi%5D+%22', '%22+qtys%5Bi%5D+%22', 'withdrawal', '%22+tag_id%22');%22%0A%09%09%09# TODO: Execute query to create log%0A%09%09cache = %5B%5D%0A%09%09flash(%22Success!%22)%0A%09%09return redirect('scanner.html')%0A%0A
 %0A%0A@a

Revert "Revert "Added cart function""