Skip to content

Commit ae9072e

Browse files
committed
date picker
1 parent 89eac8b commit ae9072e

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

core/routes.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ async def brawlstats_tests_proxy(request, endpoint):
256256
return response.text('Request failed', status=503)
257257

258258
@root.get('/schoolweek')
259-
async def schoolweek(request):
259+
async def schoolweektoday(request):
260+
return response.redirect(f'/schoolweek/{date.today()}')
261+
262+
@root.get('/schoolweek/<requested_date_str>')
263+
async def schoolweek(request, requested_date_str):
260264
first_day = date(2020, 9, 8)
261265
no_school = [
262266
date(2020, 9, 28), # Yom Kippur
@@ -276,7 +280,8 @@ async def schoolweek(request):
276280
0: 'B'
277281
}
278282

279-
next_friday = thisweek(date.today())[-1]
283+
requested_date = date(*map(int, requested_date_str.split('-')))
284+
next_friday = thisweek(requested_date)[-1]
280285
elapsed_dates = daterange(first_day, next_friday)
281286
mondays = [d for d in elapsed_dates if d.weekday() == 0 and d not in no_school]
282287
cohort_day = 'maroon'
@@ -319,7 +324,7 @@ async def schoolweek(request):
319324
'day': prev_day + 1})
320325

321326

322-
week = thisweek(date.today())
327+
week = thisweek(requested_date)
323328

324329
week_fmt = []
325330
for day in week:
@@ -330,4 +335,11 @@ async def schoolweek(request):
330335
else:
331336
week_fmt.append(f"{day.strftime('%a %m/%d')}<br>{day_info['cohort'].title()} {day_map[day_info['day'] % 2]} day")
332337

333-
return await render_template('schoolweek', request, week=week_fmt, title='School Week', description='This week\'s maroon and gray A and B days.')
338+
return await render_template(
339+
template='schoolweek',
340+
request=request,
341+
week=week_fmt,
342+
title='School Week',
343+
requested_date=requested_date,
344+
description='This week\'s maroon and gray A and B days.'
345+
)

core/templates/schoolweek.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<div class="container">
44
<div class="info" style="padding-top:40px;padding-bottom:10px;">
55
<h1>School Week</h1>
6-
<h5>This week's maroon and gray A and B days.</h5>
6+
<h5>Maroon and gray A and B days for the week of {{ requested_date.strftime('%m/%d/%Y') }}</h5>
7+
<label for="requested-date">Choose date</label>
8+
<input type="date" id="requested-date" name="requested-date"
9+
value="{{ requested_date }}"
10+
min="2020-09-05" max="2021-06-11" onchange="onDateChange(event);">
711
</div>
812
<table>
913
<tr>
@@ -25,7 +29,12 @@ <h5>This week's maroon and gray A and B days.</h5>
2529
color: #8d0000;
2630
}
2731
.Gray {
28-
color: #808080;
32+
color: #686868;
2933
}
3034
</style>
35+
<script>
36+
function onDateChange(e){
37+
window.location.href = `/schoolweek/${e.target.value}`;
38+
}
39+
</script>
3140
{% endblock content %}

0 commit comments

Comments
 (0)