1
0
forked from ScoDoc/ScoDoc

python-modernize

This commit is contained in:
Emmanuel Viennet 2021-07-09 13:59:01 +02:00
parent e9c5e53fff
commit 0c33d363ca
8 changed files with 23 additions and 11 deletions

View File

@ -31,6 +31,8 @@ nt = sco_core.get_notes_cache(context).get_NotesTable(context, formsemestre_id)
""" """
from __future__ import absolute_import
from __future__ import print_function
import pdb # pylint: disable=unused-import import pdb # pylint: disable=unused-import
import pprint import pprint

View File

@ -4,6 +4,7 @@
# #
# Command: ./csv2rules.py misc/parcoursDUT.csv # Command: ./csv2rules.py misc/parcoursDUT.csv
# #
from __future__ import absolute_import
from app.scodoc.sco_codes_parcours import ( from app.scodoc.sco_codes_parcours import (
DUTRule, DUTRule,
ADC, ADC,

View File

@ -40,6 +40,8 @@ Par exemple, la clé '_css_row_class' spécifie le style CSS de la ligne.
""" """
from __future__ import absolute_import
from __future__ import print_function
import random import random
from collections import OrderedDict from collections import OrderedDict
@ -209,7 +211,7 @@ class GenTable:
if with_titles and self.titles: if with_titles and self.titles:
l = [] l = []
if with_lines_titles: if with_lines_titles:
if self.titles.has_key("row_title"): if "row_title" in self.titles:
l = [self.titles["row_title"]] l = [self.titles["row_title"]]
T.append(l + [self.titles.get(cid, "") for cid in self.columns_ids]) T.append(l + [self.titles.get(cid, "") for cid in self.columns_ids])
@ -218,7 +220,7 @@ class GenTable:
line_num += 1 line_num += 1
l = [] l = []
if with_lines_titles: if with_lines_titles:
if row.has_key("row_title"): if "row_title" in row:
l = [row["row_title"]] l = [row["row_title"]]
if not (omit_hidden_lines and row.get("_hidden", False)): if not (omit_hidden_lines and row.get("_hidden", False)):
@ -262,7 +264,7 @@ class GenTable:
line_num += 1 line_num += 1
l = [] l = []
if with_lines_titles: if with_lines_titles:
if self.bottom_titles.has_key("row_title"): if "row_title" in self.bottom_titles:
l = [self.bottom_titles["row_title"]] l = [self.bottom_titles["row_title"]]
T.append(l + [self.bottom_titles.get(cid, "") for cid in self.columns_ids]) T.append(l + [self.bottom_titles.get(cid, "") for cid in self.columns_ids])
@ -310,7 +312,7 @@ class GenTable:
cls = "" cls = ""
H = ["<tr%s %s>" % (cls, row.get("_tr_attrs", ""))] H = ["<tr%s %s>" % (cls, row.get("_tr_attrs", ""))]
# titre ligne # titre ligne
if row.has_key("row_title"): if "row_title" in row:
content = str(row["row_title"]) content = str(row["row_title"])
help = row.get("row_title_help", "") help = row.get("row_title_help", "")
if help: if help:
@ -517,7 +519,7 @@ class GenTable:
("VALIGN", (0, 0), (-1, -1), "TOP"), ("VALIGN", (0, 0), (-1, -1), "TOP"),
] ]
nb_cols = len(self.columns_ids) nb_cols = len(self.columns_ids)
if self.rows and self.rows[0].has_key("row_title"): if self.rows and "row_title" in self.rows[0]:
nb_cols += 1 nb_cols += 1
if not self.pdf_col_widths: if not self.pdf_col_widths:
self.pdf_col_widths = (None,) * nb_cols self.pdf_col_widths = (None,) * nb_cols

View File

@ -28,6 +28,7 @@
"""HTML Header/Footer for ScoDoc pages """HTML Header/Footer for ScoDoc pages
""" """
from __future__ import absolute_import
import cgi import cgi
from flask_login import current_user from flask_login import current_user
@ -167,7 +168,7 @@ def sco_header(
REQUEST.RESPONSE.setHeader("X-ScoDoc-User", str(REQUEST.AUTHENTICATED_USER)) REQUEST.RESPONSE.setHeader("X-ScoDoc-User", str(REQUEST.AUTHENTICATED_USER))
# Get more parameters from REQUEST # Get more parameters from REQUEST
if not head_message and REQUEST.form.has_key("head_message"): if not head_message and "head_message" in REQUEST.form:
head_message = REQUEST.form["head_message"] head_message = REQUEST.form["head_message"]
params = { params = {

View File

@ -28,6 +28,7 @@
""" """
Génération de la "sidebar" (marge gauche des pages HTML) Génération de la "sidebar" (marge gauche des pages HTML)
""" """
from __future__ import absolute_import
from flask import url_for from flask import url_for
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
@ -95,7 +96,7 @@ def sidebar(context, REQUEST=None):
% params % params
) )
# ---- s'il y a un etudiant selectionné: # ---- s'il y a un etudiant selectionné:
if REQUEST.form.has_key("etudid"): if "etudid" in REQUEST.form:
etudid = REQUEST.form["etudid"] etudid = REQUEST.form["etudid"]
etud = sco_etud.get_etud_info(filled=1, etudid=etudid)[0] etud = sco_etud.get_etud_info(filled=1, etudid=etudid)[0]
params.update(etud) params.update(etud)

View File

@ -27,9 +27,10 @@
"""Various HTML generation functions """Various HTML generation functions
""" """
from __future__ import absolute_import
from flask import g, url_for from flask import g, url_for
import listhistogram from . import listhistogram
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu

View File

@ -1,5 +1,6 @@
"""Simple image resize using PIL""" """Simple image resize using PIL"""
from __future__ import absolute_import
from PIL import Image as PILImage from PIL import Image as PILImage
from cStringIO import StringIO from cStringIO import StringIO

View File

@ -4,8 +4,11 @@
# Code from http://code.activestate.com/recipes/457411/ # Code from http://code.activestate.com/recipes/457411/
from __future__ import absolute_import
from __future__ import print_function
from bisect import bisect_left, bisect_right from bisect import bisect_left, bisect_right
from itertools import izip
from six.moves import zip
class intervalmap(object): class intervalmap(object):
@ -129,7 +132,7 @@ class intervalmap(object):
in order. in order.
""" """
previous_bound = None previous_bound = None
for b, v in izip(self._bounds, self._items): for b, v in zip(self._bounds, self._items):
if v is not None: if v is not None:
yield (previous_bound, b), v yield (previous_bound, b), v
previous_bound = b previous_bound = b
@ -188,7 +191,7 @@ if __name__ == "__main__":
repr(i) repr(i)
== "{[None, 3] => 'My,', [3, 5] => 'Hello', [5.5, 5.9000000000000004] => 'Cruel', [6.5999999999999996, 7] => 'World', [8, 10] => '(Test)', [10, None] => '!'}" == "{[None, 3] => 'My,', [3, 5] => 'Hello', [5.5, 5.9000000000000004] => 'Cruel', [6.5999999999999996, 7] => 'World', [8, 10] => '(Test)', [10, None] => '!'}"
) )
assert " ".join(i.values()) == "My, Hello Cruel World (Test) !" assert " ".join(list(i.values())) == "My, Hello Cruel World (Test) !"
print("Test 1 OK") print("Test 1 OK")
# Test 2 # Test 2