From d17c1152615162e33703dd67b92b64d0cbf5b63d Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 19 Jan 2017 21:55:29 +0100 Subject: Travail initial sur les vues --- templates/index.html | 20 ++++++++++++++++++++ templates/timetable.html | 16 ++++++++++++++++ urls.py | 8 ++++++++ views.py | 20 ++++++++++++++++++-- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 templates/index.html create mode 100644 templates/timetable.html create mode 100644 urls.py diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..262d454 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,20 @@ + + + + + celcatsanitizer + + +

celcatsanitizer

+ {% for timetable in timetables %} +

{{ timetable.name }}

+ + {% endfor %} + + diff --git a/templates/timetable.html b/templates/timetable.html new file mode 100644 index 0000000..23de166 --- /dev/null +++ b/templates/timetable.html @@ -0,0 +1,16 @@ + + + + + {{ timetable.name }} – {{ group.name }} – celcatsanitizer + + +

celcatsanitizer

+

{{ timetable.name }} – {{ group.name }}

+ + + diff --git a/urls.py b/urls.py new file mode 100644 index 0000000..41b61a9 --- /dev/null +++ b/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls import url, handler404 + +from . import views + +urlpatterns = [ + url(r"^$", views.index, name="index"), + url(r"^(?P[-\w]+)/(?P[-\w]+)/$", views.timetable, name="timetable"), +] diff --git a/views.py b/views.py index 91ea44a..07572e9 100644 --- a/views.py +++ b/views.py @@ -1,3 +1,19 @@ -from django.shortcuts import render +from django.http import HttpResponse +from django.shortcuts import get_object_or_404, render, render_to_response +from django.db.models import Q -# Create your views here. +from edt.models import Timetable, Group, Course + +def index(request): + timetables = Timetable.objects.all() + groups = Group.objects.filter(tp__isnull=False).order_by("name") + + return render_to_response("index.html", {"timetables": timetables, "groups": groups}) + +def timetable(request, timetable_slug, group_slug): + timetable = get_object_or_404(Timetable, slug=timetable_slug) + group = get_object_or_404(Group, slug=group_slug, timetable=timetable) + + courses = Course.objects.filter(Q(groups__td__isnull=True) | Q(groups__td=group.td), Q(groups__tp__isnull=True) | Q(groups__tp=group.tp), groups__mention=group.mention, groups__subgroup=group.subgroup).order_by("begin").distinct() + + return render_to_response("timetable.html", {"timetable": timetable, "group": group, "courses": courses}) -- cgit v1.2.1