diff --git a/templates/timetable.html b/templates/timetable.html index 5fb7badae82e2c3b12569ecb4270633d2c9d8565..8cf89037386ef7ebdd9b1f7b4a0d687282de41dc 100644 --- a/templates/timetable.html +++ b/templates/timetable.html @@ -7,20 +7,28 @@ <a class="pull-right fa fa-calendar" aria-hidden="true" href="{{url_for('ical_all')}}" style="text-decoration: none"></a> </h1> </div> - <div class="row hidden-print"> - <div style="margin-top: 10px;" class="col-xs-12"> + <div class="hidden-print"> + <div style="margin-top: 10px; padding: 15px;" class="col-xs-12"> <a href="{{url_for('timetable', kw=kw-1) }}" class="pull-left btn btn-default">{{ "<<" }}</a> <a href="{{url_for('timetable', kw=kw+1) }}" class="pull-right btn btn-default">{{ ">>" }}</a> - <a href="{{url_for('timetable', kw=0) }}" style="width: 80px;" class="center-block btn btn-default">today</a> + <a href="{{url_for('timetable', kw=0) }}" style="width: 80px;" class="btn btn-default center-block">today</a> </div> + <input id="weeksel" type="week" class="center-block" value="{{ weekofyear }}"/> + <script> + $( function () { + $("#weeksel").on("change", function() { + window.location.href="{{ url_for('timetable') }}?date="+$("#weeksel").val() + }); + }); + </script> </div> - <div class="panel-body row table-responsive" style="margin-left: 0px; margin-right: 0px; padding-left: 0px; padding-right: 0px"> + <div class="panel-body row table-responsive"> <table id="timetable" class="table table-bordered col-xs-12" style="width: auto; min-width: 100%;"> <tr><th style="width: 30px;"></th>{% for d in days if (d.index < 5) or (d.lectures|length) > 0 %}<th style="min-width: 10em;" colspan="{{d.maxcol}}">{{ d.date.strftime("%A (%d.%m.%Y)") }}</th>{% endfor %}</tr> {# iterating over each 15 min block #} {% for t in times %} {% set time_index = loop.index %} - <tr height="12px" {% if t.strftime("%M") == "00" %} class="hourlytime" {% endif %}> + <tr{% if t.strftime("%M") == "00" %} class="hourlytime"{% endif %}> {# display time in first row if its a full hour #} {% if ((time_index - 1) is divisibleby 4) %} <td rowspan="4" style="vertical-align: top;">{{ t.strftime("%H:%M") }}</td> {% endif %} {# iterate over days if if it is a working day or we have lectures on that day (optionaly skip weekends) #} @@ -72,6 +80,5 @@ </div> </div> </div> -</div> {% endblock %} diff --git a/timetable.py b/timetable.py index ad2a54dfeeb82a585466efdb0b7c4bc0e4d53cb9..d4cd38af82252d66f01e1baed06e57456b9c894f 100644 --- a/timetable.py +++ b/timetable.py @@ -5,7 +5,29 @@ from server import * @mod_required def timetable(): if 'kw' not in request.args: - kw=0 + if 'date' in request.args: + thisweekmonday = datetime.now() + thisweekmonday -= timedelta(days=thisweekmonday.weekday()) + + try: + datesweekmonday = datetime.strptime(request.args['date'], '%d-%m-%Y') + except ValueError: + datesweekmonday = None + if not datesweekmonday: + try: + datesweekmonday = datetime.strptime(request.args['date'] + '-1', "%Y-W%W-%w") + except ValueError: + datesweekmonday = None + + if not datesweekmonday: + kw = 0 + weekofyear = str(datetime.today().year) + "-W" + str(datetime.today().isocalendar()[1]) + else: + datesweekmonday -= timedelta(days=datesweekmonday.weekday()) + weekofyear = str(datesweekmonday.year) + "-W" + str(datesweekmonday.isocalendar()[1]) + kw = int((datesweekmonday.date() - thisweekmonday.date()).days/7) + else: + kw=0 else: kw=int(request.args['kw']) try: @@ -79,4 +101,4 @@ def timetable(): for i in range(s.hour*4,min(int((60*e.hour/15)/4)*4+5,24*4)): t = i*15 times.append(time(int(t/60),t%60)) - return render_template('timetable.html',days=days,times=times,kw=kw) + return render_template('timetable.html',days=days,times=times,kw=kw, weekofyear=weekofyear)