diff --git a/app/auth/models.py b/app/auth/models.py index 9fd40ca3..bd387548 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -157,7 +157,7 @@ class User(UserMixin, db.Model): """Set users' attributes from given dict values. Roles must be encoded as "roles_string", like "Ens_RT, Secr_CJ" """ - for field in ["nom", "prenom", "dept", "status", "email"]: + for field in ["nom", "prenom", "dept", "active", "email", "date_expiration"]: if field in data: setattr(self, field, data[field]) if new_user: diff --git a/app/scodoc/sco_users.py b/app/scodoc/sco_users.py index 29267c60..fcb846ad 100644 --- a/app/scodoc/sco_users.py +++ b/app/scodoc/sco_users.py @@ -87,21 +87,16 @@ def index_html(context, REQUEST, all_depts=False, with_inactives=False, format=" with_inactives = int(with_inactives) H = [html_sco_header.html_sem_header(context, REQUEST, "Gestion des utilisateurs")] - H.append("
Ajouter un utilisateur'.format( - url_for("users.create_user_form", scodoc_dept=g.scodoc_dept).encode( - scu.SCO_ENCODING - ) # sco8 + url_for("users.create_user_form", scodoc_dept=g.scodoc_dept) ) ) H.append( ' Importer des utilisateurs
'.format( - url_for("users.import_users_form", scodoc_dept=g.scodoc_dept).encode( - scu.SCO_ENCODING - ) # sco8 + url_for("users.import_users_form", scodoc_dept=g.scodoc_dept) ) ) if all_depts: @@ -151,7 +146,7 @@ def list_users( if dept and not all_depts: users = get_user_list(dept=dept, with_inactives=with_inactives) - comm = "dept. %s" % dept.encode(scu.SCO_ENCODING) # sco8 + comm = "dept. %s" % dept else: users = get_user_list(with_inactives=with_inactives) comm = "tous" @@ -170,9 +165,7 @@ def list_users( if with_links and can_modify: target = url_for( "users.user_info_page", scodoc_dept=dept, user_name=u.user_name - ).encode( - scu.SCO_ENCODING - ) # sco8 + ) d["_user_name_target"] = target d["_nom_target"] = target d["_prenom_target"] = target @@ -307,7 +300,7 @@ def user_info_page(context, user_name=None, REQUEST=None): html_sco_header.sco_header( context, REQUEST, - page_title="Utilisateur %s" % user.user_name.encode("utf-8"), # sco8 + page_title="Utilisateur %s" % user.user_name, ) ] F = html_sco_header.sco_footer(context, REQUEST) diff --git a/app/views/users.py b/app/views/users.py index d229d597..2d7a311d 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -33,6 +33,7 @@ Vues s'appuyant sur auth et sco_users Emmanuel Viennet, 2021 """ +import datetime import re from xml.etree import ElementTree @@ -147,6 +148,9 @@ def create_user_form(context, REQUEST, user_name=None, edit=0): initvalues["roles"] = initvalues["roles_string"].split(",") else: initvalues["roles"] = [] + if "date_expiration" in initvalues: + initvalues["date_expiration"] = u.date_expiration.strftime("%d/%m/%Y") + initvalues["status"] = "" if u.active else "old" orig_roles = { # set des roles existants avant édition UserRole.role_dept_from_string(role_dept) for role_dept in initvalues["roles"] @@ -342,7 +346,7 @@ def create_user_form(context, REQUEST, user_name=None, edit=0): edit = 0 try: force = int(vals["force"][0]) - except (ValueError, TypeError): + except (IndexError, ValueError, TypeError): force = 0 if edit: @@ -390,7 +394,16 @@ def create_user_form(context, REQUEST, user_name=None, edit=0): del vals["user_name"] if (current_user.user_name == user_name) and "status" in vals: del vals["status"] # no one can't change its own status - + if "date_expiration" in vals: + try: + vals["date_expiration"] = datetime.datetime.strptime( + vals["date_expiration"], "%d/%m/%Y" + ) + except ValueError: + H.append(tf_error_message("date expiration invalide")) + return "\n".join(H) + "\n" + tf[1] + F + if "status" in vals: + vals["active"] = vals["status"] == "" # traitement des roles: ne doit pas affecter les roles # que l'on en controle pas: for role in orig_roles_strings: # { "Ens_RT", "Secr_CJ", ... }