Skip to content

Commit

Permalink
saved sorting in cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
clemenstyp committed Mar 22, 2024
1 parent 67a8f2b commit 6928341
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
38 changes: 11 additions & 27 deletions Snackbar/Frontpage/Titlepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
import random
import string

from flask import render_template, request, redirect, url_for
from flask import render_template, request, redirect, url_for, make_response
from werkzeug.utils import secure_filename

from Snackbar import app, db
from Snackbar.Helper.Appearance import monster_image, image_from_folder
from Snackbar.Helper.Database import get_users_with_leaders
from Snackbar.models import User

current_sorting = ""


@app.route('/')
def initial():
global current_sorting
sorting = request.args.get('sorting', default=None, type=str)
if sorting is None:
current_sorting = request.cookies.get('current_sorting')
else:
current_sorting = sorting
initusers = get_users_with_leaders()
users = sorted(initusers, key=lambda k: k['firstName'])

Expand All @@ -27,32 +29,14 @@ def initial():
users.reverse()
users = sorted(users, key=lambda k: k['coffeeMonth'])
users.reverse()

else:
current_sorting = "az"

# if current_sorting == "az":
# users = sorted(initusers, key=lambda k: k['firstName'])
# elif current_sorting == "za":
# users = sorted(initusers, key=lambda k: k['firstName'])
# users.reverse()
# elif current_sorting == "coffee19":
# users = sorted(initusers, key=lambda k: k['coffeeMonth'])
# elif current_sorting == "coffee91":
# users = sorted(initusers, key=lambda k: k['coffeeMonth'])
# users.reverse()
# else:
# current_sorting = "az"
# users = sorted(initusers, key=lambda k: k['firstName'])

return render_template('index.html', users=users, current_sorting=current_sorting)


@app.route('/sort/<sorting>')
def sort(sorting):
global current_sorting
current_sorting = sorting
return redirect(url_for('initial'))
resp = make_response(render_template('index.html', users=users, current_sorting=current_sorting))
resp.set_cookie('current_sorting', current_sorting)
return resp
# return render_template('index.html', users=users, current_sorting=sorting)



@app.route('/image/')
Expand Down
5 changes: 4 additions & 1 deletion templates/choices.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@
width:100% !important;
height:100% !important;
background-color: #e6efff;
font-size: 1.5rem;
font-size: 1.45rem;
}
.textBorder
{
position: absolute;
left: 0;
width: 100%;
height:60px !important;
padding-left: 2px !important;
padding-right: 2px !important;

}
.items_container {
text-align:center;
Expand Down
8 changes: 4 additions & 4 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@
<div class="ui text container">
<h2 class="ui center aligned header" style="height: 30px; overflow: hidden">
Name:
<a href="{{url_for('sort',sorting='az')}}">
<a href="{{url_for('initial',sorting='az')}}">
{% if current_sorting == 'az' %}<i class="sort alphabet ascending icon"></i>{% else %}<i class="sort alphabet ascending icon black"></i>{% endif %}
</a>
<a href="{{url_for('sort',sorting='za')}}">
<a href="{{url_for('initial',sorting='za')}}">
{% if current_sorting == 'za' %}<i class="sort alphabet descending icon"></i>{% else %}<i class="sort alphabet descending icon black"></i>{% endif %}
</a>
&nbsp;&nbsp; | &nbsp;&nbsp; Coffee:
<a href="{{url_for('sort',sorting='coffee91')}}">
<a href="{{url_for('initial',sorting='coffee91')}}">
{% if current_sorting == 'coffee91' %}<i class="sort numeric descending icon"></i>{% else %}<i class="sort numeric descending icon black"></i>{% endif %}
</a>
<a href="{{url_for('sort',sorting='coffee19')}}">
<a href="{{url_for('initial',sorting='coffee19')}}">
{% if current_sorting == 'coffee19' %}<i class="sort numeric ascending icon"></i>{% else %}<i class="sort numeric ascending icon black"></i>{% endif %}
</a>
</h2>
Expand Down

0 comments on commit 6928341

Please sign in to comment.