Commit abf3cf9a authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Fix issue #3

parent 90be8085
Pipeline #2685 skipped with stage
...@@ -16,11 +16,13 @@ def index(): ...@@ -16,11 +16,13 @@ def index():
# Fetch list of burgers with corresponding vote info # Fetch list of burgers with corresponding vote info
# Could probably also be done with SQLAlchemy but too lazy to look up how # Could probably also be done with SQLAlchemy but too lazy to look up how
# TODO: Query has a bug. Only burgers created by the user himself are returned. # TODO: Query has a bug. Only burgers created by the user himself are returned.
querystring = text('SELECT burger.id AS id, name, description, burger.nethz AS nethz, timestamp, bread, patty, toppings, side, COUNT(vote_1.id) AS vote_count, vote_2.id AS vote_id ' querystring = text('SELECT burger.id AS id, name, description, burger.nethz AS nethz, timestamp, '
'FROM burger ' 'bread, patty, toppings, side, COUNT(vote_1.id) as vote_count, vote_2.id as vote_id '
'LEFT JOIN vote AS vote_1 ON vote_1.burger_id=burger.id ' 'FROM burger '
'LEFT JOIN vote AS vote_2 ON vote_2.burger_id=burger.id AND vote_2.nethz = :nethz ' 'LEFT JOIN vote AS vote_1 ON vote_1.burger_id=burger.id '
'ORDER BY vote_count ') 'LEFT JOIN vote AS vote_2 ON vote_2.burger_id=burger.id AND vote_2.nethz= :nethz '
'GROUP BY burger.id '
'ORDER BY vote_count DESC')
burger_list = db.engine.execute(querystring, nethz=g.user).fetchall() burger_list = db.engine.execute(querystring, nethz=g.user).fetchall()
return render_template('vote.html', return render_template('vote.html',
burger_list=burger_list, burger_list=burger_list,
...@@ -78,18 +80,18 @@ def vote(): ...@@ -78,18 +80,18 @@ def vote():
return redirect(url_for('index')) return redirect(url_for('index'))
@app.before_request # @app.before_request
def load_user(): # def load_user():
''' # '''
Load user data before any request processing # Load user data before any request processing
''' # '''
try: # try:
if session['nethz']: # if session['nethz']:
g.user = session['nethz'] # g.user = session['nethz']
return # return
except KeyError: # except KeyError:
pass # pass
g.user = None # g.user = None
@app.route('/login', methods=['GET', 'POST']) @app.route('/login', methods=['GET', 'POST'])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment