Skip to content
Snippets Groups Projects
Commit 525eb2ac authored by Andreas Valder's avatar Andreas Valder
Browse files

added user pages, closes #353

parent 6700bf70
No related branches found
No related tags found
No related merge requests found
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)
......@@ -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])
......@@ -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
......
......@@ -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>
<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>
......
......@@ -4,6 +4,9 @@
<div class="panel panel-default">
<div class="panel-heading">
<span class="panel-title">
Schnittfortschritt{% if user %} für {{ user.realname }}{% endif %}
</span>
<span class="pull-right">
Semester <select id="semesterselect" name="semester"></select>
</span>
</div>
......@@ -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>
......
File moved
......@@ -3,21 +3,37 @@
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="hidden-print panel-heading">
{% 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">
{% 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() {
{% 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>
......
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)):
# 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment