Compare commits
3
Commits
cdd6d2f1e3
...
50c03e582b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50c03e582b | ||
|
|
3853c6aeb3 | ||
|
|
1e0668ad77 |
@@ -82,6 +82,36 @@ def getUpcomingMeals():
|
|||||||
r.close()
|
r.close()
|
||||||
return meals
|
return meals
|
||||||
|
|
||||||
|
def getMeal(meal_id):
|
||||||
|
query = 'select foo.id, username as kuk, meal_date, array_agg as eaters, selection_deadline from (select meals.id, kuk, meal_date, selection_deadline, array_agg(username) from meals join users on users.id = any(meals.eaters) where meals.id=:meal_id group by meals.id order by meal_date) as foo join users on kuk=users.id;'
|
||||||
|
r = db_engine.execute(text(query), meal_id=meal_id)
|
||||||
|
meals = []
|
||||||
|
for row in r:
|
||||||
|
meals.append(dict(row))
|
||||||
|
r.close()
|
||||||
|
if len(meals) == 0:
|
||||||
|
return None
|
||||||
|
meal = meals[0]
|
||||||
|
seconds_to_deadline = (meal['selection_deadline'] - datetime.datetime.now()).total_seconds()
|
||||||
|
if seconds_to_deadline < 0:
|
||||||
|
meal['friendly_selection_deadline'] = ''
|
||||||
|
elif seconds_to_deadline > 3600:
|
||||||
|
hours_td = round(seconds_to_deadline / 3600)
|
||||||
|
days_td = int(hours_td / 24)
|
||||||
|
hours_td = hours_td % 24
|
||||||
|
meal['friendly_selection_deadline'] = str(days_td) + ' days ' + str(hours_td) + ' hours'
|
||||||
|
else:
|
||||||
|
meal['friendly_selection_deadline'] = str(round(seconds_to_deadline / 60)) + ' minutes'
|
||||||
|
meal['meal_time'] = meal['meal_date'].strftime('%H:%M')
|
||||||
|
meal['meal_friendly_date'] = meal['meal_date'].strftime('%A %d %B')
|
||||||
|
meal['candidate'] = 'davide'
|
||||||
|
if (meal['meal_date'] - datetime.datetime.now()).total_seconds() < 0:
|
||||||
|
meal['needs_confirmation'] = True
|
||||||
|
else:
|
||||||
|
meal['needs_confirmation'] = False
|
||||||
|
|
||||||
|
return meal
|
||||||
|
|
||||||
# adding to meal
|
# adding to meal
|
||||||
@app.route("/addme")
|
@app.route("/addme")
|
||||||
@login_required
|
@login_required
|
||||||
@@ -102,6 +132,15 @@ def addme():
|
|||||||
def index():
|
def index():
|
||||||
return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), now=datetime.datetime.now())
|
return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), now=datetime.datetime.now())
|
||||||
|
|
||||||
|
@app.route('/view_meal')
|
||||||
|
def view_meal():
|
||||||
|
meal_id = request.args.get('meal')
|
||||||
|
meal = getMeal(meal_id)
|
||||||
|
if meal == None:
|
||||||
|
return abort(400)
|
||||||
|
print(meal)
|
||||||
|
return render_template('index.html', leaderboard=getLeaderboard(), meal=meal)
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
|||||||
@@ -162,6 +162,10 @@ h2 {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.username {
|
||||||
|
text-transform: capitalize;
|
||||||
|
}
|
||||||
|
|
||||||
.rect-button {
|
.rect-button {
|
||||||
width: 90px;
|
width: 90px;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
|
|||||||
+11
-11
@@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Meal planned for {{meal_date}} - KUKAPP</title>
|
<title>Meal planned for {{meal.meal_friendly_date}} - KUKAPP</title>
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
||||||
<script src="{{ url_for('static', filename='script.js') }}"></script>
|
<script src="{{ url_for('static', filename='script.js') }}"></script>
|
||||||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
|
||||||
@@ -29,34 +29,34 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div class="right-pane">
|
<div class="right-pane">
|
||||||
<h1>When: {{date}}</h1>
|
<h1>When: {{meal.meal_friendly_date}}</h1>
|
||||||
<h2>Cook</h2>
|
<h2>Cook</h2>
|
||||||
<div class="flex-card">
|
<div class="flex-card">
|
||||||
{% if cook.confirmed == "no" %}
|
{% if meal.kuk == "" %}
|
||||||
<img src="{{url_for('static', filename='question.png')}}">
|
<img src="{{url_for('static', filename='question.png')}}">
|
||||||
<p>If nobody volunteers,<br><img class="flex-small-thumb" src="{{url_for('static', filename=cook.name + '.png')}}" title="{{current_user.name}}" align="middle"> will cook.</p>
|
<p>If nobody volunteers,<br><img class="flex-small-thumb" src="{{url_for('static', filename=meal.kuk + '.png')}}" title="{{current_user.name}}" align="middle"> will cook.</p>
|
||||||
<div class="rect-button" onclick="location.href='/volunteer';" style="background-color: #EE7500;">VOLUNTEER</div>
|
<div class="rect-button" onclick="location.href='/volunteer';" style="background-color: #EE7500;">VOLUNTEER</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<img src="{{url_for('static', filename= cook.name + '.png')}}">
|
<img src="{{url_for('static', filename=meal.kuk + '.png')}}">
|
||||||
<span>{{ cook.name }}</span>
|
<span class="username">{{ meal.kuk }}</span>
|
||||||
<div class="rect-button" style="background-color: #8faf38; cursor: default;">CONFIRMED</div>
|
<div class="rect-button" style="background-color: #8faf38; cursor: default;">CONFIRMED</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<h2>Eaters</h2>
|
<h2>Eaters</h2>
|
||||||
{% for eater in eaters %}
|
{% for eater in meal.eaters %}
|
||||||
<div class="flex-card">
|
<div class="flex-card">
|
||||||
<img src="{{url_for('static', filename=eater + '.png')}}">
|
<img src="{{url_for('static', filename=eater + '.png')}}">
|
||||||
<span>{{ eater }}</span>
|
<span class="username">{{ eater }}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if not current_user.name in eaters %}
|
{% if not current_user.name in eaters and current_user.name != meal.kuk %}
|
||||||
<div class="flex-card" style="background: none; box-shadow: none">
|
<div class="flex-card" style="background: none; box-shadow: none">
|
||||||
<div class="round-button" onclick="location.href='/addme';"><i class="fa fa-plus" aria-hidden="true"></i></div>
|
<div class="round-button" onclick="location.href='/addme?meal={{meal.id}}';"><i class="fa fa-plus" aria-hidden="true"></i></div>
|
||||||
<span>Add me</span>
|
<span>Add me</span>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="flex-card" style="background: none; box-shadow: none">
|
<div class="flex-card" style="background: none; box-shadow: none">
|
||||||
<div class="round-button" onclick="location.href='/removeme';"><i class="fa fa-minus" aria-hidden="true"></i></div>
|
<div class="round-button" onclick="location.href='/removeme?meal={{meal.id}}';"><i class="fa fa-minus" aria-hidden="true"></i></div>
|
||||||
<span>Remove me</span>
|
<span>Remove me</span>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -39,9 +39,9 @@
|
|||||||
<h2>{{meal.meal_friendly_date}}</h2>
|
<h2>{{meal.meal_friendly_date}}</h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if meal.needs_confirmation %}
|
{% if meal.needs_confirmation %}
|
||||||
<div class="flex-card" onclick="location.href='/verify/{{meal.id}}';" style="cursor: pointer; width: 60%; justify-content: space-between;">
|
<div class="flex-card" onclick="location.href='/verify?meal={{meal.id}}';" style="cursor: pointer; width: 60%; justify-content: space-between;">
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="flex-card" onclick="location.href='/meal/{{meal.id}}';" style="cursor: pointer; width: 60%; justify-content: space-between;">
|
<div class="flex-card" onclick="location.href='/view_meal?meal={{meal.id}}';" style="cursor: pointer; width: 60%; justify-content: space-between;">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span{% if meal.needs_confirmation%} style="color: #EE7500;"{% endif %}><b>{{meal.meal_time}}</b></span>
|
<span{% if meal.needs_confirmation%} style="color: #EE7500;"{% endif %}><b>{{meal.meal_time}}</b></span>
|
||||||
<p style="text-align: left;">{% if meal.needs_confirmation %}Did {% endif %}{% if meal.kuk != "" %}<img class="flex-small-thumb" src="{{url_for('static', filename=meal.kuk + '.png')}}" title="{{meal.kuk}}" align="middle" style="margin: " /> {% if not meal.needs_confirmation %}<b>WILL</b>{% endif %}{% else %}<img class="flex-small-thumb" src="{{url_for('static', filename=meal.candidate + '.png')}}" title="{{meal.kuk}}" align="middle" style="margin: " /> {% if not meal.needs_confirmation %}<b>SHOULD</b>{% endif %}{% endif%} cook for <br>{% for e in meal.eaters %}<img class="flex-small-thumb" src="{{url_for('static', filename=e + '.png')}}" title="{{e}}" align="middle"/> {% endfor %}{% if meal.needs_confirmation %}<b>?</b>{% endif %}</p>
|
<p style="text-align: left;">{% if meal.needs_confirmation %}Did {% endif %}{% if meal.kuk != "" %}<img class="flex-small-thumb" src="{{url_for('static', filename=meal.kuk + '.png')}}" title="{{meal.kuk}}" align="middle" style="margin: " /> {% if not meal.needs_confirmation %}<b>WILL</b>{% endif %}{% else %}<img class="flex-small-thumb" src="{{url_for('static', filename=meal.candidate + '.png')}}" title="{{meal.kuk}}" align="middle" style="margin: " /> {% if not meal.needs_confirmation %}<b>SHOULD</b>{% endif %}{% endif%} cook for <br>{% for e in meal.eaters %}<img class="flex-small-thumb" src="{{url_for('static', filename=e + '.png')}}" title="{{e}}" align="middle"/> {% endfor %}{% if meal.needs_confirmation %}<b>?</b>{% endif %}</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user