diff --git a/schoolapps/templates/partials/header.html b/schoolapps/templates/partials/header.html index 5401bbd63dc65c3b7a1e50c8fa83e2bd765b921e..640d6a9135ee29f1dba37dba3b2f58a7307212c3 100755 --- a/schoolapps/templates/partials/header.html +++ b/schoolapps/templates/partials/header.html @@ -102,9 +102,14 @@ <li> <a class="subheader grey lighten-3">Stundenplan</a> </li> + <li> + <a href="{% url 'timetable_my_plan' %}"> + <i class="material-icons">person</i> Mein Plan + </a> + </li> <li> <a href="{% url 'timetable_admin_all' %}"> - <i class="material-icons">grid_on</i> Übersicht + <i class="material-icons">grid_on</i> Alle Pläne </a> </li> <li> diff --git a/schoolapps/timetable/templates/timetable/datepicker.html b/schoolapps/timetable/templates/timetable/datepicker.html new file mode 100644 index 0000000000000000000000000000000000000000..ace7c502c7559e30299e7405e65c07f306b57635 --- /dev/null +++ b/schoolapps/timetable/templates/timetable/datepicker.html @@ -0,0 +1,62 @@ +<script type="text/javascript"> + function updateDatepicker() { + $("#date").val(formatDate(activeDate)); + } + + function update() { + console.log("Render new."); + + updateDatepicker(); + } + + function loadNew() { + window.location.href = dest + formatDateForDjango(activeDate); + } + + function onDateBeforeClick() { + activeDate.setDate(activeDate.getDate() - 1); + update(); + loadNew(); + } + + function onDateNextClick() { + activeDate.setDate(activeDate.getDate() + 1); + update(); + loadNew(); + } + + function onDateChanged() { + var str = $("#date").val(); + var split = str.split(".") + activeDate = new Date(split[2], split[1] - 1, split[0]); + update(); + loadNew(); + } + + var activeDate = new Date({{ date_js }}); + + $(document).ready(function () { + $("#date-before").click(onDateBeforeClick); + $("#date-next").click(onDateNextClick); + $("#date").change(onDateChanged); + + update(); + }) +</script> + + +<div class="col s2"> + <a class="waves-effect waves-teal btn-flat btn-flat-medium right" id="date-before"> + <i class="material-icons center">navigate_before</i> + </a> + +</div> +<div class="col s8"> + <input type="text" class="datepicker center-align" id="date"> +</div> +<div class="col s2"> + <a class="waves-effect waves-teal btn-flat btn-flat-medium left" id="date-next"> + <i class="material-icons center">navigate_next</i> + </a> +</div> + diff --git a/schoolapps/timetable/templates/timetable/lesson.html b/schoolapps/timetable/templates/timetable/lesson.html new file mode 100644 index 0000000000000000000000000000000000000000..9c974cbe4c1bf28f1bbd29578b8abe21163b9508 --- /dev/null +++ b/schoolapps/timetable/templates/timetable/lesson.html @@ -0,0 +1,88 @@ +<div class="card lesson-card"> + <div class="card-content"> + + {# Every element of the lesson #} + {% for element_container in col.elements %} + <div style=" + {# Display background color only if no badge exists and it is not the old room #} + {% if not element_container.substitution.table.badge %} + {% if not element_container.is_old or type != 1 %} + background-color: {{ element_container.element.subject.hex_color }}; + {% endif %} + {% endif %}" + + {# Add CSS class for sub when it's a sub #} + class="{% if element_container.substitution %}lesson-with-sub{% endif %}"> + <p> + {% if element_container.substitution %} + {# SUBSTITUTION #} + + {% if type == 1 and element_container.is_old %} + {# When it's the old room, let it empty #} + + {% elif element_container.substitution.table.badge %} + {# When a badge (cancellation, etc.) exists, then display it #} + <span class="badge new green darken-2">{{ element_container.substitution.table.badge }}</span> + + + {% else %} + {# Display sub #} + + {# Teacher or room > display classes #} + {% if type == 0 or type == 1 %} + {{ element_container.substitution.table.classes }} + {% endif %} + + {# Display teacher with tooltip #} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ element_container.substitution.table.teacher_full|safe }}">{{ element_container.substitution.table.teacher|safe }}</span> + + {# Display subject #} + {{ element_container.substitution.table.subject|safe }} + + {# Teacher or class > display room #} + {% if type == 0 or type == 2 %} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ element_container.substitution.table.room_full|safe }}">{{ element_container.substitution.table.room|safe }}</span> + {% endif %} + {% endif %}<br> + + {# When it isn't a room or the old plan, then display the extra text (e. g. work orders)#} + {% if not type == 1 or not element_container.is_old %} + <small> + <em>{{ element_container.substitution.table.text|default:"" }}</em> + </small> + {% endif %} + + + {% else %} + {# Normal plan #} + + {# Teacher or room > Display classes #} + {% if type == 0 or type == 1 %} + {% for class in element_container.element.classes %} + {{ class.name }} + {% endfor %} + {% endif %} + + {# Class or room > Display teacher #} + {% if type == 2 or type == 1 %} + <span data-position="bottom" class="tooltipped" + data-tooltip="{{ element_container.element.teacher }}">{{ element_container.element.teacher.shortcode }}</span> + {% endif %} + + {# Display subject #} + <strong>{{ element_container.element.subject.shortcode }}</strong> + + {# Teacher or class > Display room #} + {% if type == 0 or type == 2 %} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ element_container.room.name }}">{{ element_container.room.shortcode }}</span> + {% endif %} + {% endif %} + </p> + </div> + + {% endfor %} + </div> +</div> diff --git a/schoolapps/timetable/templates/timetable/myplan.html b/schoolapps/timetable/templates/timetable/myplan.html new file mode 100644 index 0000000000000000000000000000000000000000..8d0ac5933da1531baf0e911af2c14079c1571715 --- /dev/null +++ b/schoolapps/timetable/templates/timetable/myplan.html @@ -0,0 +1,75 @@ +{% include 'partials/header.html' %} + + +<main> + <h4>Mein Plan</h4> + <h6>für <em>{{ el }}</em></h6> + + <script type="text/javascript"> + var dest = "/timetable/my/"; + </script> + <div class="row"> + <div class="col s12 m6"> + {% include "timetable/datepicker.html" %} + </div> + </div> + {# <h5>{{ date|date:"l, j. F Y" }}</h5>#} + <div class="row"> + <div class="timetable-plan col s12 m6"> + + {# Week days #} + <div class="row"> + <div class="col s6"> + + </div> + {% for week_daye in week_days %} + {% if forloop.counter0 == week_day %} + <div class="col s6"> + <div class="card timetable-title-card"> + <div class="card-content"> + <span class="card-title"> + {{ week_daye }} + </span> + </div> + </div> + </div> + {% endif %} + {% endfor %} + </div> + {# Lessons #} + {% for row, time in plan %} + <div class="row"> + <div class="col s6"> + <div class="card timetable-title-card"> + <div class="card-content"> + + {# Lesson number #} + <span class="card-title left"> + {{ time.number_format }} + </span> + + {# Time dimension of lesson #} + <div class="right timetable-time grey-text text-darken-2"> + <span>{{ time.start|date:"H:i" }}</span><br> + <span>{{ time.end|date:"H:i" }}</span> + </div> + </div> + </div> + + </div> + {% for col in row %} + {% if forloop.counter0 == week_day %} + <div class="col s6"> + {# A lesson #} + {% include "timetable/lesson.html" %} + </div> + {% endif %} + {% endfor %} + </div> + {% endfor %} + + </div> + </div> +</main> + +{% include 'partials/footer.html' %} diff --git a/schoolapps/timetable/templates/timetable/plan.html b/schoolapps/timetable/templates/timetable/plan.html index 6b54309f10983713a21ea22479b2f88cf55428c4..af57930dd5127c7464a9ac89dadffb526dbcc0b3 100755 --- a/schoolapps/timetable/templates/timetable/plan.html +++ b/schoolapps/timetable/templates/timetable/plan.html @@ -135,96 +135,7 @@ </div> {% for col in row %} {# A lesson #} - <div class="col s2"> - <div class="card lesson-card"> - <div class="card-content"> - - {# Every element of the lesson #} - {% for element_container in col.elements %} - <div style=" - {# Display background color only if no badge exists and it is not the old room #} - {% if not element_container.substitution.table.badge %} - {% if not element_container.is_old or type != 1 %} - background-color: {{ element_container.element.subject.hex_color }}; - {% endif %} - {% endif %}" - - {# Add CSS class for sub when it's a sub #} - class="{% if element_container.substitution %}lesson-with-sub{% endif %}"> - <p> - {% if element_container.substitution %} - {# SUBSTITUTION #} - - {% if type == 1 and element_container.is_old %} - {# When it's the old room, let it empty #} - - {% elif element_container.substitution.table.badge %} - {# When a badge (cancellation, etc.) exists, then display it #} - <span class="badge new green darken-2">{{ element_container.substitution.table.badge }}</span> - - - {% else %} - {# Display sub #} - - {# Teacher or room > display classes #} - {% if type == 0 or type == 1 %} - {{ element_container.substitution.table.classes }} - {% endif %} - - {# Display teacher with tooltip #} - <span class="tooltipped" data-position="bottom" - data-tooltip="{{ element_container.substitution.table.teacher_full|safe }}">{{ element_container.substitution.table.teacher|safe }}</span> - - {# Display subject #} - {{ element_container.substitution.table.subject|safe }} - - {# Teacher or class > display room #} - {% if type == 0 or type == 2 %} - <span class="tooltipped" data-position="bottom" - data-tooltip="{{ element_container.substitution.table.room_full|safe }}">{{ element_container.substitution.table.room|safe }}</span> - {% endif %} - {% endif %}<br> - - {# When it isn't a room or the old plan, then display the extra text (e. g. work orders)#} - {% if not type == 1 or not element_container.is_old %} - <small> - <em>{{ element_container.substitution.table.text|default:"" }}</em> - </small> - {% endif %} - - - {% else %} - {# Normal plan #} - - {# Teacher or room > Display classes #} - {% if type == 0 or type == 1 %} - {% for class in element_container.element.classes %} - {{ class.name }} - {% endfor %} - {% endif %} - - {# Class or room > Display teacher #} - {% if type == 2 or type == 1 %} - <span data-position="bottom" class="tooltipped" - data-tooltip="{{ element_container.element.teacher }}">{{ element_container.element.teacher.shortcode }}</span> - {% endif %} - - {# Display subject #} - <strong>{{ element_container.element.subject.shortcode }}</strong> - - {# Teacher or class > Display room #} - {% if type == 0 or type == 2 %} - <span class="tooltipped" data-position="bottom" - data-tooltip="{{ element_container.room.name }}">{{ element_container.room.shortcode }}</span> - {% endif %} - {% endif %} - </p> - </div> - - {% endfor %} - </div> - </div> - </div> + {% include "timetable/lesson.html" %} {% endfor %} </div> {% endfor %} diff --git a/schoolapps/timetable/urls.py b/schoolapps/timetable/urls.py index 17ab3432169873d32baaf4e4500142c6e3a51904..8c6ad77e7845bd98cb0d0e203ff23dc2b2a14c7d 100755 --- a/schoolapps/timetable/urls.py +++ b/schoolapps/timetable/urls.py @@ -3,6 +3,8 @@ from . import views urlpatterns = [ path('', views.all, name='timetable_admin_all'), + path('my', views.my_plan, name='timetable_my_plan'), + path('my/<int:year>/<int:month>/<int:day>/', views.my_plan, name='timetable_my_plan'), path('quick/', views.quicklaunch, name='timetable_quicklaunch'), path('<str:plan_type>/<int:plan_id>', views.plan, name='timetable_plan'), path('<str:plan_type>/<int:plan_id>/<str:smart>', views.plan, name='timetable_smart_plan'), diff --git a/schoolapps/timetable/views.py b/schoolapps/timetable/views.py index 8e8ea62defee13945669b18b68ef64d2be5dc0af..fcd5e91e2655d19a6231a577d105e32de27fadb0 100755 --- a/schoolapps/timetable/views.py +++ b/schoolapps/timetable/views.py @@ -3,7 +3,7 @@ import os from django.contrib.auth.decorators import login_required, permission_required from django.http import Http404, FileResponse -from django.shortcuts import render +from django.shortcuts import render, redirect from django.utils import timezone from schoolapps.settings import WEEK_DAYS @@ -12,6 +12,7 @@ from timetable.pdf import generate_class_tex, generate_pdf from untisconnect.plan import get_plan, TYPE_TEACHER, TYPE_CLASS, TYPE_ROOM, parse_lesson_times from untisconnect.sub import get_substitutions_by_date, generate_sub_table from untisconnect.api import * +from userinformation import UserInformation def get_all_context(): @@ -118,6 +119,53 @@ def plan(request, plan_type, plan_id, smart="", year=timezone.datetime.now().yea return render(request, 'timetable/plan.html', context) +@login_required +@permission_required("timetable.show_plan") +def my_plan(request, year=None, day=None, month=None): + date = timezone.datetime.now() + if year is not None and day is not None and month is not None: + date = timezone.datetime(year=year, month=month, day=day) + + calendar_week = date.isocalendar()[1] + monday_of_week = get_calendar_week(calendar_week, date.year)["first_day"] + + _type = UserInformation.user_type(request.user) + + if _type == UserInformation.TEACHER: + _type = TYPE_TEACHER + shortcode = request.user.username + el = get_teacher_by_shortcode(shortcode) + plan_id = el.id + print(el) + elif _type == UserInformation.STUDENT: + _type = TYPE_CLASS + _name = UserInformation.user_classes(request.user)[0] + print(_name) + el = get_class_by_name(_name) + plan_id = el.id + else: + redirect("timetable_admin_all") + print(monday_of_week) + + plan = get_plan(_type, plan_id, smart=True, monday_of_week=monday_of_week) + # print(parse_lesson_times()) + + context = { + "type": _type, + "id": plan_id, + "plan": plan, + "el": el, + "times": parse_lesson_times(), + "week_day": date.isoweekday() - 1, + "week_days": WEEK_DAYS, + "date": date, + "date_js": int(date.timestamp()) * 1000 + } + print(context["week_day"]) + + return render(request, 'timetable/myplan.html', context) + + def get_next_weekday(date): """Get the next weekday by a datetime object""" diff --git a/schoolapps/untisconnect/api.py b/schoolapps/untisconnect/api.py index 598b00ffcad34eba66707d1acd1c193d114ea13c..c769ab2d2c9cdf19f03f909b8f41b8424d841b9e 100755 --- a/schoolapps/untisconnect/api.py +++ b/schoolapps/untisconnect/api.py @@ -41,7 +41,7 @@ def row_by_row(db_ref, obj, filter_term=True): def one_by_id(db_ref, obj): # print(db_ref) - if db_ref != None: + if db_ref is not None: o = obj() o.create(db_ref) return o @@ -85,6 +85,11 @@ def get_teacher_by_id(id): return one_by_id(teacher, Teacher) +def get_teacher_by_shortcode(shortcode): + teacher = run_one(models.Teacher.objects).get(name__icontains=shortcode) + return one_by_id(teacher, Teacher) + + ######### # CLASS # ######### @@ -125,6 +130,11 @@ def get_class_by_id(id): return one_by_id(_class, Class) +def get_class_by_name(name): + _class = run_one(models.Class.objects).get(name__icontains=name) + return one_by_id(_class, Class) + + ######## # ROOM # ########