Preferences OK

This commit is contained in:
Emmanuel Viennet 2021-08-11 11:53:20 +02:00
parent 055dcfea36
commit 846bdfa8d8
6 changed files with 47 additions and 25 deletions

View File

@ -701,8 +701,17 @@ var {field}_as = new bsn.AutoSuggest('{field}', {field}_opts);
labels = descr.get( labels = descr.get(
"labels", descr.get("allowed_values", ["oui", "non"]) "labels", descr.get("allowed_values", ["oui", "non"])
) )
R.append(labels[int(self.values[field])]) _val = self.values[field]
if int(self.values[field]): if isinstance(_val, bool):
bool_val = 1 if _val else 0
elif _val == "False":
bool_val = 0
elif _val:
bool_val = 1
else:
bool_val = 0
R.append(labels[bool_val])
if bool_val:
R.append('<input type="hidden" name="%s" value="1"/>' % field) R.append('<input type="hidden" name="%s" value="1"/>' % field)
else: else:
labels = descr.get("labels", descr["allowed_values"]) labels = descr.get("labels", descr["allowed_values"])

View File

@ -1600,9 +1600,9 @@ def formsemestre_edit_uecoefs(context, formsemestre_id, err_ue_id=None, REQUEST=
cnx, args={"formsemestre_id": formsemestre_id, "ue_id": ue["ue_id"]} cnx, args={"formsemestre_id": formsemestre_id, "ue_id": ue["ue_id"]}
) )
if coefs: if coefs:
initvalues["ue_" + ue["ue_id"]] = coefs[0]["coefficient"] initvalues["ue_" + str(ue["ue_id"])] = coefs[0]["coefficient"]
else: else:
initvalues["ue_" + ue["ue_id"]] = "auto" initvalues["ue_" + str(ue["ue_id"])] = "auto"
descr = { descr = {
"size": 10, "size": 10,
"title": ue["acronyme"], "title": ue["acronyme"],
@ -1610,7 +1610,7 @@ def formsemestre_edit_uecoefs(context, formsemestre_id, err_ue_id=None, REQUEST=
} }
if ue["ue_id"] == err_ue_id: if ue["ue_id"] == err_ue_id:
descr["dom_id"] = "erroneous_ue" descr["dom_id"] = "erroneous_ue"
form.append(("ue_" + ue["ue_id"], descr)) form.append(("ue_" + str(ue["ue_id"]), descr))
tf = TrivialFormulator( tf = TrivialFormulator(
REQUEST.URL0, REQUEST.URL0,
@ -1632,7 +1632,7 @@ def formsemestre_edit_uecoefs(context, formsemestre_id, err_ue_id=None, REQUEST=
ue_modified = [] ue_modified = []
msg = [] msg = []
for ue in ues: for ue in ues:
val = tf[2]["ue_" + ue["ue_id"]] val = tf[2]["ue_" + str(ue["ue_id"])]
coefs = sco_formsemestre.formsemestre_uecoef_list( coefs = sco_formsemestre.formsemestre_uecoef_list(
cnx, args={"formsemestre_id": formsemestre_id, "ue_id": ue["ue_id"]} cnx, args={"formsemestre_id": formsemestre_id, "ue_id": ue["ue_id"]}
) )

View File

@ -229,7 +229,8 @@ def formsemestre_ext_edit_ue_validations(
descr = _ue_form_description(context, ue_list, REQUEST.form) descr = _ue_form_description(context, ue_list, REQUEST.form)
if REQUEST and REQUEST.method == "GET": if REQUEST and REQUEST.method == "GET":
initvalues = { initvalues = {
"note_" + ue["ue_id"]: ue["validation"].get("moy_ue", "") for ue in ue_list "note_" + str(ue["ue_id"]): ue["validation"].get("moy_ue", "")
for ue in ue_list
} }
else: else:
initvalues = {} initvalues = {}
@ -326,11 +327,11 @@ def _ue_form_description(context, ue_list, values):
for ue in ue_list: for ue in ue_list:
# Menu pour code validation UE: # Menu pour code validation UE:
# Ne propose que ADM, CMP et "Non inscrit" # Ne propose que ADM, CMP et "Non inscrit"
select_name = "valid_" + ue["ue_id"] select_name = "valid_" + str(ue["ue_id"])
menu_code_UE = """<select class="ueext_valid_select" name="%s">""" % ( menu_code_UE = """<select class="ueext_valid_select" name="%s">""" % (
select_name, select_name,
) )
cur_value = values.get("valid_" + ue["ue_id"], False) cur_value = values.get("valid_" + str(ue["ue_id"]), False)
for code in _UE_VALID_CODES: for code in _UE_VALID_CODES:
if cur_value is False: # pas dans le form, cherche en base if cur_value is False: # pas dans le form, cherche en base
cur_value = ue["validation"].get("code", None) cur_value = ue["validation"].get("code", None)
@ -348,7 +349,7 @@ def _ue_form_description(context, ue_list, values):
else: else:
disabled = "" disabled = ""
menu_code_UE += "</select>" menu_code_UE += "</select>"
cur_value = values.get("coef_" + ue["ue_id"], False) cur_value = values.get("coef_" + str(ue["ue_id"]), False)
if cur_value is False: # pas dans le form, cherche en base if cur_value is False: # pas dans le form, cherche en base
cur_value = ue["uecoef"].get("coefficient", "") cur_value = ue["uecoef"].get("coefficient", "")
itemtemplate = ( itemtemplate = (
@ -389,15 +390,15 @@ def _check_values(context, ue_list, values):
""" """
for ue in ue_list: for ue in ue_list:
pu = " pour UE %s" % ue["acronyme"] pu = " pour UE %s" % ue["acronyme"]
code = values.get("valid_" + ue["ue_id"], False) code = values.get("valid_" + str(ue["ue_id"]), False)
if code == "None": if code == "None":
code = None code = None
note = values.get("note_" + ue["ue_id"], False) note = values.get("note_" + str(ue["ue_id"]), False)
try: try:
note = _convert_field_to_float(note) note = _convert_field_to_float(note)
except ValueError: except ValueError:
return False, "note invalide" + pu return False, "note invalide" + pu
coef = values.get("coef_" + ue["ue_id"], False) coef = values.get("coef_" + str(ue["ue_id"]), False)
try: try:
coef = _convert_field_to_float(coef) coef = _convert_field_to_float(coef)
except ValueError: except ValueError:
@ -472,12 +473,12 @@ def _record_ue_validations_and_coefs(
context, formsemestre_id, etudid, ue_list, values, REQUEST=None context, formsemestre_id, etudid, ue_list, values, REQUEST=None
): ):
for ue in ue_list: for ue in ue_list:
code = values.get("valid_" + ue["ue_id"], False) code = values.get("valid_" + str(ue["ue_id"]), False)
if code == "None": if code == "None":
code = None code = None
note = values.get("note_" + ue["ue_id"], False) note = values.get("note_" + str(ue["ue_id"]), False)
note = _convert_field_to_float(note) note = _convert_field_to_float(note)
coef = values.get("coef_" + ue["ue_id"], False) coef = values.get("coef_" + str(ue["ue_id"]), False)
coef = _convert_field_to_float(coef) coef = _convert_field_to_float(coef)
if coef == "" or coef == False: if coef == "" or coef == False:
coef = None coef = None

View File

@ -1424,7 +1424,7 @@ class BasePreferences(object):
{ {
"initvalue": None, "initvalue": None,
"title": "Bulletins PDF: largeur col. modules", "title": "Bulletins PDF: largeur col. modules",
"explanation": "en cm (vide si auto)", "explanation": "en cm (vide ou 0 si auto)",
"type": "float", "type": "float",
"category": "bul", "category": "bul",
}, },
@ -1816,10 +1816,18 @@ class BasePreferences(object):
and self.prefs_dict[p["name"]].get("input_type", None) and self.prefs_dict[p["name"]].get("input_type", None)
== "boolcheckbox" == "boolcheckbox"
): ):
# boolcheckbox: la valeur stockée en base est une chaine "0" ou "1"
# que l'on ressort en True|False
if p["value"]: if p["value"]:
p["value"] = int(p["value"]) # boolcheckboxes are always 0/1 try:
p["value"] = bool(int(p["value"]))
except ValueError:
log(
f"""Warning: invalid value for boolean pref in db: '{p["value"]}'"""
)
p["value"] = False
else: else:
p["value"] = 0 # NULL (backward compat) p["value"] = False # NULL (backward compat)
self.prefs[p["formsemestre_id"]][p["name"]] = p["value"] self.prefs[p["formsemestre_id"]][p["name"]] = p["value"]
# add defaults for missing prefs # add defaults for missing prefs
@ -1885,6 +1893,9 @@ class BasePreferences(object):
names = [name] names = [name]
for name in names: for name in names:
value = self.get(formsemestre_id, name) value = self.get(formsemestre_id, name)
if self.prefs_dict[name].get("input_type", None) == "boolcheckbox":
# repasse les booleens en chaines "0":"1"
value = "1" if value else "0"
# existe deja ? # existe deja ?
pdb = self._editor.list( pdb = self._editor.list(
cnx, args={"formsemestre_id": formsemestre_id, "name": name} cnx, args={"formsemestre_id": formsemestre_id, "name": name}
@ -2187,7 +2198,7 @@ function set_global_pref(el, pref_name) {
return flask.redirect(dest_url + "&head_message=Préférences modifiées") return flask.redirect(dest_url + "&head_message=Préférences modifiées")
elif destination == "again": elif destination == "again":
return flask.redirect( return flask.redirect(
REQUEST.URL0 + "?formsemestre_id=" + self.formsemestre_id REQUEST.URL0 + "?formsemestre_id=" + str(self.formsemestre_id)
) )
elif destination == "global": elif destination == "global":
return flask.redirect(scu.ScoURL() + "/edit_preferences") return flask.redirect(scu.ScoURL() + "/edit_preferences")

View File

@ -313,6 +313,12 @@ sco_publish(
sco_edit_ue.edit_ue_set_code_apogee, sco_edit_ue.edit_ue_set_code_apogee,
Permission.ScoChangeFormation, Permission.ScoChangeFormation,
) )
sco_publish(
"/formsemestre_edit_uecoefs",
sco_formsemestre_edit.formsemestre_edit_uecoefs,
Permission.ScoView,
methods=["GET", "POST"],
)
sco_publish( sco_publish(
"/formation_table_recap", sco_edit_ue.formation_table_recap, Permission.ScoView "/formation_table_recap", sco_edit_ue.formation_table_recap, Permission.ScoView
) )

View File

@ -2077,10 +2077,5 @@ sco_publish(
) )
# #
sco_publish(
"/formsemestre_edit_uecoefs",
sco_formsemestre_edit.formsemestre_edit_uecoefs,
Permission.ScoView,
)
context.populate(globals()) context.populate(globals())