Skip to content
Snippets Groups Projects
Commit 5cd2d2a4 authored by Emmanuel Viennet's avatar Emmanuel Viennet
Browse files

Pages Statistiques: prise en compte des groupes sélectionnés dans les exports excel et pdf

parent a93f5d86
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,7 @@ from app.scodoc import (
sco_report,
sco_etud,
)
from app.scodoc.sco_exceptions import ScoValueError
from app.models import FormSemestre
from app.scodoc.gen_tables import GenTable
import app.scodoc.sco_utils as scu
......@@ -180,13 +181,20 @@ def _table_etuds_lycees(etuds, group_lycees, title, preferences, no_links=False)
def formsemestre_etuds_lycees(
formsemestre_id,
group_ids: list[int] = None, # si indiqué, ne prend que ces groupes
fmt="html",
only_primo=False,
no_grouping=False,
):
"""Table des lycées d'origine"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
if request.method == "POST":
group_ids = request.form.getlist("group_ids")
else:
group_ids = request.args.getlist("group_ids")
try:
group_ids = [int(gid) for gid in group_ids]
except ValueError as exc:
raise ScoValueError("group_ids invalide") from exc
groups_infos = sco_groups_view.DisplayedGroupsInfos(
group_ids,
formsemestre_id=formsemestre.id,
......@@ -195,11 +203,17 @@ def formsemestre_etuds_lycees(
tab, etuds_by_lycee = formsemestre_table_etuds_lycees(
formsemestre, groups_infos, only_primo=only_primo, group_lycees=not no_grouping
)
tab.base_url = "%s?formsemestre_id=%s" % (request.base_url, formsemestre_id)
if only_primo:
tab.base_url += "&only_primo=1"
if no_grouping:
tab.base_url += "&no_grouping=1"
tab.base_url = (
scu.build_url_query(
request.base_url,
formsemestre_id=formsemestre.id,
no_grouping="1" if no_grouping else None,
only_primo="on" if only_primo else None,
)
+ ("&" + groups_infos.groups_query_args)
if groups_infos
else ""
)
table_html = tab.make_page(fmt=fmt, with_html_headers=False)
if fmt != "html":
return table_html
......
......@@ -800,11 +800,20 @@ def formsemestre_suivi_cohorte(
only_primo=only_primo,
)
tab.base_url = (
"%s?formsemestre_id=%s&percent=%s&bac=%s&bacspecialite=%s&civilite=%s"
% (request.base_url, formsemestre.id, percent, bac, bacspecialite, civilite)
scu.build_url_query(
request.base_url,
bac=bac,
bacspecialite=bacspecialite,
civilite=civilite,
formsemestre_id=formsemestre.id,
percent=percent,
only_primo="on" if only_primo else None,
)
if only_primo:
tab.base_url += "&only_primo=on"
+ ("&" + groups_infos.groups_query_args)
if groups_infos
else ""
)
t = tab.make_page(fmt=fmt, with_html_headers=False)
if fmt != "html":
return t
......@@ -1806,9 +1815,16 @@ def formsemestre_graph_cursus(
% sem,
f"""(<a href="{
url_for("notes.formsemestre_graph_cursus", fmt="pdf", **url_kw)
+ ("&" + groups_infos.groups_query_args)
if groups_infos
else ""
}">version pdf</a>,
<a href="{
url_for("notes.formsemestre_graph_cursus", fmt="png", **url_kw)}">image PNG</a>)
url_for("notes.formsemestre_graph_cursus", fmt="png", **url_kw)
+ ("&" + groups_infos.groups_query_args)
if groups_infos
else ""
}">image PNG</a>)
</p>
<p class="help">Le graphe permet de suivre les étudiants inscrits dans le semestre
......
......@@ -912,11 +912,11 @@ def unescape_html(s):
def build_url_query(url: str, **params) -> str:
"""Add parameters to existing url, as a query string"""
"""Add parameters to existing url, as a query string. Eliminate None values."""
url_parse = urlparse(url)
query = url_parse.query
url_dict = dict(parse_qsl(query))
url_dict.update(params)
url_dict.update({k: v for k, v in params.items() if v is not None})
url_new_query = urlencode(url_dict)
url_parse = url_parse._replace(query=url_new_query)
new_url = urlunparse(url_parse)
......
......@@ -29,4 +29,5 @@ Page non fonctionnelle dans cette version (modif. API Google)
<script src="{{scu.STATIC_DIR}}/libjs/jquery.ui.map.full.min.js"></script>
<script src="https://maps.google.com/maps/api/js"></script>
<script src="{{scu.STATIC_DIR}}/js/map_lycees.js"></script>
<script src="{{scu.STATIC_DIR}}/js/groups_view.js"></script>
{% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment