Compare commits

...

2 Commits

4 changed files with 43 additions and 78 deletions

View File

@ -226,50 +226,27 @@ def dept_formsemestres_ids_by_id(dept_id: int):
@bp.route("/departement/<string:acronym>/formsemestres_courants")
@bp.route("/departement/id/<int:dept_id>/formsemestres_courants")
@login_required
@scodoc
@permission_required(Permission.ScoView)
@as_json
def dept_formsemestres_courants(acronym: str):
def dept_formsemestres_courants(acronym: str = "", dept_id: int | None = None):
"""
Liste des semestres actifs d'un département d'acronyme donné
Liste les semestres du département indiqué (par son acronyme ou son id)
contenant la date courante, ou à défaut celle indiquée en argument
(au format ISO).
QUERY
-----
date_courante:<string:date_courante>
Exemple de résultat :
[
{
"titre": "master machine info",
"gestion_semestrielle": false,
"scodoc7_id": null,
"date_debut": "01/09/2021",
"bul_bgcolor": null,
"date_fin": "15/12/2022",
"resp_can_edit": false,
"dept_id": 1,
"etat": true,
"resp_can_change_ens": false,
"id": 1,
"modalite": "FI",
"ens_can_edit_eval": false,
"formation_id": 1,
"gestion_compensation": false,
"elt_sem_apo": null,
"semestre_id": 1,
"bul_hide_xml": false,
"elt_annee_apo": null,
"block_moyennes": false,
"formsemestre_id": 1,
"titre_num": "master machine info semestre 1",
"date_debut_iso": "2021-09-01",
"date_fin_iso": "2022-12-15",
"responsables": [
3,
2
]
},
...
]
"""
dept = Departement.query.filter_by(acronym=acronym).first_or_404()
dept = (
Departement.query.filter_by(acronym=acronym).first_or_404()
if acronym
else Departement.query.get_or_404(dept_id)
)
date_courante = request.args.get("date_courante")
date_courante = datetime.fromisoformat(date_courante) if date_courante else None
return [
@ -278,29 +255,3 @@ def dept_formsemestres_courants(acronym: str):
dept, date_courante
)
]
@bp.route("/departement/id/<int:dept_id>/formsemestres_courants")
@login_required
@scodoc
@permission_required(Permission.ScoView)
@as_json
def dept_formsemestres_courants_by_id(dept_id: int):
"""
Liste des semestres actifs d'un département d'id donné
"""
# Le département, spécifié par un id ou un acronyme
dept = Departement.query.get_or_404(dept_id)
date_courante = request.args.get("date_courante")
if date_courante:
test_date = datetime.fromisoformat(date_courante)
else:
test_date = db.func.current_date()
# Les semestres en cours de ce département
formsemestres = FormSemestre.query.filter(
FormSemestre.dept_id == dept.id,
FormSemestre.date_debut <= test_date,
FormSemestre.date_fin >= test_date,
)
return [d.to_dict_api() for d in formsemestres]

View File

@ -564,7 +564,7 @@ def fiche_etud(etudid=None):
%(etat_civil)s
<span>%(email_link)s</span>
</td><td class="photocell">
<a href="etud_photo_orig_page?etudid=%(etudid)s">%(etudfoto)s</a>
<a href="etud_photo_orig_page/%(etudid)s">%(etudfoto)s</a>
</td></tr></table>
"""
+ situation_template

View File

@ -1018,23 +1018,21 @@ sco_publish("/get_photo_image", sco_photos.get_photo_image, Permission.ScoView)
sco_publish("/etud_photo_html", sco_photos.etud_photo_html, Permission.ScoView)
@bp.route("/etud_photo_orig_page")
@bp.route("/etud_photo_orig_page/<int:etudid>")
@scodoc
@permission_required(Permission.ScoView)
@scodoc7func
def etud_photo_orig_page(etudid=None):
def etud_photo_orig_page(etudid):
"Page with photo in orig. size"
etud = sco_etud.get_etud_info(filled=True, etudid=etudid)[0]
H = [
html_sco_header.sco_header(page_title=etud["nomprenom"]),
"<h2>%s</h2>" % etud["nomprenom"],
'<div><a href="%s">'
% url_for("scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=etudid),
sco_photos.etud_photo_orig_html(etud),
"</a></div>",
html_sco_header.sco_footer(),
]
return "\n".join(H)
etud = Identite.get_etud(etudid)
return f"""{
html_sco_header.sco_header(etudid=etud.id, page_title=etud.nomprenom)
}
<h2>{etud.nomprenom}</h2>
<div>
<a href="{etud.url_fiche()}">{etud.photo_html(size='orig')}</a>
</div>
{html_sco_header.sco_footer()}
"""
@bp.route("/form_change_photo", methods=["GET", "POST"])

View File

@ -280,3 +280,19 @@ def test_semestres_courant(api_headers):
assert len(result_a) > 0
sem = result_a[0]
assert verify_fields(sem, FORMSEMESTRE_FIELDS) is True
# accès avec id incorrect
r = requests.get(
f"{API_URL}/departement/id/bad/formsemestres_courants?date_courante=2022-07-01",
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 404
r = requests.get(
f"{API_URL}/departement/id/-1/formsemestres_courants?date_courante=2022-07-01",
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 404