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

Show hints in plan and my plan for students

parent 1374312d
No related branches found
No related tags found
No related merge requests found
import datetime
from timetable.models import Hint
......@@ -6,9 +8,25 @@ def get_all_hints_by_date(date):
return hints
def get_all_hints_by_class_and_time_period(_class, from_date, to_date):
hints_tmp = get_all_hints_by_time_period(from_date, to_date)
hints_match = []
for hint in hints_tmp:
if _class.id in [x.class_id for x in hint.classes.all()]:
hints_match.append(hint)
return hints_match
def get_all_hints_by_time_period(from_date, to_date):
print(from_date, to_date)
hints = Hint.objects.filter(from_date__gte=from_date, to_date__lte=to_date).order_by("from_date", "classes")
week_days = [from_date + datetime.timedelta(days=i) for i in range(5)]
hints = []
for week_day in week_days:
hints_tmp = get_all_hints_by_date(week_day)
for hint in hints_tmp:
if hint not in hints:
hints.append(hint)
print(hints)
return hints
......
{% load martortags %}
{% if hints %}
{% for hint in hints %}
<div class="alert primary">
<div>
<em class="right">Hinweis für {{ hint.from_date|date:"D" }}
{% if hint.from_date != hint.to_date %}
bis {{ hint.to_date|date:"D" }}
{% endif %} </em>
<i class="material-icons left">announcement</i>
{{ hint.text|safe_markdown }}
{# {{ hint }}#}
</div>
</div>
{% endfor %}
{% endif %}
\ No newline at end of file
......@@ -13,6 +13,11 @@
</div>
</div>
<div class="row nomargin">
<div class="col m12 s12 l6">
{% include "timetable/hintsinplan.html" %}
</div>
</div>
<script type="text/javascript">
var dest = "/timetable/my/";
......
......@@ -93,6 +93,9 @@
</a>
{% endif %}
</div>
{% include "timetable/hintsinplan.html" %}
<div class="timetable-plan">
{# Week days #}
......
......@@ -11,7 +11,7 @@ from material import Fieldset, Row
from schoolapps.settings import WEEK_DAYS
from timetable.filters import HintFilter
from timetable.forms import HintForm
from timetable.hints import get_all_hints_by_date, get_all_hints_by_time_period
from timetable.hints import get_all_hints_by_date, get_all_hints_by_time_period, get_all_hints_by_class_and_time_period
from timetable.pdf import generate_class_tex, generate_pdf
from untisconnect.plan import get_plan, TYPE_TEACHER, TYPE_CLASS, TYPE_ROOM, parse_lesson_times
......@@ -94,7 +94,10 @@ def plan(request, plan_type, plan_id, regular="", year=timezone.datetime.now().y
smart = True
monday_of_week = get_calendar_week(calendar_week, year)["first_day"]
friday = monday_of_week + datetime.timedelta(days=4)
# print(monday_of_week)
hints = None
if plan_type == 'teacher':
_type = TYPE_TEACHER
......@@ -102,6 +105,12 @@ def plan(request, plan_type, plan_id, regular="", year=timezone.datetime.now().y
elif plan_type == 'class':
_type = TYPE_CLASS
el = get_class_by_id(plan_id)
# Get hints
if smart:
hints = list(get_all_hints_by_class_and_time_period(el, monday_of_week, friday))
print(hints)
elif plan_type == 'room':
_type = TYPE_ROOM
el = get_room_by_id(plan_id)
......@@ -111,12 +120,6 @@ def plan(request, plan_type, plan_id, regular="", year=timezone.datetime.now().y
plan = get_plan(_type, plan_id, smart=smart, monday_of_week=monday_of_week)
# print(parse_lesson_times())
# Get hints
if smart:
friday = monday_of_week + datetime.timedelta(days=4)
hints = list(get_all_hints_by_time_period(monday_of_week, friday))
print(hints)
context = {
"smart": smart,
"type": _type,
......@@ -128,7 +131,8 @@ def plan(request, plan_type, plan_id, regular="", year=timezone.datetime.now().y
"weeks": get_calendar_weeks(year=year),
"selected_week": calendar_week,
"selected_year": year,
"week_days": WEEK_DAYS
"week_days": WEEK_DAYS,
"hints": hints
}
return render(request, 'timetable/plan.html', context)
......@@ -158,6 +162,7 @@ def my_plan(request, year=None, day=None, month=None):
plan_id = el.id
raw_type = "teacher"
# print(el)
hints = []
elif _type == UserInformation.STUDENT:
_type = TYPE_CLASS
_name = UserInformation.user_classes(request.user)[0]
......@@ -165,6 +170,10 @@ def my_plan(request, year=None, day=None, month=None):
el = get_class_by_name(_name)
plan_id = el.id
raw_type = "class"
# Get hints
hints = list(get_all_hints_by_class_and_time_period(el, date, date))
print(hints)
else:
return redirect("timetable_admin_all")
# print(monday_of_week)
......@@ -183,7 +192,8 @@ def my_plan(request, year=None, day=None, month=None):
"week_days": WEEK_DAYS,
"date": date,
"date_js": int(date.timestamp()) * 1000,
"display_date_only": True
"display_date_only": True,
"hints": hints
}
# print(context["week_day"])
......
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