Fix formulaire gestion utilisateur
This commit is contained in:
parent
b8efe15c0a
commit
f00a18aeb7
@ -157,7 +157,7 @@ class User(UserMixin, db.Model):
|
|||||||
"""Set users' attributes from given dict values.
|
"""Set users' attributes from given dict values.
|
||||||
Roles must be encoded as "roles_string", like "Ens_RT, Secr_CJ"
|
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:
|
if field in data:
|
||||||
setattr(self, field, data[field])
|
setattr(self, field, data[field])
|
||||||
if new_user:
|
if new_user:
|
||||||
|
@ -87,21 +87,16 @@ def index_html(context, REQUEST, all_depts=False, with_inactives=False, format="
|
|||||||
with_inactives = int(with_inactives)
|
with_inactives = int(with_inactives)
|
||||||
|
|
||||||
H = [html_sco_header.html_sem_header(context, REQUEST, "Gestion des utilisateurs")]
|
H = [html_sco_header.html_sem_header(context, REQUEST, "Gestion des utilisateurs")]
|
||||||
H.append("<h2>Gestion des utilisateurs</h2>")
|
|
||||||
|
|
||||||
if current_user.has_permission(Permission.ScoUsersAdmin, g.scodoc_dept):
|
if current_user.has_permission(Permission.ScoUsersAdmin, g.scodoc_dept):
|
||||||
H.append(
|
H.append(
|
||||||
'<p><a href="{}" class="stdlink">Ajouter un utilisateur</a>'.format(
|
'<p><a href="{}" class="stdlink">Ajouter un utilisateur</a>'.format(
|
||||||
url_for("users.create_user_form", scodoc_dept=g.scodoc_dept).encode(
|
url_for("users.create_user_form", scodoc_dept=g.scodoc_dept)
|
||||||
scu.SCO_ENCODING
|
|
||||||
) # sco8
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
H.append(
|
H.append(
|
||||||
' <a href="{}" class="stdlink">Importer des utilisateurs</a></p>'.format(
|
' <a href="{}" class="stdlink">Importer des utilisateurs</a></p>'.format(
|
||||||
url_for("users.import_users_form", scodoc_dept=g.scodoc_dept).encode(
|
url_for("users.import_users_form", scodoc_dept=g.scodoc_dept)
|
||||||
scu.SCO_ENCODING
|
|
||||||
) # sco8
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if all_depts:
|
if all_depts:
|
||||||
@ -151,7 +146,7 @@ def list_users(
|
|||||||
|
|
||||||
if dept and not all_depts:
|
if dept and not all_depts:
|
||||||
users = get_user_list(dept=dept, with_inactives=with_inactives)
|
users = get_user_list(dept=dept, with_inactives=with_inactives)
|
||||||
comm = "dept. %s" % dept.encode(scu.SCO_ENCODING) # sco8
|
comm = "dept. %s" % dept
|
||||||
else:
|
else:
|
||||||
users = get_user_list(with_inactives=with_inactives)
|
users = get_user_list(with_inactives=with_inactives)
|
||||||
comm = "tous"
|
comm = "tous"
|
||||||
@ -170,9 +165,7 @@ def list_users(
|
|||||||
if with_links and can_modify:
|
if with_links and can_modify:
|
||||||
target = url_for(
|
target = url_for(
|
||||||
"users.user_info_page", scodoc_dept=dept, user_name=u.user_name
|
"users.user_info_page", scodoc_dept=dept, user_name=u.user_name
|
||||||
).encode(
|
)
|
||||||
scu.SCO_ENCODING
|
|
||||||
) # sco8
|
|
||||||
d["_user_name_target"] = target
|
d["_user_name_target"] = target
|
||||||
d["_nom_target"] = target
|
d["_nom_target"] = target
|
||||||
d["_prenom_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(
|
html_sco_header.sco_header(
|
||||||
context,
|
context,
|
||||||
REQUEST,
|
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)
|
F = html_sco_header.sco_footer(context, REQUEST)
|
||||||
|
@ -33,6 +33,7 @@ Vues s'appuyant sur auth et sco_users
|
|||||||
|
|
||||||
Emmanuel Viennet, 2021
|
Emmanuel Viennet, 2021
|
||||||
"""
|
"""
|
||||||
|
import datetime
|
||||||
import re
|
import re
|
||||||
from xml.etree import ElementTree
|
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(",")
|
initvalues["roles"] = initvalues["roles_string"].split(",")
|
||||||
else:
|
else:
|
||||||
initvalues["roles"] = []
|
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
|
orig_roles = { # set des roles existants avant édition
|
||||||
UserRole.role_dept_from_string(role_dept)
|
UserRole.role_dept_from_string(role_dept)
|
||||||
for role_dept in initvalues["roles"]
|
for role_dept in initvalues["roles"]
|
||||||
@ -342,7 +346,7 @@ def create_user_form(context, REQUEST, user_name=None, edit=0):
|
|||||||
edit = 0
|
edit = 0
|
||||||
try:
|
try:
|
||||||
force = int(vals["force"][0])
|
force = int(vals["force"][0])
|
||||||
except (ValueError, TypeError):
|
except (IndexError, ValueError, TypeError):
|
||||||
force = 0
|
force = 0
|
||||||
|
|
||||||
if edit:
|
if edit:
|
||||||
@ -390,7 +394,16 @@ def create_user_form(context, REQUEST, user_name=None, edit=0):
|
|||||||
del vals["user_name"]
|
del vals["user_name"]
|
||||||
if (current_user.user_name == user_name) and "status" in vals:
|
if (current_user.user_name == user_name) and "status" in vals:
|
||||||
del vals["status"] # no one can't change its own status
|
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
|
# traitement des roles: ne doit pas affecter les roles
|
||||||
# que l'on en controle pas:
|
# que l'on en controle pas:
|
||||||
for role in orig_roles_strings: # { "Ens_RT", "Secr_CJ", ... }
|
for role in orig_roles_strings: # { "Ens_RT", "Secr_CJ", ... }
|
||||||
|
Loading…
Reference in New Issue
Block a user