diff --git a/ImportScolars.py b/ImportScolars.py index 69a6c62a3..d38218f52 100644 --- a/ImportScolars.py +++ b/ImportScolars.py @@ -28,10 +28,16 @@ """ Importation des etudiants à partir de fichiers CSV """ -import os, sys, time, pdb +import os +import sys +import time +import pdb +import collections +import types +import re -from sco_utils import * -from notesdb import * +import sco_utils as scu +import notesdb as ndb from notes_log import log import scolars import sco_formsemestre @@ -42,6 +48,15 @@ import sco_news from sco_news import NEWS_INSCR, NEWS_NOTE, NEWS_FORM, NEWS_SEM, NEWS_MISC from sco_formsemestre_inscriptions import do_formsemestre_inscription_with_modules from gen_tables import GenTable +from sco_exceptions import ( + AccessDenied, + FormatError, + ScoException, + ScoValueError, + ScoInvalidDateError, + ScoLockedFormError, + ScoGenError, +) # format description (relative to Product directory)) FORMAT_FILE = "misc/format_import_etudiants.txt" @@ -93,7 +108,7 @@ ADMISSION_MODIFIABLE_FIELDS = ( def sco_import_format(with_codesemestre=True): "returns tuples (Attribut, Type, Table, AllowNulls, Description)" r = [] - for l in open(SCO_SRC_DIR + "/" + FORMAT_FILE): + for l in open(scu.SCO_SRC_DIR + "/" + FORMAT_FILE): l = l.strip() if l and l[0] != "#": fs = l.split(";") @@ -152,10 +167,10 @@ def sco_import_generate_excel_sample( titles = [] titlesStyles = [] for l in fmt: - name = strlower(l[0]) + name = scu.strlower(l[0]) if (not with_codesemestre) and name == "codesemestre": continue # pas de colonne codesemestre - if only_tables is not None and strlower(l[2]) not in only_tables: + if only_tables is not None and scu.strlower(l[2]) not in only_tables: continue # table non demandée if name in exclude_cols: continue # colonne exclue @@ -192,7 +207,7 @@ def sco_import_generate_excel_sample( ) l.append(etud["partitionsgroupes"]) else: - key = strlower(field).split()[0] + key = scu.strlower(field).split()[0] l.append(etud.get(key, "")) lines.append(l) else: @@ -224,7 +239,7 @@ def students_import_excel( if formsemestre_id: dest = "formsemestre_status?formsemestre_id=%s" % formsemestre_id else: - dest = REQUEST.URL1 + dest = context.NotesURL() H = [context.sco_header(REQUEST, page_title="Import etudiants")] H.append("
Département " + DeptId - + """ supprimé du serveur web (la base de données n'est pas affectée)!
""" - % REQUEST.URL1 + + """ supprimé du serveur web (la base de données n'est pas affectée)!""" ) _top_level_css = """ @@ -410,7 +409,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp except: admin_password_initialized = "0" if isAdmin and admin_password_initialized != "1": - REQUEST.RESPONSE.redirect( + return REQUEST.RESPONSE.redirect( "ScoDoc/change_admin_user_form?message=Le%20mot%20de%20passe%20administrateur%20doit%20etre%20change%20!" ) @@ -980,5 +979,5 @@ def manage_addZScoDoc(self, id="ScoDoc", title="Site ScoDoc", REQUEST=None): ) # ne cree (presque rien), tout se passe lors du 1er accès self._setObject(id, zscodoc) if REQUEST is not None: - REQUEST.RESPONSE.redirect("%s/manage_workspace" % REQUEST.URL1) + REQUEST.RESPONSE.redirect("/ScoDoc/manage_workspace") return id diff --git a/ZScoUsers.py b/ZScoUsers.py index 9e9dd9246..efe1eb976 100644 --- a/ZScoUsers.py +++ b/ZScoUsers.py @@ -27,28 +27,45 @@ """ Gestion des utilisateurs (table SQL pour Zope User Folder) """ -import string, re +import string +import re import time -import md5, base64 +import md5 +import base64 +import jaxml - -from sco_zope import * +from sco_zope import * # pylint: disable=unused-wildcard-import # --------------- - -import notesdb -from notesdb import * +import sco_utils as scu +import notesdb as ndb from notes_log import log from scolog import logdb -from sco_utils import * from scolars import format_prenom, format_nom -import sco_import_users, sco_excel -from TrivialFormulator import TrivialFormulator, TF +import sco_import_users +import sco_excel +from TrivialFormulator import TrivialFormulator, TF, tf_error_message from gen_tables import GenTable import scolars import sco_cache import sco_users - +from sco_permissions import ( + ScoEditAllEvals, + ScoEditAllNotes, + ScoImplement, + ScoSuperAdmin, + ScoUsersAdmin, + ScoUsersView, + ScoView, +) +from sco_exceptions import ( + AccessDenied, + ScoException, + ScoValueError, + ScoInvalidDateError, + ScoLockedFormError, + ScoGenError, +) # --------------- # cache global: chaque instance, repérée par son URL, a un cache @@ -93,7 +110,7 @@ class ZScoUsers( # Ugly but necessary during transition out of Zope: _db_cnx_string = "dbname=SCOUSERS port=5432" security.declareProtected("Change DTML Documents", "GetUsersDBConnexion") - GetUsersDBConnexion = notesdb.GetUsersDBConnexion + GetUsersDBConnexion = ndb.GetUsersDBConnexion # -------------------------------------------------------------------- # @@ -162,7 +179,7 @@ class ZScoUsers( F = self.sco_footer(REQUEST) return "\n".join(H) + F - _userEditor = EditableTable( + _userEditor = ndb.EditableTable( "sco_users", "user_id", ( @@ -180,12 +197,12 @@ class ZScoUsers( "date_expiration", ), output_formators={ - "date_modif_passwd": DateISOtoDMY, - "date_expiration": DateISOtoDMY, + "date_modif_passwd": ndb.DateISOtoDMY, + "date_expiration": ndb.DateISOtoDMY, }, input_formators={ - "date_modif_passwd": DateDMYtoISO, - "date_expiration": DateDMYtoISO, + "date_modif_passwd": ndb.DateDMYtoISO, + "date_expiration": ndb.DateDMYtoISO, }, sortkey="nom", filter_nulls=False, @@ -217,12 +234,12 @@ class ZScoUsers( u = self._user_list(args={"user_name": user_name})[0] if u["status"] == "old" and u["roles"] and u["roles"][0] != "-": roles = ["-" + r for r in u["roles"].split(",")] - cursor = cnx.cursor(cursor_factory=ScoDocCursor) + cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) self.acl_users.scodoc_editUser(cursor, user_name, roles=roles) self.get_userlist_cache().inval_cache() elif not u["status"] and u["roles"] and u["roles"][0] == "-": roles = [r[1:] for r in u["roles"].split(",") if (r and r[0] == "-")] - cursor = cnx.cursor(cursor_factory=ScoDocCursor) + cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) self.acl_users.scodoc_editUser(cursor, user_name, roles=roles) self.get_userlist_cache().inval_cache() @@ -268,7 +285,7 @@ class ZScoUsers( "nom_fmt": user_name, "nomcomplet": user_name, "nomplogin": user_name, - "nomnoacc": suppress_accents(user_name), + "nomnoacc": scu.suppress_accents(user_name), "passwd_temp": 0, "status": "", "date_expiration": None, @@ -289,7 +306,7 @@ class ZScoUsers( else: n = user_name - prenom_abbrv = abbrev_prenom(p) + prenom_abbrv = scu.abbrev_prenom(p) # nomprenom est le nom capitalisé suivi de l'initiale du prénom info["nomprenom"] = (n + " " + prenom_abbrv).strip() # prenomnom est l'initiale du prénom suivie du nom @@ -301,9 +318,9 @@ class ZScoUsers( info["nomcomplet"] = info["prenom_fmt"] + " " + info["nom_fmt"] # nomplogin est le nom en majuscules suivi du prénom et du login # e.g. Dupont Pierre (dupont) - info["nomplogin"] = "%s %s (%s)" % (strupper(n), p, info["user_name"]) + info["nomplogin"] = "%s %s (%s)" % (scu.strupper(n), p, info["user_name"]) # nomnoacc est le nom en minuscules sans accents - info["nomnoacc"] = suppress_accents(strlower(info["nom"])) + info["nomnoacc"] = scu.suppress_accents(scu.strlower(info["nom"])) return info @@ -346,7 +363,7 @@ class ZScoUsers( assert len(user) == 1, "database inconsistency: len(user)=%d" % len(user) # should not occur, already tested in _can_handle_passwd cnx = self.GetUsersDBConnexion() # en mode autocommit - cursor = cnx.cursor(cursor_factory=ScoDocCursor) + cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor.execute( "update sco_users set date_modif_passwd=now(), passwd_temp=0 where user_name=%(user_name)s", {"user_name": user_name}, @@ -417,7 +434,7 @@ class ZScoUsers(