From 6bf4fe3762da11e98f0497b97cb11058687c54d0 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 9 Aug 2021 14:29:03 +0200 Subject: [PATCH] Fix: dialogue choix modules avec ids --- app/auth/models.py | 2 +- app/scodoc/TrivialFormulator.py | 15 ++++----------- app/scodoc/sco_formsemestre_edit.py | 10 ++++++---- app/views/users.py | 4 +++- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/auth/models.py b/app/auth/models.py index bd387548..8ee5bef7 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -159,7 +159,7 @@ class User(UserMixin, db.Model): """ for field in ["nom", "prenom", "dept", "active", "email", "date_expiration"]: if field in data: - setattr(self, field, data[field]) + setattr(self, field, data[field] or None) if new_user: if "user_name" in data: # never change name of existing users diff --git a/app/scodoc/TrivialFormulator.py b/app/scodoc/TrivialFormulator.py index e8871b12..d780643d 100644 --- a/app/scodoc/TrivialFormulator.py +++ b/app/scodoc/TrivialFormulator.py @@ -562,18 +562,11 @@ class TF(object): '') % values) + lem.append('value="%(' + field + ')s" />' % values) suggest_js.append( - """var %s_opts = %s; - var %s_as = new bsn.AutoSuggest('%s', %s_opts); - """ - % ( - field, - dict2js(descr.get("text_suggest_options", {})), - field, - field, - field, - ) + f"""var {field}_opts = {dict2js(descr.get("text_suggest_options", {}))}; +var {field}_as = new bsn.AutoSuggest('{field}', {field}_opts); +""" ) else: raise ValueError("unkown input_type for form (%s)!" % input_type) diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index 6d4120c6..cfd7d51c 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -200,7 +200,7 @@ def do_formsemestre_createwithmodules(context, REQUEST=None, edit=False): NB_SEM = parcours.NB_SEM else: NB_SEM = 10 # fallback, max 10 semestres - semestre_id_list = [-1] + [str(x) for x in range(1, NB_SEM + 1)] + semestre_id_list = ["-1"] + [str(x) for x in range(1, NB_SEM + 1)] semestre_id_labels = [] for sid in semestre_id_list: if sid == "-1": @@ -578,7 +578,7 @@ def do_formsemestre_createwithmodules(context, REQUEST=None, edit=False): itemtemplate = """%(label)s%(elem)s""" modform.append( ( - str(mod["module_id"]), + "MI" + str(mod["module_id"]), { "input_type": "text_suggest", "size": 50, @@ -738,8 +738,9 @@ def do_formsemestre_createwithmodules(context, REQUEST=None, edit=False): formsemestre_id = sco_formsemestre.do_formsemestre_create(tf[2]) # creation des modules for module_id in tf[2]["tf-checked"]: + assert module_id[:2] == "MI" modargs = { - "module_id": module_id, + "module_id": int(module_id[2:]), "formsemestre_id": formsemestre_id, "responsable_id": tf[2][module_id], } @@ -755,7 +756,8 @@ def do_formsemestre_createwithmodules(context, REQUEST=None, edit=False): # Note: la destruction echouera s'il y a des objets dependants # (eg des evaluations définies) # nouveaux modules - checkedmods = tf[2]["tf-checked"] + # (retire le "MI" du début du nom de champs) + checkedmods = [int(x[2:]) for x in tf[2]["tf-checked"]] sco_formsemestre.do_formsemestre_edit(context, tf[2]) ams = sco_moduleimpl.do_moduleimpl_list( context, formsemestre_id=formsemestre_id diff --git a/app/views/users.py b/app/views/users.py index a705f809..69eac225 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -150,7 +150,9 @@ def create_user_form(context, REQUEST, user_name=None, edit=0): else: initvalues["roles"] = [] if "date_expiration" in initvalues: - initvalues["date_expiration"] = u.date_expiration.strftime("%d/%m/%Y") + initvalues["date_expiration"] = ( + u.date_expiration.strftime("%d/%m/%Y") if u.date_expiration else "" + ) initvalues["status"] = "" if u.active else "old" orig_roles = { # set des roles existants avant édition UserRole.role_dept_from_string(role_dept)