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

Include print view for substitutions with SchoolApps template

Close #60
parent 23287f7e
No related branches found
No related tags found
1 merge request!34Include print view for substitutions
......@@ -96,3 +96,15 @@ table.substitutions td, table.substitutions th {
margin: 1%;
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 @@
<h4>{% trans "Substitutions" %}</h4>
</div>
<div class="col s2 m6 right align-right print-icon">
{# <a class="waves-effect waves-teal btn-flat btn-flat-medium right"#}
{# href="#}
{# {% if debug %}#}
{# {% url "timetable_substitutions_pdf_date" date|date:"Y-m-d" %}#}
{# {% else %}#}
{# {% url "timetable_substitutions_pdf" %}#}
{# {% endif %}#}
{# ">#}
{# <i class="material-icons center">print</i>#}
{# </a>#}
<a class="waves-effect waves-teal btn-flat btn-flat-medium right"
href="{% url "substitutions_print_by_date" day.year day.month day.day "print" %}" target="_blank">
<i class="material-icons center">print</i>
</a>
</div>
</div>
......@@ -79,7 +73,8 @@
</td>
{% endif %}
{% 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>
{% include "chronos/partials/groups.html" with groups=sub.lesson_period.lesson.groups.all %}
</td>
......@@ -102,7 +97,7 @@
{# TODO: Support other cases#}
<span class="badge new green hide-on-med-and-up">{% trans "Cancelled" %}</span>
{% endif %}
{# <em>{{ sub.text|default:"" }}</em>#}
{# <em>{{ sub.text|default:"" }}</em>#}
</td>
<td class="hide-on-small-and-down">
{% if sub.cancelled %}
......
{# -*- engine:django -*- #}
{% extends 'core/base.html' %}
{% load common %}
{% extends 'core/base_print.html' %}
{% block content %}
<script type="text/javascript">
var dest = Urls.substitutions();
</script>
{% load i18n static %}
<style>
table.substitutions td, table.substitutions th {
padding: 0 2px;
}
{% block extra_head %}
<link rel="stylesheet" href="{% static 'css/chronos/timetable.css' %}">
{% endblock %}
span.badge.new {
font-size: 0.9rem;
line-height: 20px;
height: 20px;
margin: 2px;
letter-spacing: 0.3pt;
}
</style>
{% block browser_title %}{% blocktrans %}Print: Substitutions{% endblocktrans %}{% endblock %}
{% block page_title %}{% blocktrans %}Substitutions{% endblocktrans %}{% endblock %}
{% 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">
{% if c.header_info.is_box_needed %}
{% for row in c.header_info.rows %}
<div class="row no-margin">
<div class="col s3 no-padding">
<strong>{{ row.0 }}</strong>
</div>
<div class="col s9 no-padding">
{{ row.1 }}
</div>
</div>
{% endfor %}
{% endif %}
</div>
{# <div style="margin-bottom: 20px">#}
{# {% if c.header_info.is_box_needed %}#}
{# {% for row in c.header_info.rows %}#}
{# <div class="row no-margin">#}
{# <div class="col s3 no-padding">#}
{# <strong>{{ row.0 }}</strong>#}
{# </div>#}
{# <div class="col s9 no-padding">#}
{# {{ row.1 }}#}
{# </div>#}
{# </div>#}
{# {% endfor %}#}
{# {% endif %}#}
{# </div>#}
<table class="substitutions">
<thead>
<tr>
<th><i class="material-icons">people</i></th>
<th><i class="material-icons">access_time</i></th>
<th>{% blocktrans %}Teachers{% endblocktrans %}</th>
<th>{% blocktrans %}Subject{% endblocktrans %}</th>
<th>{% blocktrans %}Room{% endblocktrans %}</th>
<th>{% blocktrans %}Hint{% endblocktrans %}</th>
<th></th>
</tr>
</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 = "" %}
<thead>
<tr>
<th><i class="material-icons">people</i></th>
<th><i class="material-icons">access_time</i></th>
<th>{% blocktrans %}Teachers{% endblocktrans %}</th>
<th>{% blocktrans %}Subject{% endblocktrans %}</th>
<th>{% blocktrans %}Room{% endblocktrans %}</th>
<th>{% blocktrans %}Notes{% endblocktrans %}</th>
<th></th>
</tr>
</thead>
{% 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 #}
{% if last_classes != sub.classes %}
{% if color_background %}{% set color_background = 0 %}
{% else %}{% set color_background = 1 %}
{% endif %}
<tbody>
{% for sub in c.substitutions %}
<tr class="{% if sub.type_ == "cancellation" %}green-text{% else %}black-text{% endif %} ">
<td>
{% 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 %}
{% set last_classes = sub.classes %}
{# <em>{{ sub.text|default:"" }}</em>#}
</td>
</tr>
<tr class="{{ sub.color }}-text {% if color_background %}striped{% endif %}">
<td>
{{ sub.classes }}
</td>
<td>
<strong>
{{ 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>
{% ifchanged sub.lesson_period.lesson.groups %}
</tbody>
<tbody class="{% cycle "" "striped" %}">
{% endifchanged %}
{% endfor %}
</tbody>
</table>
{% endfor %}
{% endfor %}
{% endblock %}
......@@ -22,5 +22,7 @@ urlpatterns = [
name="delete_substitution",
),
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>/<str:is_print>/", views.substitutions, name="substitutions_print_by_date"),
]
......@@ -298,26 +298,48 @@ def substitutions(
year: Optional[int] = None,
month: Optional[int] = None,
day: Optional[int] = None,
is_print: Optional[str] = None,
) -> HttpResponse:
context = {}
is_print = is_print == "print"
if day:
wanted_day = timezone.datetime(year=year, month=month, day=day).date()
wanted_day = get_next_relevant_day(wanted_day)
else:
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
context["day"] = wanted_day
context["datepicker"] = {
"date": date_unix(wanted_day),
"dest": reverse("substitutions")
}
if is_print:
next_day = wanted_day
for i in range(DAY_COUNT):
day_contexts[next_day] = {"day": next_day}
next_day = get_next_relevant_day(next_day + timedelta(days=1))
else:
day_contexts = {wanted_day: {"day": wanted_day}}
for day in day_contexts:
day_contexts[day]["substitutions"] = LessonSubstitution.objects.on_day(
day
).order_by("lesson_period__lesson__groups", "lesson_period__period")
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"
)
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"
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