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

Include print view for substitutions with SchoolApps template

Close #60
parent c77aa15c
No related branches found
No related tags found
No related merge requests found
...@@ -96,3 +96,15 @@ table.substitutions td, table.substitutions th { ...@@ -96,3 +96,15 @@ table.substitutions td, table.substitutions th {
margin: 1%; margin: 1%;
width: 30%; width: 30%;
} }
.print-body table.substitutions td, .print-body table.substitutions th {
padding: 0 2px;
}
.print-body span.badge.new {
font-size: 0.9rem;
line-height: 20px;
height: 20px;
margin: 2px;
letter-spacing: 0.3pt;
}
...@@ -17,16 +17,10 @@ ...@@ -17,16 +17,10 @@
<h4>{% trans "Substitutions" %}</h4> <h4>{% trans "Substitutions" %}</h4>
</div> </div>
<div class="col s2 m6 right align-right print-icon"> <div class="col s2 m6 right align-right print-icon">
{# <a class="waves-effect waves-teal btn-flat btn-flat-medium right"#} <a class="waves-effect waves-teal btn-flat btn-flat-medium right"
{# href="#} href="{% url "substitutions_print_by_date" day.year day.month day.day "print" %}" target="_blank">
{# {% if debug %}#} <i class="material-icons center">print</i>
{# {% url "timetable_substitutions_pdf_date" date|date:"Y-m-d" %}#} </a>
{# {% else %}#}
{# {% url "timetable_substitutions_pdf" %}#}
{# {% endif %}#}
{# ">#}
{# <i class="material-icons center">print</i>#}
{# </a>#}
</div> </div>
</div> </div>
...@@ -79,7 +73,8 @@ ...@@ -79,7 +73,8 @@
</td> </td>
{% endif %} {% endif %}
{% for sub in substitutions %} {% for sub in substitutions %}
<tr class="{% if sub.type_ == "cancellation" %}green-text{% else %}black-text{% endif %}"> {# TODO: Extend support for blue and purple (supervisions and events) #} <tr class="{% if sub.type_ == "cancellation" %}green-text{% else %}black-text{% endif %}">
{# TODO: Extend support for blue and purple (supervisions and events) #}
<td> <td>
{% include "chronos/partials/groups.html" with groups=sub.lesson_period.lesson.groups.all %} {% include "chronos/partials/groups.html" with groups=sub.lesson_period.lesson.groups.all %}
</td> </td>
...@@ -102,7 +97,7 @@ ...@@ -102,7 +97,7 @@
{# TODO: Support other cases#} {# TODO: Support other cases#}
<span class="badge new green hide-on-med-and-up">{% trans "Cancelled" %}</span> <span class="badge new green hide-on-med-and-up">{% trans "Cancelled" %}</span>
{% endif %} {% endif %}
{# <em>{{ sub.text|default:"" }}</em>#} {# <em>{{ sub.text|default:"" }}</em>#}
</td> </td>
<td class="hide-on-small-and-down"> <td class="hide-on-small-and-down">
{% if sub.cancelled %} {% if sub.cancelled %}
......
{# -*- engine:django -*- #} {# -*- engine:django -*- #}
{% extends 'core/base.html' %} {% extends 'core/base_print.html' %}
{% load common %}
{% block content %} {% load i18n static %}
<script type="text/javascript">
var dest = Urls.substitutions();
</script>
<style> {% block extra_head %}
table.substitutions td, table.substitutions th { <link rel="stylesheet" href="{% static 'css/chronos/timetable.css' %}">
padding: 0 2px; {% endblock %}
}
span.badge.new { {% block browser_title %}{% blocktrans %}Print: Substitutions{% endblocktrans %}{% endblock %}
font-size: 0.9rem; {% block page_title %}{% blocktrans %}Substitutions{% endblocktrans %}{% endblock %}
line-height: 20px;
height: 20px;
margin: 2px;
letter-spacing: 0.3pt;
}
</style>
{% for c in days %}
<h4>Substitutions {{ c.date|date" }}</h4>
{% block content %}
{% for day, c in days.items %}
<h4>{% trans "Substitutions" %} {{ c.day|date:"l" }} {{ c.day }}</h4>
{% include "timetable/hintsinsubprint.html" %} {# {% include "timetable/hintsinsubprint.html" %}#}
<div style="margin-bottom: 20px"> {# <div style="margin-bottom: 20px">#}
{% if c.header_info.is_box_needed %} {# {% if c.header_info.is_box_needed %}#}
{% for row in c.header_info.rows %} {# {% for row in c.header_info.rows %}#}
<div class="row no-margin"> {# <div class="row no-margin">#}
<div class="col s3 no-padding"> {# <div class="col s3 no-padding">#}
<strong>{{ row.0 }}</strong> {# <strong>{{ row.0 }}</strong>#}
</div> {# </div>#}
<div class="col s9 no-padding"> {# <div class="col s9 no-padding">#}
{{ row.1 }} {# {{ row.1 }}#}
</div> {# </div>#}
</div> {# </div>#}
{% endfor %} {# {% endfor %}#}
{% endif %} {# {% endif %}#}
</div> {# </div>#}
<table class="substitutions"> <table class="substitutions">
<thead> <thead>
<tr> <tr>
<th><i class="material-icons">people</i></th> <th><i class="material-icons">people</i></th>
<th><i class="material-icons">access_time</i></th> <th><i class="material-icons">access_time</i></th>
<th>{% blocktrans %}Teachers{% endblocktrans %}</th> <th>{% blocktrans %}Teachers{% endblocktrans %}</th>
<th>{% blocktrans %}Subject{% endblocktrans %}</th> <th>{% blocktrans %}Subject{% endblocktrans %}</th>
<th>{% blocktrans %}Room{% endblocktrans %}</th> <th>{% blocktrans %}Room{% endblocktrans %}</th>
<th>{% blocktrans %}Hint{% endblocktrans %}</th> <th>{% blocktrans %}Notes{% endblocktrans %}</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody>
{% if not c.sub_table %}
<td colspan="7">
<p class="flow-text center">
{% blocktrans %}No existing substitutions{% endblocktrans %}
</p>
</td>
{% endif %}
{% set color_background = 1 %}
{% set last_classes = "" %}
{% for sub in c.sub_table %} {% if not c.substitutions %}
<tbody>
<tr class="striped">
<td colspan="7">
<p class="flow-text center">
{% blocktrans %}No substitutions available.{% endblocktrans %}
</p>
</td>
</tr>
</tbody>
{% endif %}
{# Color groups of classes in grey/white #} <tbody>
{% if last_classes != sub.classes %} {% for sub in c.substitutions %}
{% if color_background %}{% set color_background = 0 %} <tr class="{% if sub.type_ == "cancellation" %}green-text{% else %}black-text{% endif %} ">
{% else %}{% set color_background = 1 %} <td>
{% endif %} {% include "chronos/partials/groups.html" with groups=sub.lesson_period.lesson.groups.all %}
</td>
<td>
<strong>
{{ sub.lesson_period.period.period }}.
</strong>
</td>
<td>
{% include "chronos/partials/subs/teachers.html" %}
</td>
<td>
{% include "chronos/partials/subs/subject.html" %}
</td>
<td>
{% include "chronos/partials/subs/room.html" %}
</td>
<td>
{% if sub.cancelled %}
{# TODO: Support other cases#}
<span class="badge new green">{% trans "Cancelled" %}</span>
{% endif %} {% endif %}
{% set last_classes = sub.classes %} {# <em>{{ sub.text|default:"" }}</em>#}
</td>
</tr>
<tr class="{{ sub.color }}-text {% if color_background %}striped{% endif %}"> {% ifchanged sub.lesson_period.lesson.groups %}
<td> </tbody>
{{ sub.classes }} <tbody class="{% cycle "" "striped" %}">
</td> {% endifchanged %}
<td> {% endfor %}
<strong> </tbody>
{{ sub.lesson }}
</strong>
</td>
<td>
{% include "timetable/subs/teacher.html" %}
</td>
<td>
{% include "timetable/subs/subject.html" %}
</td>
<td>
{% include "timetable/subs/room.html" %}
</td>
<td>
{% if sub.badge %}
<span class="badge new green">{{ sub.badge }}</span>
{% endif %}
<em>{{ sub.text|default:"" }}</em>
</td>
</tr>
{% endfor %}
</tbody>
</table> </table>
{% endfor %}
{% endfor %}
{% endblock %} {% endblock %}
...@@ -22,5 +22,7 @@ urlpatterns = [ ...@@ -22,5 +22,7 @@ urlpatterns = [
name="delete_substitution", name="delete_substitution",
), ),
path("substitutions/", views.substitutions, name="substitutions"), path("substitutions/", views.substitutions, name="substitutions"),
path("substitutions/<str:is_print>/", views.substitutions, name="substitutions_print"),
path("substitutions/<int:year>/<int:month>/<int:day>/", views.substitutions, name="substitutions_by_date"), path("substitutions/<int:year>/<int:month>/<int:day>/", views.substitutions, name="substitutions_by_date"),
path("substitutions/<int:year>/<int:month>/<int:day>/<str:is_print>/", views.substitutions, name="substitutions_print_by_date"),
] ]
...@@ -18,12 +18,7 @@ from .forms import LessonSubstitutionForm ...@@ -18,12 +18,7 @@ from .forms import LessonSubstitutionForm
from .models import LessonPeriod, LessonSubstitution, TimePeriod, Room from .models import LessonPeriod, LessonSubstitution, TimePeriod, Room
from .tables import LessonsTable from .tables import LessonsTable
from .util.js import date_unix from .util.js import date_unix
from .util.min_max import ( from .util.min_max import period_min, period_max, weekday_min_, weekday_max
period_min,
period_max,
weekday_min_,
weekday_max
)
from .util.prev_next import get_next_relevant_day, get_prev_next_by_day from .util.prev_next import get_next_relevant_day, get_prev_next_by_day
from .util.weeks import CalendarWeek, get_weeks_for_year from .util.weeks import CalendarWeek, get_weeks_for_year
from aleksis.core.util.core_helpers import has_person from aleksis.core.util.core_helpers import has_person
...@@ -187,7 +182,7 @@ def timetable( ...@@ -187,7 +182,7 @@ def timetable(
context["smart"] = is_smart context["smart"] = is_smart
context["week_select"] = { context["week_select"] = {
"year": wanted_week.year, "year": wanted_week.year,
"dest": reverse("timetable", args=[type_, pk]) "dest": reverse("timetable", args=[type_, pk]),
} }
week_prev = wanted_week - 1 week_prev = wanted_week - 1
...@@ -231,7 +226,7 @@ def lessons_day( ...@@ -231,7 +226,7 @@ def lessons_day(
context["datepicker"] = { context["datepicker"] = {
"date": date_unix(wanted_day), "date": date_unix(wanted_day),
"dest": reverse("lessons_day") "dest": reverse("lessons_day"),
} }
context["url_prev"], context["url_next"] = get_prev_next_by_day( context["url_prev"], context["url_next"] = get_prev_next_by_day(
...@@ -271,8 +266,7 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse ...@@ -271,8 +266,7 @@ def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse
date = wanted_week[lesson_period.period.weekday] date = wanted_week[lesson_period.period.weekday]
return redirect( return redirect(
"lessons_day_by_date", "lessons_day_by_date", year=date.year, month=date.month, day=date.day
year=date.year, month=date.month, day=date.day
) )
context["edit_substitution_form"] = edit_substitution_form context["edit_substitution_form"] = edit_substitution_form
...@@ -293,8 +287,7 @@ def delete_substitution(request: HttpRequest, id_: int, week: int) -> HttpRespon ...@@ -293,8 +287,7 @@ def delete_substitution(request: HttpRequest, id_: int, week: int) -> HttpRespon
date = wanted_week[lesson_period.period.weekday] date = wanted_week[lesson_period.period.weekday]
return redirect( return redirect(
"lessons_day_by_date", "lessons_day_by_date", year=date.year, month=date.month, day=date.day
year=date.year, month=date.month, day=date.day
) )
...@@ -304,26 +297,60 @@ def substitutions( ...@@ -304,26 +297,60 @@ def substitutions(
year: Optional[int] = None, year: Optional[int] = None,
month: Optional[int] = None, month: Optional[int] = None,
day: Optional[int] = None, day: Optional[int] = None,
is_print: Optional[str] = None,
) -> HttpResponse: ) -> HttpResponse:
context = {} context = {}
is_print = is_print == "print"
print(is_print)
if day: if day:
wanted_day = timezone.datetime(year=year, month=month, day=day).date() wanted_day = timezone.datetime(year=year, month=month, day=day).date()
wanted_day = get_next_relevant_day(wanted_day) wanted_day = get_next_relevant_day(wanted_day)
else: else:
wanted_day = get_next_relevant_day(timezone.now().date(), datetime.now().time()) wanted_day = get_next_relevant_day(timezone.now().date(), datetime.now().time())
substitutions = LessonSubstitution.objects.on_day(wanted_day) DAY_COUNT = 2
day_contexts = {}
context["substitutions"] = substitutions if is_print:
context["day"] = wanted_day
context["datepicker"] = {
"date": date_unix(wanted_day),
"dest": reverse("substitutions")
}
context["url_prev"], context["url_next"] = get_prev_next_by_day( next_day = wanted_day
wanted_day, "substitutions_by_date" for i in range(DAY_COUNT):
) print(i, next_day)
day_contexts[next_day] = {"day": next_day}
next_day = get_next_relevant_day(next_day + timedelta(days=1))
print(day_contexts)
print(day_contexts)
else:
day_contexts = {wanted_day: {"day": wanted_day}}
print(day_contexts)
for day in day_contexts:
day_contexts[day]["substitutions"] = LessonSubstitution.objects.on_day(
day
).order_by("lesson_period__lesson__groups", "lesson_period__period")
print(day_contexts[day]["substitutions"].count(), day)
print(day_contexts)
if not is_print:
context = day_contexts[wanted_day]
context["datepicker"] = {
"date": date_unix(wanted_day),
"dest": reverse("substitutions"),
}
context["url_prev"], context["url_next"] = get_prev_next_by_day(
wanted_day, "substitutions_by_date"
)
template_name = "chronos/substitutions.html"
else:
context["days"] = day_contexts
template_name = "chronos/substitutions_print.html"
print(context)
return render(request, "chronos/substitutions.html", context) return render(request, template_name, context)
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