diff --git a/app/__init__.py b/app/__init__.py
index f8ccff6..ddb4f6a 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -4,7 +4,6 @@ import time
from flask import current_app, g, render_template, request
from flask import Flask
-from scodoc.api import APIError, ScoDocAuthError
from config import DevConfig
@@ -48,6 +47,8 @@ def handle_sco_auth_error(exc):
def create_app(config_class=DevConfig):
+ from scodoc.api import APIError, ScoDocAuthError
+
app = Flask(__name__, static_url_path="/AutoSco/static", static_folder="static")
app.config.from_object(config_class)
app.wsgi_app = ReverseProxied(app.wsgi_app)
diff --git a/app/static/logo.png b/app/static/logo.png
new file mode 100644
index 0000000..f6fb69d
Binary files /dev/null and b/app/static/logo.png differ
diff --git a/app/templates/base.j2 b/app/templates/base.j2
index 9c70348..297619e 100644
--- a/app/templates/base.j2
+++ b/app/templates/base.j2
@@ -13,9 +13,27 @@
{%- endblock styles %}
@@ -23,6 +41,11 @@
{% block body -%}
+ {%- block app_header %}
+
+
+
+ {%- endblock app_header %}
{% block navbar %}
{%- endblock navbar %}
{% block content -%}
diff --git a/app/templates/formsemestre_description.j2 b/app/templates/formsemestre_description.j2
index 2a42f18..a2b7ae3 100644
--- a/app/templates/formsemestre_description.j2
+++ b/app/templates/formsemestre_description.j2
@@ -5,13 +5,6 @@
{{super()}}
+{% endblock %}
+
{% block content %}
-AutoSco - Accueil
-
+Cours ouverts
{% for sem in sems %}
-
- {{sem.date_debut}} :
+ {{sem.titre}}
+
cours du {{sem.date_debut}} au {{sem.date_fin}}
+
+ {% if sem.descr.date_fin_inscriptions is not none %}
+
fermeture des inscriptions le {{sem.descr.date_fin_inscriptions|format_date}}
+ {% endif %}
+
+ {% if sem.autosco.inscription_autorisee %}
+
+ {% if sem.autosco.nb_dispo is not none %}
+
{{ sem.autosco.nb_dispo }} places disponibles :
+ {% endif %}
+
+ s'inscrire
+
+
+ {% endif %}
+
{% endfor %}
diff --git a/app/views/views.py b/app/views/views.py
index d6fa342..eab0dc4 100644
--- a/app/views/views.py
+++ b/app/views/views.py
@@ -11,17 +11,18 @@ from scodoc import api
@bp.route("/")
def index():
annee_scolaire = scu.annee_scolaire()
- sems = api.get(f"/formsemestres/query?annee_scolaire={annee_scolaire}")
- # nb: l'utilisaton de l'API départementale permet de n'avoir
+ sems = api.get(f"/formsemestres/with_description/query?annee_scolaire={annee_scolaire}")
+ # nb: l'utilisation de l'API départementale permet de n'avoir
# que les semestres du département configuré.
+ # Ne retient que les semestres ayant une description et étant visibles
+ sems = [ s for s in sems if s["autosco"] and s["autosco"]["visible"] ]
return render_template("index.j2", sems=sems)
@bp.route("/formdescription/")
def formsemestre_description(formsemestre_id:int):
"""Page description d'un formsemestre (=d'un cours)"""
- sem = api.get(f"/formsemestre/{formsemestre_id}")
- sem["descr"] = api.get(f"/formsemestre/{formsemestre_id}/description")
+ sem = api.get(f"/formsemestre/{formsemestre_id}/with_description")
return render_template("formsemestre_description.j2", sem=sem)
@bp.route("/formsemestre//description/photo_ens")
@@ -38,3 +39,8 @@ def formsemestre_get_photo_ens(formsemestre_id: int):
r = make_response(response.content)
r.headers["Content-Type"] = content_type
return r
+
+@bp.route("/formsemestre//inscription")
+def formsemestre_inscription(formsemestre_id: int):
+ """Formulaire d'auto-inscription étudiant"""
+ return "Formulaire d'auto-inscription étudiant" # TODO
\ No newline at end of file
diff --git a/autosco.py b/autosco.py
index 9339241..ec1a6e9 100755
--- a/autosco.py
+++ b/autosco.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""Application Flask: AutoSco"""
-import os
+import datetime
from pprint import pprint as pp
import click
@@ -44,6 +44,15 @@ def make_shell_context():
"pp": pp,
}
+
+@app.template_filter()
+def format_date(value:str|datetime.datetime):
+ """Format a date dd/mm/yyyy"""
+ if isinstance(value, str):
+ value = datetime.datetime.fromisoformat(value)
+ return value.strftime("%d/%m/%Y")
+
+
# Start using:
# flask run -p 5001 --host 0.0.0.0 --debug
diff --git a/scodoc/api.py b/scodoc/api.py
index 1e16f2b..0629a83 100644
--- a/scodoc/api.py
+++ b/scodoc/api.py
@@ -3,7 +3,10 @@
import os
import requests
+
from flask import current_app
+
+from app import log
import config
@@ -22,12 +25,17 @@ class ScoDocAuthError(APIError):
def get_auth_headers(user: str, password: str, conf: config.Config) -> dict:
"Demande de jeton, dict à utiliser dans les en-têtes de requêtes http"
- ans = requests.post(
- conf["API_URL"] + "/tokens",
- auth=(user, password),
- timeout=conf["API_TIMEOUT"],
- )
+ try:
+ ans = requests.post(
+ conf["API_URL"] + "/tokens",
+ auth=(user, password),
+ timeout=conf["API_TIMEOUT"],
+ )
+ except requests.exceptions.ConnectionError as exc:
+ log(f"get_auth_headers: error: user={user}, url='{conf['API_URL']}/tokens'")
+ raise ScoDocAuthError(f"Impossible de se connecter à ScoDoc: problème de configuration?", exc)
if ans.status_code != 200:
+ log(f"get_auth_headers: error: user={user}, answer status={ans.status_code}")
raise ScoDocAuthError(f"Echec demande jeton par {user}", status_code=ans.status_code)
token = ans.json()["token"]
return {"Authorization": f"Bearer {token}"}