{% extends "base.html" %}

{% load static %}
{% load extras %}

{% block title %}Colloscope{% endblock title %}

{% block head %}
<link href="{% static 'table.css' %}" rel="stylesheet" type="text/css">
{% endblock head %}

{% block header %}
<h1>Colloscope</h1>
{% endblock header %}


{% block main %}

    <p>
    Lycée : {{ term.cls.school.description }}. Classe : {{ term.cls.description }}. <a href="dashboard.html">Retour au tableau de bord</a>
    </p>

    <h2>Colloscope : {{ term.description }}</h2>

    <form method="get" action="{% url "colloscope.table" %}">
    Changer de période&nbsp;:
        <select name="term" id="term">
            {% for p in term.cls.term_set.all %}
            {% if p.id == term.id %}
            <option value="{{ p.id }}" selected>{{ p }}</option>
            {% else %}
            <option value="{{ p.id }}" selected>{{ p }}</option>
            {% endif %}
            {% endfor %}
        </select>
        <button type="submit">Valider</button>
    </form>

    {% if request.GET.term %}
        <a href="export.pdf?term={{ request.GET.term }}" target="_blank">Exporter le colloscope</a>
    {% else %}
        <a href="export.pdf" target="_blank">Exporter le colloscope</a>
    {% endif %}

    <div class="table-wrapper">
    <table>

    <colgroup>
        <col>
        <col>
        <col>
        <col>
        <col>
    </colgroup>
    <colgroup>
    {% for _ in weeks %}
        <col>
    {% endfor %}
    </colgroup>

    <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>
    {% for n in weeks %}
    <th>{{ n }}</th>
    {% endfor %}
    </tr>

    <tr>
    {% for monday in mondays %}
        <th>{{ monday | strftime:"%d/%m/%y" }}</th>
    {% endfor %}
    </tr>


    {% for c, rs in colles %}
        <tr>
            <td>{{ c.subject.description }}</td>
            <td>{{ days | getitem:c.day }}</td>
            <td>{{ c.time | strftime:"%H:%M" }}</td>
            <td>{{ c.colleur }}</td>
            <td>{{ c.room }}</td>

            {% for sem, exists, r, is_edited, groups in rs %}
                {% if exists %}
                    {% if is_edited %}
                        <td class="modif">{{ groups | join:"," }}</td>
                    {% else %}
                        <td>{{ groups | join:"," }}</td>
                    {% endif %}
                {% else %}
                    <td></td>
                {% endif %}
            {% endfor %}
        </tr>
    {% endfor %}

    </table>
    </div>
{% endblock main %}