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

Make quick launch usable

- Add a links to quick launch
- Update url schemas for timetable to remove the need of get params
- Add i18n and reformat
parent 6c208952
No related branches found
No related tags found
1 merge request!31Biscuit merge. Closes #53.
......@@ -139,6 +139,13 @@ class LessonPeriodQuerySet(models.QuerySet):
if query_data.get("room", None):
return self.filter_room(int(query_data["room"]))
def filter_from_type(self, type_: str, pk: int):
if type_ == "group":
return self.filter_group(pk)
elif type == "teacher":
return self.filter_teacher(pk)
else:
return self.filter_room(pk)
class TimePeriod(models.Model):
WEEKDAY_CHOICES = [
......
{% extends 'core/base.html' %}
{% load i18n %}
<style type="text/css"> {# TODO: Have to be moved to head if there is a block header in core #}
.btn-timetable-quicklaunch {
margin: 1%;
width: 30%;
}
</style>
{% block page_title %}{% trans "All timetables" %}{% endblock %}
{% block content %}
<h4>Alle Pläne</h4>
<div class="row">
<div class="col s12 m4">
<h5>Lehrkräfte</h5>
{% for teacher in teachers %}
{# <a class="waves-effect waves-light btn btn-timetable-quicklaunch"#}
{# href="{% url 'timetable_smart_plan' 'teacher' teacher.id %}">#}
{{ teacher.short_name }}
{# </a><!-- Shortcode -->#}
{% endfor %}
</div>
<div class="col s12 m4">
<h5>Klassen</h5>
{% for class in classes %}
{# <a class="waves-effect waves-light btn btn-timetable-quicklaunch"#}
{# href="{% url 'timetable_smart_plan' 'class' class.id %}">#}
{{ class.short_name }}
{# </a>#}
{% endfor %}
</div>
<div class="col s12 m4">
<h5>Räume</h5>
{% for room in rooms %}
{# <a class="waves-effect waves-light btn btn-timetable-quicklaunch"#}
{# href="{% url 'timetable_smart_plan' 'room' room.id %}">#}
{{ room.short_name }}
{# </a>#}
{% endfor %}
</div>
<div class="row">
<div class="col s12 m4">
<h5>{% trans "Teachers" %}</h5>
{% for teacher in teachers %}
<a class="waves-effect waves-light btn btn-timetable-quicklaunch"
href="{% url 'timetable' 'teacher' teacher.pk %}">
{{ teacher.short_name }}
</a>
{% endfor %}
</div>
<div class="col s12 m4">
<h5>{% trans "Classes" %}</h5>
{% for class in classes %}
<a class="waves-effect waves-light btn btn-timetable-quicklaunch"
href="{% url 'timetable' 'group' class.id %}">
{{ class.short_name }}
</a>
{% endfor %}
</div>
<div class="col s12 m4">
<h5>{% trans "Rooms" %}</h5>
{% for room in rooms %}
<a class="waves-effect waves-light btn btn-timetable-quicklaunch"
href="{% url 'timetable' 'room' room.id %}">
{{ room.short_name }}
</a>
{% endfor %}
</div>
</div>
{% endblock %}
......
......@@ -3,9 +3,9 @@ from django.urls import path
from . import views
urlpatterns = [
path("timetable", views.timetable, name="timetable"),
path("timetable/<str:_type>/<int:pk>", views.timetable, name="timetable"),
path("all_timetables", views.all, name="all_timetables"),
path("timetable/<int:year>/<int:week>", views.timetable, name="timetable_by_week"),
path("timetable/<str:_type>/<int:pk>/<int:year>/<int:week>", views.timetable, name="timetable_by_week"),
path("lessons", views.lessons_day, name="lessons_day"),
path("lessons/<when>", views.lessons_day, name="lessons_day_by_date"),
path(
......
......@@ -39,7 +39,7 @@ def all(request: HttpRequest) -> HttpResponse:
@login_required
def timetable(
request: HttpRequest, year: Optional[int] = None, week: Optional[int] = None
request: HttpRequest, _type: str, pk: int, year: Optional[int] = None, week: Optional[int] = None
) -> HttpResponse:
context = {}
......@@ -51,21 +51,22 @@ def timetable(
lesson_periods = LessonPeriod.objects.in_week(wanted_week)
# Incrementally filter lesson periods by GET parameters
if (
request.GET.get("group", None)
or request.GET.get("teacher", None)
or request.GET.get("room", None)
):
lesson_periods = lesson_periods.filter_from_query(request.GET)
else:
# Redirect to a selected view if no filter provided
if request.user.person:
if request.user.person.primary_group:
return redirect(
reverse("timetable") + "?group=%d" % request.user.person.primary_group.pk
)
elif lesson_periods.filter(lesson__teachers=request.user.person).exists():
return redirect(reverse("timetable") + "?teacher=%d" % request.user.person.pk)
# if (
# request.GET.get("group", None)
# or request.GET.get("teacher", None)
# or request.GET.get("room", None)
# ):
lesson_periods = lesson_periods.filter_from_type(_type, pk)
# else:
# # Redirect to a selected view if no filter provided
# if request.user.person:
# if request.user.person.primary_group:
# return redirect(
# reverse("timetable") + "?group=%d" % request.user.person.primary_group.pk
# )
# elif lesson_periods.filter(lesson__teachers=request.user.person).exists():
# return redirect(reverse("timetable") + "?teacher=%d" % request.user.person.pk)
# Regroup lesson periods per weekday
per_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