1
0
forked from ScoDoc/ScoDoc

python-modernize views

This commit is contained in:
Emmanuel Viennet 2021-07-09 13:45:10 +02:00
parent d52d2b8565
commit 111f77d667
6 changed files with 25 additions and 25 deletions

0
app/views/entreprises.py Executable file → Normal file
View File

View File

@ -5,6 +5,7 @@ Module Essais: divers essais pour la migration vers Flask
Emmanuel Viennet, 2021 Emmanuel Viennet, 2021
""" """
from __future__ import absolute_import
from flask import g from flask import g
from flask import current_app from flask import current_app

View File

@ -30,6 +30,7 @@ Module notes: issu de ScoDoc7 / ZNotes.py
Emmanuel Viennet, 2021 Emmanuel Viennet, 2021
""" """
from __future__ import absolute_import
import sys import sys
import time import time
import datetime import datetime
@ -722,7 +723,7 @@ def edit_enseignants_form(context, REQUEST, moduleimpl_id):
login2display = {} # user_name : forme pour affichage = "NOM Prenom (login)" login2display = {} # user_name : forme pour affichage = "NOM Prenom (login)"
for u in userlist: for u in userlist:
login2display[u["user_name"]] = u["nomplogin"] login2display[u["user_name"]] = u["nomplogin"]
allowed_user_names = login2display.values() allowed_user_names = list(login2display.values())
H = [ H = [
"<ul><li><b>%s</b> (responsable)</li>" "<ul><li><b>%s</b> (responsable)</li>"
@ -836,7 +837,7 @@ def edit_moduleimpl_resp(context, REQUEST, moduleimpl_id):
login2display = {} # user_name : forme pour affichage = "NOM Prenom (login)" login2display = {} # user_name : forme pour affichage = "NOM Prenom (login)"
for u in userlist: for u in userlist:
login2display[u["user_name"]] = u["nomplogin"] login2display[u["user_name"]] = u["nomplogin"]
allowed_user_names = login2display.values() allowed_user_names = list(login2display.values())
initvalues = M initvalues = M
initvalues["responsable_id"] = login2display.get( initvalues["responsable_id"] = login2display.get(
@ -1206,7 +1207,7 @@ def formsemestre_enseignants_list(context, REQUEST, formsemestre_id, format="htm
if sem_ens[ens]["email"]: if sem_ens[ens]["email"]:
sem_ens[ens]["_email_target"] = "mailto:%s" % sem_ens[ens]["email"] sem_ens[ens]["_email_target"] = "mailto:%s" % sem_ens[ens]["email"]
sem_ens_list = sem_ens.values() sem_ens_list = list(sem_ens.values())
sem_ens_list.sort(lambda x, y: cmp(x["nomprenom"], y["nomprenom"])) sem_ens_list.sort(lambda x, y: cmp(x["nomprenom"], y["nomprenom"]))
# --- Generate page with table # --- Generate page with table
@ -1840,7 +1841,7 @@ def appreciation_add_form(
app = apps[0] app = apps[0]
formsemestre_id = app["formsemestre_id"] formsemestre_id = app["formsemestre_id"]
etudid = app["etudid"] etudid = app["etudid"]
if REQUEST.form.has_key("edit"): if "edit" in REQUEST.form:
edit = int(REQUEST.form["edit"]) edit = int(REQUEST.form["edit"])
elif id: elif id:
edit = 1 edit = 1

View File

@ -30,13 +30,13 @@ Module main: page d'accueil, avec liste des départements
Emmanuel Viennet, 2021 Emmanuel Viennet, 2021
""" """
from __future__ import absolute_import
import flask import flask
from flask import request, render_template, redirect from flask import render_template
from flask_login import login_required
from app.views import scodoc_bp as bp
from scodoc_manager import sco_mgr from scodoc_manager import sco_mgr
from app.views import scodoc_bp as bp
from app.scodoc import VERSION from app.scodoc import VERSION
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission

View File

@ -29,24 +29,24 @@ Module scolar: issu de ScoDoc7 / ZScolar.py
Emmanuel Viennet, 2021 Emmanuel Viennet, 2021
""" """
from __future__ import absolute_import
import sys import sys
import traceback import traceback
import time import time
import string import string
import glob import glob
import re import re
import urllib
import urllib2
import cgi import cgi
import xml import xml
import jaxml import jaxml
# StringIO => io.StringIO or io.BytesIO for text and data respectively. #py3
try: try:
from cStringIO import StringIO from cStringIO import StringIO
except: except ImportError:
from StringIO import StringIO from StringIO import StringIO
from zipfile import ZipFile from zipfile import ZipFile
import thread
import psycopg2 import psycopg2
from flask import g from flask import g
@ -122,7 +122,7 @@ from app.scodoc import sco_etud
context = ScoDoc7Context("scolar") context = ScoDoc7Context("scolar")
def sco_publish(route, function, permission, methods=["GET"]): def sco_publish(route, function, permission, methods=("GET",)):
"""Declare a route for a python function, """Declare a route for a python function,
protected by permission and called following ScoDoc 7 Zope standards. protected by permission and called following ScoDoc 7 Zope standards.
""" """

View File

@ -33,11 +33,11 @@ Vues s'appuyant sur auth et sco_users
Emmanuel Viennet, 2021 Emmanuel Viennet, 2021
""" """
from __future__ import absolute_import
import re import re
import jaxml import jaxml
from flask import g from flask import g
from flask import current_app, request
from flask_login import current_user from flask_login import current_user
from app import db from app import db
@ -50,9 +50,6 @@ from app.decorators import (
scodoc7func, scodoc7func,
ScoDoc7Context, ScoDoc7Context,
permission_required, permission_required,
admin_required,
login_required,
ZRequest,
) )
from app.scodoc import html_sco_header from app.scodoc import html_sco_header
@ -64,6 +61,7 @@ from app.scodoc.sco_permissions_check import can_handle_passwd
from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message
from app.views import users_bp as bp from app.views import users_bp as bp
from scodoc_manager import sco_mgr from scodoc_manager import sco_mgr
from six.moves import range
context = ScoDoc7Context("users") # sco8 context = ScoDoc7Context("users") # sco8
@ -338,7 +336,7 @@ def create_user_form(context, REQUEST, user_name=None, edit=0):
else: else:
vals = tf[2] vals = tf[2]
roles = set(vals["roles"]).intersection(editable_roles_strings) roles = set(vals["roles"]).intersection(editable_roles_strings)
if REQUEST.form.has_key("edit"): if "edit" in REQUEST.form:
edit = int(REQUEST.form["edit"]) edit = int(REQUEST.form["edit"])
else: else:
edit = 0 edit = 0
@ -382,15 +380,15 @@ def create_user_form(context, REQUEST, user_name=None, edit=0):
return "\n".join(H) + "\n" + tf[1] + F return "\n".join(H) + "\n" + tf[1] + F
if edit: # modif utilisateur (mais pas passwd ni user_name !) if edit: # modif utilisateur (mais pas passwd ni user_name !)
if (not can_choose_dept) and vals.has_key("dept"): if (not can_choose_dept) and "dept" in vals:
del vals["dept"] del vals["dept"]
if vals.has_key("passwd"): if "passwd" in vals:
del vals["passwd"] del vals["passwd"]
if vals.has_key("date_modif_passwd"): if "date_modif_passwd" in vals:
del vals["date_modif_passwd"] del vals["date_modif_passwd"]
if vals.has_key("user_name"): if "user_name" in vals:
del vals["user_name"] del vals["user_name"]
if (current_user.user_name == user_name) and vals.has_key("status"): 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
# traitement des roles: ne doit pas affecter les roles # traitement des roles: ne doit pas affecter les roles
@ -459,11 +457,11 @@ def user_info_page(user_name, REQUEST=None):
@bp.route("/get_user_list_xml") @bp.route("/get_user_list_xml")
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
@scodoc7func(context) @scodoc7func(context)
def get_user_list_xml(context, dept=None, start="", limit=25, REQUEST=None): def get_user_list_xml(dept=None, start="", limit=25, REQUEST=None):
"""Returns XML list of users with name (nomplogin) starting with start. """Returns XML list of users with name (nomplogin) starting with start.
Used for forms auto-completion.""" Used for forms auto-completion."""
userlist = sco_users.get_user_list(dept=dept) userlist = sco_users.get_user_list(dept=dept)
start = scu.suppression_diacritics(unicode(start, "utf-8")) start = scu.suppression_diacritics(unicode(start, "utf-8")) # utf8 #sco8
start = scu.strlower(str(start)) start = scu.strlower(str(start))
# TODO : à refaire avec une requete SQL #py3 # TODO : à refaire avec une requete SQL #py3
# (et en json) # (et en json)