Commit 59b8a449 authored by Christoph Rackwitz's avatar Christoph Rackwitz Committed by Julian Rother
Browse files

cutprogress: Sortierung nach Tagen

parent 77529a98
from server import * from server import *
from datetime import time import datetime
@register_navbar('Schnittfortschritt User', icon='spinner', iconlib='fa', userendpoint=True, endpoint='cutprogress_user') @register_navbar('Schnittfortschritt User', icon='spinner', iconlib='fa', userendpoint=True, endpoint='cutprogress_user')
@register_navbar('Schnittfortschritt', icon='spinner', iconlib='fa') @register_navbar('Schnittfortschritt', icon='spinner', iconlib='fa')
...@@ -7,33 +7,94 @@ from datetime import time ...@@ -7,33 +7,94 @@ from datetime import time
@app.route('/internal/user/<int:user>/cutprogress', endpoint='cutprogress_user') @app.route('/internal/user/<int:user>/cutprogress', endpoint='cutprogress_user')
@mod_required @mod_required
def cutprogress(user=None): def cutprogress(user=None):
# use request argument, default to latest semester
allsemester = query('SELECT DISTINCT semester from courses ORDER BY semester DESC') allsemester = query('SELECT DISTINCT semester from courses ORDER BY semester DESC')
semester = request.values.get('semester', allsemester[0]['semester']) semester = request.values.get('semester', allsemester[0]['semester'])
coursesraw = query('SELECT courses.id, courses.handle, courses.short FROM courses WHERE semester = ?', semester)
courses = [] # filter to single user?
maxlecturecount = 0 if user is not None:
for course in coursesraw: user = query('SELECT * FROM users WHERE id = ?', user)[0]
course['lectures'] = query('''
SELECT lectures.title, lectures.time, lectures.id FROM lectures # column headers: courses
WHERE lectures.course_id= ? AND NOT lectures.deleted AND NOT lectures.norecording courses = query('''
ORDER BY lectures.time''', course['id']) SELECT courses.id, courses.handle, courses.short, courses.responsible
for lecture in course['lectures']: FROM courses
lecture['videos'] = query(''' WHERE semester = ?
SELECT videos.path, formats.description as formatdesc, videos.visible FROM videos ORDER by id DESC
JOIN formats ON (videos.video_format = formats.id) ''', semester)
WHERE videos.lecture_id = ? AND NOT videos.deleted''', lecture['id'])
course['responsible'] = query('''SELECT users.* # list of people responsible for course
FROM responsible for course in courses:
JOIN users ON (responsible.user_id = users.id AND responsible.course_id = ?) people = query('''
ORDER BY users.realname ASC''', course['id']) SELECT users.*
if len(course['responsible']) == 0: FROM users
course['responsible'] = [{"realname": "Niemand", "id": -1}] JOIN responsible ON responsible.user_id = users.id
if not user or user in [ r['id'] for r in course['responsible'] ]: WHERE responsible.course_id = ?
courses.append(course) ORDER BY users.realname ASC
maxlecturecount = max(len(course['lectures']), maxlecturecount) ''', course['id'])
if not people:
people = [{ 'realname': 'Niemand' }]
course['responsible'] = people
# fetch lectures
lectures = query('''
SELECT
lectures.id,
lectures.course_id,
lectures.time, DATE(lectures.time) as date,
lectures.title,
COUNT(videos.id) as videos_total,
COUNT(videos.visible) as videos_visible
FROM lectures
JOIN courses ON courses.id = lectures.course_id
LEFT JOIN videos ON lectures.id = videos.lecture_id
WHERE courses.semester = ?
AND date <= DATE('now')
AND NOT lectures.norecording
GROUP BY lectures.id
ORDER BY date DESC, lectures.time ASC, lectures.id ASC
''', semester)
# sort dates, figure out when weeks change
dates = sorted({
datetime.datetime.strptime(row['date'], '%Y-%m-%d')
for row in lectures
}, reverse=True)
# check week numbers
is_new_weeks = [
False if (i == 0) else thisdate.isocalendar()[1] != dates[i-1].isocalendar()[1]
for i, thisdate in enumerate(dates)
]
# sort into cells
tablebody = [
{
'date': date, # row header
'is_new_week': is_new_week,
'cells': [ # this is the body of the row
[ # this list is a cell
lecture
for lecture in lectures
if lecture['course_id'] == course['id'] and datetime.datetime.strptime(lecture['date'], '%Y-%m-%d') == date
and (user is None or user in [r['id'] for r in course['responsible']])
]
for course in courses
]
}
for date,is_new_week in zip(dates, is_new_weeks)
]
return render_template('cutprogress.html', return render_template('cutprogress.html',
allsemester=allsemester, # dropdown selection
semester=semester, allsemester=allsemester, # options
courses=courses, semester=semester, # choice
maxlecturecount=maxlecturecount, user=user,
user=query('SELECT * FROM users WHERE id = ?', user)[0] if user else None)
# content
courses=courses,
dates=dates,
tablebody=tablebody,
)
...@@ -144,3 +144,7 @@ th.rotate > div { ...@@ -144,3 +144,7 @@ th.rotate > div {
max-width: 500px; max-width: 500px;
} }
#cutprogress.table tr.weekbreak td {
border-top: 2px solid black !important;
}
...@@ -12,8 +12,11 @@ ...@@ -12,8 +12,11 @@
</span> </span>
</div> </div>
<div class="panel-body table-responsive"> <div class="panel-body table-responsive">
<table class="table table-condensed table-bordered"> <table id="cutprogress" class="table table-condensed table-bordered">
<tr> <tr>
<th class="text-left">
Datum
</th>
{% for course in courses %} {% for course in courses %}
<th class="text-center rotate"> <th class="text-center rotate">
<div> <div>
...@@ -22,33 +25,27 @@ ...@@ -22,33 +25,27 @@
</th> </th>
{% endfor %} {% endfor %}
</tr> </tr>
{% for i in range(maxlecturecount) %}
<tr class="text-center"> {% for row in tablebody %}
{% for course in courses %} <tr class="text-center {% if row.is_new_week %}weekbreak{% endif %}">
<td class="text-left">{{ row.date.strftime("%d.%m.%Y (%a)") }}</td>
{% for cell in row.cells %}
<td> <td>
{% set l = course.lectures[i]|d({}) %} {% for lecture in cell %}
{% if "time" in l %} <a href="{{ url_for('course', handle=lecture.course_id) }}#lecture-{{ lecture.id }}" title="Uhrzeit: {{ lecture.time.strftime('%H:%M') }}&#10;Titel: {{ lecture.title|replace('\n','') }}&#10;Videos: {{ lecture.videos_total }}&#10;Interner Kommentar: {{ lecture.internal }}">
<a href="{{ url_for("course", handle=course.handle) }}#lecture-{{ l.id }}" title="{{ l.time }} &#10;Titel: {{ l.title|replace('\n','') }} &#10;Videos: {{ l.videos|count }} &#10;Internes Kommentar: {{ l.internal }}"> {% if lecture.videos_total == 0 %}
{% if l.time < datetime.now() %}
{% if l.videos|count == 0 %}
<span style="color: red" aria-hidden="true" class="fa fa-times"></span> <span style="color: red" aria-hidden="true" class="fa fa-times"></span>
{% else %} {% elif lecture.videos_visible == 0 %}
{% if l.videos|selectattr('visible')|list|count == 0 %} <span style="color: orange" aria-hidden="true" class="glyphicon glyphicon-ok"></span>
<span style="color: orange" aria-hidden="true" class="glyphicon glyphicon-ok"></span>
{% else %}
<span style="color: green" aria-hidden="true" class="glyphicon glyphicon-ok"></span>
{% endif %}
{% endif %}
{% else %} {% else %}
<span style="color: grey" aria-hidden="true" class="fa fa-times"></span> <span style="color: green" aria-hidden="true" class="glyphicon glyphicon-ok"></span>
{% endif %} {% endif %}
</a> </a>
{% else %} {% endfor %}
{% endif %}
</td> </td>
{% endfor %} {% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
</div> </div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment