From a2c7d46ced239bc6884ed9100ac20c9881defc3a Mon Sep 17 00:00:00 2001 From: Andreas Valder <andreasv@fsmpi.rwth-aachen.de> Date: Thu, 1 Sep 2016 19:31:10 +0200 Subject: [PATCH] made it posible to select the week to schow in the schedule fixed bugs who the hell inserts lectures with zero duration?!? --- server.py | 15 ++++++++++----- templates/macros.html | 1 + templates/schedule.html | 7 +++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/server.py b/server.py index 81d40c2..77a00e7 100755 --- a/server.py +++ b/server.py @@ -198,7 +198,11 @@ def auth(): # For use with nginx auth_request @register_navbar('Drehplan', 'calendar') @mod_required def schedule(): - start = date.today() - timedelta(days=date.today().weekday()+7*20) + if 'kw' not in request.args: + kw=0 + else: + kw=int(request.args['kw']) + start = date.today() - timedelta(days=date.today().weekday() -7*kw) days = [{'date': start, 'lectures': [], 'atonce':0, 'index': 0 }] earlieststart=time(23,59) latestend=time(0,0) @@ -221,7 +225,8 @@ def schedule(): freecol=[]; for l in i['lectures']: l['time_asdate'] = datetime.strptime(l['time'],'%Y-%m-%d %H:%M:%S') - l['end_asdate'] = l['time_asdate']+timedelta(minutes=l['duration']) + # who the hell inserts lectures with zero length?!?!? + l['end_asdate'] = l['time_asdate']+timedelta(minutes=max(l['duration'],1)) for l in sorted([(l['time_asdate'],True,l) for l in i['lectures']] + [(l['end_asdate'],False,l) for l in i['lectures']],key=lambda t:(t[0],t[1])): if l[1]: curcol += 1 @@ -240,12 +245,12 @@ def schedule(): i['maxcol'] = max(maxcol,1) times=[] s = min(earlieststart,time(8,0)) - e = max(latestend,time(20,0)) - for i in range(s.hour*4,int(60*e.hour/15)): + e = max(latestend,time(19,0)) + 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('schedule.html',days=days,times=times) + return render_template('schedule.html',days=days,times=times,kw=kw) @app.route('/stats') @register_navbar('Statistiken', 'stats') diff --git a/templates/macros.html b/templates/macros.html index 629a8d9..16579d2 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -130,6 +130,7 @@ $('#embedcodebtn').popover( <li>{{ valueeditor(['lectures',lecture.id,'title'], lecture.title) }}</li> {% if lecture.speaker or ismod() %}<li>Gehalten von {{ valueeditor(['lectures',lecture.id,'speaker'], lecture.speaker) }}</li>{% endif %} <li>{{ valueeditor(['lectures',lecture.id,'time'], lecture.time) }} </li> + <li>Dauer: {{ valueeditor(['lectures',lecture.id,'duration'], lecture.duration) }} min</li> {% if ismod() %} {% endif %} </ul> diff --git a/templates/schedule.html b/templates/schedule.html index 45b33f4..dbd4123 100644 --- a/templates/schedule.html +++ b/templates/schedule.html @@ -5,6 +5,13 @@ <div class="panel-heading"> <h1 class="panel-title">Drehplan</h1> </div> + <div class="row"> + <div style="margin-top: 10px;" class="col-xs-12"> + <a href="{{url_for('schedule', kw=kw-1) }}" class="pull-left btn btn-default">{{ "<<" }}</a> + <a href="{{url_for('schedule', kw=kw+1) }}" class="pull-right btn btn-default">{{ ">>" }}</a> + <a href="{{url_for('schedule', kw=0) }}" style="width: 80px;" class="center-block btn btn-default">today</a> + </div> + </div> <div class="panel-body row table-responsive"> <table class="table-bordered col-xs-12"> <tr><th></th>{% for d in days if (d.index < 5) or (d.lectures|length) > 0%}<th colspan="{{d.maxcol}}">{{ d.date.strftime("%A (%d.%m.%Y)") }}</th>{% endfor %}</tr> -- GitLab