Skip to content
Snippets Groups Projects
Commit d7a2bfb8 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

My plan with bugs > Test with teachers and e/q classes

parent 94f25b95
No related branches found
No related tags found
No related merge requests found
<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>
<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>
{% 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' %}
......@@ -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 %}
......
......@@ -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'),
......
......@@ -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"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment