colloscope web

This commit is contained in:
Valentin Moguérou 2024-04-16 13:54:00 +02:00
parent e7dbcafa7f
commit 3483ce62c8
9 changed files with 230 additions and 121 deletions

View File

@ -13,11 +13,13 @@ calendrier = {
]
}
class Lycee(models.Model):
uai = models.CharField(max_length=10)
libelle = models.CharField(max_length=100)
vacances = models.CharField(max_length=1)
class Classe(models.Model):
lycee = models.ForeignKey(Lycee, on_delete=models.CASCADE)
libelle = models.CharField(max_length=20)

View File

@ -3,83 +3,7 @@ from datetime import date, timedelta
from colloscope.models import *
from fpdf import FPDF
from fpdf.fonts import FontFace
from fpdf.enums import TableCellFillMode
"""
etudiants = [
['Aboujaib', 'Alexandre', 4, 'A', '', ''],
['Ajan', 'George', 4, 'A', '', ''],
['Akrad', 'Lina', 1, 'SI', '', ''],
['Aubert', 'Nicolas', 1, 'SI', '', ''],
['Badr', 'Roman', 4, 'A', '', ''],
['Bazire', 'Aurélien', 5, 'A', '', ''],
['Boit', 'Arthur', 5, 'A', '', ''],
['Boubker', 'Youssef', 5, 'A', '', ''],
['Boudjema', 'Dylan', 1, 'SI', '', ''],
['Chiriac', 'Mihnea', 6, 'A', '', ''],
['Courier', 'Marine', 6, 'A', '', ''],
['Daguin', 'Joseph', 6, 'A', '', ''],
['Dauguen', 'Gabriel', 7, 'A', '', ''],
['De Weer', 'Matthias', 7, 'A', '', ''],
['Desbouis', 'Katell', 2, 'SI', '', ''],
['Dupouy', 'Jérémie', 7, 'A', '', ''],
['Hariri--Gautier-Picard', 'Grégoire', 8, 'A', '', ''],
['Juricevic', 'Matteo', 8, 'A', '', ''],
['Knanoua', 'Anas', 8, 'A', '', ''],
['Lesenne', 'Pierrick', 9, 'A', '', ''],
['Lin', 'Hao', 2, 'SI', '', ''],
['Masbatin', 'Lucas', 2, 'SI', '', ''],
['Mayuran', 'Mithushan', 9, 'A', '', ''],
['Messahli', 'Yassine', 9, 'A', '', ''],
['Moguérou', 'Valentin', 10, 'B', '', ''],
['Mohellebi', 'Mathéo', 10, 'B', '', ''],
['Mouisset--Ferrara', 'Maël', 10, 'B', '', ''],
['Ottavi', 'Corentin', 11, 'B', '', ''],
['Ponce', 'Alexian', 11, 'B', '', ''],
['Pujol', 'Raphaël', 11, 'B', '', ''],
['Pustetto', 'Mathis', 12, 'B', '', ''],
['Radice', 'Roman', 12, 'B', '', ''],
['Rat', 'Evelyn', 12, 'B', '', ''],
['Rousse', 'Louis', 3, 'SI', '', ''],
['Roux', 'Gaëtan', 3, 'SI', '', ''],
['Rouyre--Cros', 'Célian', 3, 'SI', '', ''],
['Sourbé', 'François-Gabriel', 13, 'B', '', ''],
['Stourbe', 'Simon', 13, 'B', '', ''],
['Thai', 'Dany', 13, 'B', '', ''],
['Théodore', 'Jonathan', 14, 'B', '', ''],
['Vandroux', 'Benoît', 14, 'B', '', ''],
['Veyssière', 'Thibaud', 14, 'B', '', ''],
['Vié', 'Adrien', 15, 'B', '', ''],
['Ye', 'Luan', 15, 'B', '', ''],
['Zarka', 'Amélie', 15, 'B', '', ''],
]
"""
creneaux = [
["Mathématiques", "vendredi", "17:00", "M. OUBAHA", "C382"],
["Anglais", "mercredi", "14:00", "Mme LE GOURIELLEC", "C393"],
["Mathématiques", "mercredi", "15:00", "M. BOULLY", "R004"],
["Physique", "mardi", "14:00", "Mme CHEVALIER", "R103"],
["Mathématiques", "mardi", "18:00", "M. RAPIN", "V152"],
["Anglais", "mardi", "14:00", "Mme BELAGGOUNE", "C4??"],
["pas de colle", "", "", "", ""],
["Physique", "mardi", "17:00", "M. COLIN", "C386"],
["Mathématiques", "mercredi", "13:30", "M. BOUVEROT", "??"],
["Anglais", "lundi", "13:00", "M. HERBAUT", "V052"],
]
semaines = list(range(24, 34))
rotations = [
# [semaine, groupe, creneau]
(24, 1, 1),
(24, 2, 2),
(24, 3, 3),
(27, 3, 3),
(28, 3, 3),
(31, 3, 3),
]
class PDF(FPDF):
def liste_eleves(self, periode):

59
colloscope/table.py Normal file
View File

@ -0,0 +1,59 @@
from colloscope.models import *
def table_colloscope(periode, heading=True, est_colle=True):
semaines = periode.range_semaines()
lundis = [ periode.classe.date_debut_sem(n) for n in semaines ]
creneaux = Creneau.objects.filter(periode=periode, est_colle=est_colle)
jours = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"]
s = ""
s += "<table>\n"
if heading:
s += "<tr>\n"
for th in ("Matière", "Jour", "Heure", "Colleur", "Salle"):
s += f"<th rowspan=2>{th}</th>\n"
for sem in semaines:
s +=f"<th>{sem}</th>\n"
s += "</tr>\n<tr>\n"
for lundi in lundis:
s += f"<th>{lundi.strftime('%d/%m/%y')}</th>\n"
s += "</tr>\n"
for i, c in enumerate(creneaux):
matiere = c.matiere
jour = c.jour
heure = c.heure
colleur = c.colleur
salle = c.salle
s += "<tr>\n"
s += f"<td>{matiere.libelle}</td>\n"
s += f"<td>{jours[jour]}</td>\n"
s += f"<td>{heure.strftime('%H:%M')}</td>\n"
s += "<td>{} {}</td>\n".format("M." if colleur.civilite=="M" else "Mme", colleur.nom.upper())
s += f"<td>salle</td>\n"
for sem in semaines:
if Rotation.objects.filter(creneau=c, semaine=sem).exists():
r = Rotation.objects.get(creneau=c, semaine=sem)
groupes = r.groupes
content = ", ".join(g.libelle for g in groupes.all())
if r.est_modifiee():
s += f"<td class='modif'>{content}</td>\n"
else:
s += f"<td>{content}</td>\n"
else:
s += "<td></td>\n"
s += "</table>\n"
return s

View File

@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block title %}Erreur 404{% endblock title %}
{% block header %}
<h1>404 : GAME OVER</h1>
{% endblock header %}
{% block main %}
Vous vous êtes perdu.
{% endblock main %}

View File

@ -0,0 +1,21 @@
{% load static %}
<!DOCTYPE html>
<html lang="fr-fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}{% endblock title %}</title>
<link href="{% static 'main.css' %}" rel="stylesheet" type="text/css">
{% block head %}{% endblock head %}
</head>
<body>
<header>
{% block header %}{% endblock header %}
</header>
<main>
{% block main %}{% endblock main %}
</main>
<footer>
{% block footer %}&copy; UKS 2024{% endblock footer %}
</footer>
</body>

View File

@ -1,52 +1,72 @@
{% load static %}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Colloscope</title>
<link href="{% static 'main.css' %}" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<h1>Universal Kholloscope Systems&#8482;</h1>
{% extends "base.html" %}
<nav class="semaine">
<span class="select">&lt;</span>
<span class="label">Semaine : du 22 au 26 avril 2024.</span>
<span class="select">&gt;</span>
</nav>
{% load extras %}
</header>
{% block title %}Colloscope{% endblock title %}
<main>
<h2>Programme de colles</h2>
<p class="programme">
Mathématiques&nbsp;: Dimension finie et matrices
</p>
<p class="programme">
Physique&nbsp;: Mécanique du solide
</p>
{% block header %}
<h1>Colloscope</h1>
{% endblock header %}
<h2>
Colles cette semaine
</h2>
<ul>
<li>Groupe 1 : Physique dimanche 23h Newton</li>
<li>Groupe 2 : Maths dimanche 23h Euler</li>
<li>Groupe 3 : Anglais dimanche 23h Shakespeare</li>
<li>Groupe 4 : Informatique dimanche 23h Turing</li>
<li>Groupe 5 : Histoire dimanche 23h Tite-Live</li>
<li>Groupe 6 : Philosophie dimanche 23h Descartes</li>
<li>Groupe 7 : EPS dimanche 23h Bolt</li>
</ul>
{% block main %}
</main>
<p>
Lycée : {{ periode.classe.lycee.libelle }}. Classe : {{ periode.classe.libelle }}.
</p>
<footer>
&copy; UKS 2024
</footer>
</body>
</html>
<h2>Colloscope : {{ periode.libelle }}</h2>
<table>
<tr>
<th rowspan=2>Matière</th>
<th rowspan=2>Jour</th>
<th rowspan=2>Heure</th>
<th rowspan=2>Colleur</th>
<th rowspan=2>Salle</th>
</tr>
<tr>
{% for lundi in lundis %}
<th>{{ lundi | strftime:"%d/%m/%y" }}</th>
{% endfor %}
</tr>
{% for c, rs in rotations %}
<tr>
<td>{{ c.matiere.libelle }}</td>
<td>{{ jours | getitem:c.jour }}</td>
<td>{{ c.heure | strftime:"%H:%M" }}</td>
<td>
{% if c.colleur.civilite == "M" %}
M.
{% else %}
Mme
{% endif %}
{{ c.colleur.nom | upper }}
</td>
<td>
{{ c.salle }}
</td>
{% for sem, exists, r, est_modifiee, groupes in rs %}
{% if exists %}
{% if est_modifiee %}
<td class="modif">{{ groupes | join:"," }}</td>
{% else %}
<td>{{ groupes | join:"," }}</td>
{% endif %}
{% else %}
<td></td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>
{% endblock main %}

View File

View File

@ -0,0 +1,24 @@
from django import template
from colloscope.models import *
register = template.Library()
@register.filter(name="strftime")
def strftime(value, arg):
return value.strftime(arg)
@register.filter(name="getitem")
def getitem(indexable, i):
return indexable[i]
"""
@register.filter(name="exists")
def exists(queryset):
return queryset.exists()
"""
"""
@register.filter(name="est_modifiee")
def est_modifiee(rotation):
return rotation.est_modifiee()
"""

View File

@ -1,10 +1,58 @@
from django.http import HttpResponse
from django.template import loader
from colloscope.models import *
from colloscope.table import table_colloscope
from colloscope.pdfexport import main # /!\ temporaire
def handler404(request):
template = loader.get_template("404.html")
response.status_code = 404
context = {}
return HttpResponse(template.render(context, response))
def colloscope(request):
periode_str = request.GET.get("periode", "")
if periode_str=="":
periode = Periode.objects.get(id=3)
else:
try:
periode = Periode.objects.get(id=int(periode_str))
except Periode.DoesNotExist:
template = loader.get_template("404.html")
context = {}
response = HttpResponse(template.render(context, request))
response.status_code = 404
return response
creneaux = Creneau.objects.filter(periode=periode, est_colle=True)
semaines = periode.range_semaines()
rotations = [ (c, []) for c in creneaux ]
for c, l in rotations:
for sem in semaines:
rot = Rotation.objects.filter(creneau=c, semaine=sem)
exists = rot.exists()
if exists:
r = rot.first()
est_modifiee = r.est_modifiee()
groupes = (g.libelle for g in r.groupes.all())
else:
r = est_modifiee = groupes = None
l.append((sem, exists, r, est_modifiee, groupes))
template = loader.get_template("colloscope.html")
return HttpResponse(template.render())
context = {
"periode": periode,
"lundis": [periode.classe.date_debut_sem(n) for n in semaines ],
"jours" : ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
"rotations" : rotations
}
return HttpResponse(template.render(context, request))
def export(request):
return HttpResponse(bytes(main().output()), content_type="application/pdf")