i['lectures']=query ('SELECT lectures.*,courses.* FROM lectures JOIN courses ON (lectures.course_id = courses.id) WHERE (time < ?) AND (time > ?) ORDER BY time ASC',e,s);
<tr><th></th>{% for d in days %}<thcolspan="{{d.maxcol}}">{{ d.date.strftime("%A (%d.%m.%Y)") }}</th>{% endfor %}</tr>
{% for t in times %}
{% set time_loop = loop %}
<trheight="10px">
{% if ((loop.index - 1) is divisibleby 4) %} <tdrowspan=4>{{ t }}</td> {% endif %}
{% for d in days %}
{% for i in range(1,d.maxcol+1) %}
{% for l in d.lectures|selectattr('schedule_col','equalto',i) if (((l.time_asdate.time() > t) and (l.time_asdate.time() <times[time_loop.index+1]))!=(l.time_asdate.time() ==t))%}