diff --git a/cutprogress.py b/cutprogress.py index dc216881b9da0f692fb689b4220be2338a691d7a..a46b6c9aa182a2ad5929bd7edd6cf7043ca42f2e 100644 --- a/cutprogress.py +++ b/cutprogress.py @@ -1,9 +1,14 @@ from server import * from datetime import time -@app.route('/internal/cutprogress') -@app.route('/internal/users/<int:user>/cutprogress') +@register_navbar('Schnittfortschritt User', icon='spinner', iconlib='fa', userendpoint=True) +@app.route('/internal/user/<int:user>/cutprogress') +@mod_required +def cutprogress_user(user): + return cutprogress(user) + @register_navbar('Schnittfortschritt', icon='spinner', iconlib='fa') +@app.route('/internal/cutprogress', endpoint="cutprogress") @mod_required def cutprogress(user=None): allsemester = query('SELECT DISTINCT semester from courses ORDER BY semester DESC'); @@ -24,4 +29,4 @@ def cutprogress(user=None): course['responsible'] = [{"realname": "Niemand", "id": -1}] if not user or user in [ r['id'] for r in course['responsible'] ]: courses.append(course) - return render_template('cutprogress.html', allsemester=allsemester, semester=semester, courses=courses, maxlecturecount=maxlecturecount, user=user) + return render_template('cutprogress.html', allsemester=allsemester, semester=semester, courses=courses, maxlecturecount=maxlecturecount, user=query('SELECT * FROM users WHERE id = ?', user)[0] if user else None) diff --git a/mail.py b/mail.py index b6151302fed7ef6e0a3ddecd37e227e3852e5b26..a464002cb83424ea5d6eea94d743b2f102e519fa 100644 --- a/mail.py +++ b/mail.py @@ -67,10 +67,9 @@ def notify_admins(msgtype, **kwargs): except: traceback.print_exc() -@app.route('/internal/notifications') -@register_navbar('Benachrichtigungen', icon='bell') +@app.route('/internal/user/<int:user>/notifications') +@register_navbar('Benachrichtigungen', icon='bell', userendpoint=True) @mod_required -def user_notifications(): - user = query('SELECT * FROM users WHERE id = ?', session['user']['dbid'])[0] - return render_template('user.html', user=user) +def user_notifications(user): + return render_template('notifications.html', user=query('SELECT * FROM users WHERE id = ?', user)[0]) diff --git a/server.py b/server.py index 08473197df571c5a5f35e3a4a45c695723744f65..282c75ebdb970290d3e68320645d41cd71612808 100644 --- a/server.py +++ b/server.py @@ -80,10 +80,10 @@ app.jinja_env.globals['navbar'] = [] # ( see: http://getbootstrap.com/components/#glyphicons ) # or 'fa' # ( see: http://fontawesome.io/icons/ ) -def register_navbar(name, iconlib='bootstrap', icon=None): +def register_navbar(name, iconlib='bootstrap', icon=None, userendpoint=False): def wrapper(func): endpoint = func.__name__ - app.jinja_env.globals['navbar'].append((endpoint, name, iconlib, icon, not endpoint in mod_endpoints)) + app.jinja_env.globals['navbar'].append((endpoint, name, iconlib, icon, not endpoint in mod_endpoints, userendpoint)) return func return wrapper diff --git a/templates/base.html b/templates/base.html index 5f09cc7fda2622a9d98b886fac23b8025c5d8fa1..7a72d98ad3d763a1104b327d45093ad8ec9f2dc7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,7 +8,7 @@ <html lang="de"> <head> {% block header %} - <title>Video AG {% block title %}{% for endpoint, caption, iconlib, gly, visible in navbar if ((visible or ismod()) and (endpoint == request.endpoint)) %}- {{ caption }}{% else%}{% endfor %}{% endblock %}</title> + <title>Video AG {% block title %}{% for endpoint, caption, iconlib, gly, visible, userendpoint in navbar if ((visible or ismod()) and (endpoint == request.endpoint)) %}- {{ caption }}{% else%}{% endfor %}{% endblock %}</title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <link rel="icon" type="image/png" href="{{url_for('static', filename='favicon.png')}}"> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> @@ -56,7 +56,7 @@ <img alt="Brand" src="{{url_for('static', filename='logo.png')}}" style="height: 44px; width: 44px" > </a> <ul class="nav nav-pills" style="margin-top: 5px; padding-left: 40px;"> - {% for endpoint, caption, iconlib, gly, visible in navbar if visible %} + {% for endpoint, caption, iconlib, gly, visible, userendpoint in navbar if visible and (not userendpoint) %} <li{% if endpoint == request.endpoint %} class="active"{% endif %}> <a href="{{ url_for(endpoint) }}" style="padding: 10px 6px;"> {% if gly != '' %} @@ -72,9 +72,9 @@ {% endfor %} </ul> </div> - <div class="collapse navbar-collapse"> + <div class="collapse navbar-collapse" style="overflow-y: inherit"> <ul class="nav nav-pills" style="margin-top: 5px;"> - {% for endpoint, caption, iconlib, gly, visible in navbar if (not visible) and ismod() %} + {% for endpoint, caption, iconlib, gly, visible, userendpoint in navbar if (not visible) and ismod() and (not userendpoint) %} <li{% if endpoint == request.endpoint %} class="active"{% endif %}> <a href="{{ url_for(endpoint) }}" style="padding: 10px 6px;"> {% if gly != '' %} @@ -114,10 +114,25 @@ ) </script> {% else %} - <a href="{{url_for('logout', ref=request.url)}}"> - {{ session.user.givenName }} - <span class="glyphicon glyphicon-log-out"></span> - </a> + <button data-toggle="dropdown" data-boundary="viewport" class="btn dropdown-toggle" style="padding: 10px 6px;">{{ session.user.givenName }} <span class="caret"></span></button> + <ul class="dropdown-menu"> + {% for endpoint, caption, iconlib, gly, visible, userendpoint in navbar if userendpoint %} + <li{% if endpoint == request.endpoint %} class="active"{% endif %}> + <a href="{{ url_for(endpoint, user=session.user.dbid) }}"> + {% if gly != '' %} + {% if iconlib == 'bootstrap' %} + <span aria-hidden="true" class="glyphicon glyphicon-{{ gly }}"></span> + {% elif iconlib == 'fa' %} + <span aria-hidden="true" class="fa fa-{{ gly }}"></span> + {% endif %} + {{ caption }} + {% endif %} + </a> + </li> + {% endfor %} + <li class="divider"></li> + <li><a href="{{url_for('logout', ref=request.url)}}">Logout</a></li> + </ul> {% endif %} </li> </ul> diff --git a/templates/cutprogress.html b/templates/cutprogress.html index 34ae9ea619bec864cddd4284b762773a8ff24b2b..f04178f13c50e163b803ac645e0209f4de171a18 100644 --- a/templates/cutprogress.html +++ b/templates/cutprogress.html @@ -4,8 +4,11 @@ <div class="panel panel-default"> <div class="panel-heading"> <span class="panel-title"> - Semester <select id="semesterselect" name="semester"></select> + Schnittfortschritt{% if user %} für {{ user.realname }}{% endif %} </span> + <span class="pull-right"> + Semester <select id="semesterselect" name="semester"></select> + </span> </div> <div class="panel-body table-responsive"> <table class="table table-condensed table-bordered"> @@ -52,7 +55,11 @@ $( document ).ready(function () { {% endfor %} $("#semesterselect").val("{{ semester }}") $("#semesterselect").on("change", function () { - window.location.href="{{ url_for('cutprogress', user=user) }}?semester="+$("#semesterselect").val(); + {% if user %} + window.location.href="{{ url_for('cutprogress_user', user=user.id) }}?semester="+$("#semesterselect").val(); + {% else %} + window.location.href="{{ url_for('cutprogress') }}?semester="+$("#semesterselect").val(); + {% endif %} }); }); </script> diff --git a/templates/user.html b/templates/notifications.html similarity index 100% rename from templates/user.html rename to templates/notifications.html diff --git a/templates/timetable.html b/templates/timetable.html index c6aaa6d60ac92f8b717d6249339ab36e8761d39d..f00f55ff136da1a48f8a1538dc1591ecd471fe18 100644 --- a/templates/timetable.html +++ b/templates/timetable.html @@ -3,21 +3,37 @@ <div class="panel-group" id="accordion"> <div class="panel panel-default"> <div class="hidden-print panel-heading"> - <h1 class="panel-title">Drehplan - <a class="pull-right fa fa-calendar" aria-hidden="true" href="{{url_for('ical_all')}}" style="text-decoration: none"></a> - </h1> + {% if user %} + <h1 class="panel-title">personalisierter Drehplan für {{ user.realname }} + <a class="pull-right fa fa-calendar" aria-hidden="true" href="{{ url_for('ical_user', user=user.id) }}" style="text-decoration: none"></a> + </h1> + {% else %} + <h1 class="panel-title">Drehplan + <a class="pull-right fa fa-calendar" aria-hidden="true" href="{{ url_for('ical_all') }}" style="text-decoration: none"></a> + </h1> + {% endif %} </div> <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="btn btn-default center-block">today</a> + {% if user %} + <a href="{{url_for('timetable_user', user=user.id, kw=kw-1) }}" class="pull-left btn btn-default">{{ "<<" }}</a> + <a href="{{url_for('timetable_user', user=user.id, kw=kw+1) }}" class="pull-right btn btn-default">{{ ">>" }}</a> + <a href="{{url_for('timetable_user', user=user.id, kw=0) }}" style="width: 80px;" class="btn btn-default center-block">today</a> + {% else %} + <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="btn btn-default center-block">today</a> + {% endif %} </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() + {% if user %} + window.location.href="{{ url_for('timetable_user', user=user.id) }}?date="+$("#weeksel").val() + {% else %} + window.location.href="{{ url_for('timetable') }}?date="+$("#weeksel").val() + {% endif %} }); }); </script> diff --git a/timetable.py b/timetable.py index 2f6fbf34ea833f5b13619ecaab64cc377c0c8ad7..2d93dca541ce5a883ed89738b4965e0ed8567124 100644 --- a/timetable.py +++ b/timetable.py @@ -1,10 +1,16 @@ from server import * from datetime import time +@app.route('/internal/user/<int:user>/timetable') +@register_navbar('personalisierter Drehplan', icon='calendar', userendpoint=True) +@mod_required +def timetable_user(user): + return timetable(user) + @app.route('/internal/timetable') @register_navbar('Drehplan', icon='calendar') @mod_required -def timetable(): +def timetable(user=None): if 'kw' not in request.args: if 'date' in request.args: thisweekmonday = datetime.now() @@ -56,7 +62,16 @@ def timetable(): if not l['time']: l['time'] = datetime.fromtimestamp(0) if ((l['time'] < e) and (l['time'] > s)) or ((l['time'] + timedelta(minutes=l['duration']) < e) and (l['time'] + timedelta(minutes=l['duration'])> s)): - i['lectures'].append(l) + # filter on responsible user if a user parameter was given + l['responsible'] = query('''SELECT users.* + FROM responsible + JOIN users ON (responsible.user_id = users.id AND responsible.course_id = ?) + ORDER BY users.realname ASC''', l['course_id']) + if len(l['responsible']) == 0: + l['responsible'] = [{"realname": "Niemand", "id": -1}] + if not user or user in [ r['id'] for r in l['responsible'] ]: + i['lectures'].append(l) + oldtime = l['time'] l['time'] = max(s,l['time']) l['duration'] = ( min(e,oldtime + timedelta(minutes=l['duration'])) - l['time'] ).total_seconds()/60 @@ -102,4 +117,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, weekofyear=weekofyear) + return render_template('timetable.html',days=days,times=times,kw=kw, weekofyear=weekofyear, user=query('SELECT * FROM users WHERE id = ?', user)[0] if user else None)