forked from ScoDoc/ScoDoc
code cleaning
This commit is contained in:
parent
73cabb0039
commit
dc88238f63
86
ZScoDoc.py
86
ZScoDoc.py
@ -31,19 +31,29 @@
|
|||||||
Chaque departement est géré par un ZScolar sous ZScoDoc.
|
Chaque departement est géré par un ZScolar sous ZScoDoc.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time, string, glob, re, inspect
|
import time
|
||||||
import urllib, urllib2, cgi, xml
|
import datetime
|
||||||
|
import string
|
||||||
|
import glob
|
||||||
|
import re
|
||||||
|
import inspect
|
||||||
|
import urllib
|
||||||
|
import urllib2
|
||||||
|
import cgi
|
||||||
|
import xml
|
||||||
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
import os.path, glob
|
import os.path
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from email.MIMEMultipart import MIMEMultipart
|
from email.MIMEMultipart import ( # pylint: disable=no-name-in-module,import-error
|
||||||
from email.MIMEText import MIMEText
|
MIMEMultipart,
|
||||||
from email.MIMEBase import MIMEBase
|
)
|
||||||
from email.Header import Header
|
from email.MIMEText import MIMEText # pylint: disable=no-name-in-module,import-error
|
||||||
from email import Encoders
|
from email.MIMEBase import MIMEBase # pylint: disable=no-name-in-module,import-error
|
||||||
|
from email.Header import Header # pylint: disable=no-name-in-module,import-error
|
||||||
|
from email import Encoders # pylint: disable=no-name-in-module,import-error
|
||||||
|
|
||||||
from sco_zope import * # pylint: disable=unused-wildcard-import
|
from sco_zope import * # pylint: disable=unused-wildcard-import
|
||||||
|
|
||||||
@ -52,10 +62,28 @@ try:
|
|||||||
except:
|
except:
|
||||||
import ZPsycopgDA.DA as ZopeDA # interp.py
|
import ZPsycopgDA.DA as ZopeDA # interp.py
|
||||||
|
|
||||||
from sco_utils import *
|
import sco_utils as scu
|
||||||
|
import VERSION
|
||||||
from notes_log import log
|
from notes_log import log
|
||||||
import sco_find_etud
|
import sco_find_etud
|
||||||
import sco_users
|
import sco_users
|
||||||
|
from sco_permissions import (
|
||||||
|
ScoView,
|
||||||
|
ScoEnsView,
|
||||||
|
ScoImplement,
|
||||||
|
ScoChangeFormation,
|
||||||
|
ScoObservateur,
|
||||||
|
ScoEtudInscrit,
|
||||||
|
ScoEtudChangeGroups,
|
||||||
|
ScoEtudChangeAdr,
|
||||||
|
ScoEtudSupprAnnotations,
|
||||||
|
ScoEditAllEvals,
|
||||||
|
ScoEditAllNotes,
|
||||||
|
ScoEditFormationTags,
|
||||||
|
ScoEditApo,
|
||||||
|
ScoSuperAdmin,
|
||||||
|
)
|
||||||
|
from sco_exceptions import ScoValueError, ScoLockedFormError, ScoGenError, AccessDenied
|
||||||
|
|
||||||
|
|
||||||
class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Implicit):
|
class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Implicit):
|
||||||
@ -101,7 +129,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
|
|||||||
def _check_users_folder(self, REQUEST=None):
|
def _check_users_folder(self, REQUEST=None):
|
||||||
"""Vérifie UserFolder et le crée s'il le faut"""
|
"""Vérifie UserFolder et le crée s'il le faut"""
|
||||||
try:
|
try:
|
||||||
udb = self.UsersDB
|
_ = self.UsersDB
|
||||||
return "<!-- uf ok -->"
|
return "<!-- uf ok -->"
|
||||||
except:
|
except:
|
||||||
e = self._check_admin_perm(REQUEST)
|
e = self._check_admin_perm(REQUEST)
|
||||||
@ -154,7 +182,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
|
|||||||
pass
|
pass
|
||||||
# add missing getAuthFailedMessage (bug in exUserFolder ?)
|
# add missing getAuthFailedMessage (bug in exUserFolder ?)
|
||||||
try:
|
try:
|
||||||
x = self.getAuthFailedMessage
|
_ = self.getAuthFailedMessage
|
||||||
except:
|
except:
|
||||||
log("adding getAuthFailedMessage to Zope install")
|
log("adding getAuthFailedMessage to Zope install")
|
||||||
parent = self.aq_parent
|
parent = self.aq_parent
|
||||||
@ -177,7 +205,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
|
|||||||
da = ZopeDA.Connection(
|
da = ZopeDA.Connection(
|
||||||
oid,
|
oid,
|
||||||
"Cnx bd utilisateurs",
|
"Cnx bd utilisateurs",
|
||||||
SCO_DEFAULT_SQL_USERS_CNX,
|
scu.SCO_DEFAULT_SQL_USERS_CNX,
|
||||||
False,
|
False,
|
||||||
check=1,
|
check=1,
|
||||||
tilevel=2,
|
tilevel=2,
|
||||||
@ -254,7 +282,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
|
|||||||
r = []
|
r = []
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
try:
|
try:
|
||||||
s = folder.Scolarite
|
_ = folder.Scolarite
|
||||||
r.append(folder)
|
r.append(folder)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -352,10 +380,10 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
|
|||||||
def scodoc_top_html_header(self, REQUEST, page_title="ScoDoc"):
|
def scodoc_top_html_header(self, REQUEST, page_title="ScoDoc"):
|
||||||
H = [
|
H = [
|
||||||
self._html_begin
|
self._html_begin
|
||||||
% {"page_title": "ScoDoc: bienvenue", "encoding": SCO_ENCODING},
|
% {"page_title": "ScoDoc: bienvenue", "encoding": scu.SCO_ENCODING},
|
||||||
self._top_level_css,
|
self._top_level_css,
|
||||||
"""</head><body class="gtrcontent" id="gtrcontent">""",
|
"""</head><body class="gtrcontent" id="gtrcontent">""",
|
||||||
CUSTOM_HTML_HEADER_CNX,
|
scu.CUSTOM_HTML_HEADER_CNX,
|
||||||
]
|
]
|
||||||
return "\n".join(H)
|
return "\n".join(H)
|
||||||
|
|
||||||
@ -468,7 +496,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
|
|||||||
E. Viennet (Université Paris 13).</p>
|
E. Viennet (Université Paris 13).</p>
|
||||||
</div>
|
</div>
|
||||||
</div>"""
|
</div>"""
|
||||||
% (SCO_WEBSITE,)
|
% (scu.SCO_WEBSITE,)
|
||||||
)
|
)
|
||||||
|
|
||||||
H.append("""</body></html>""")
|
H.append("""</body></html>""")
|
||||||
@ -581,8 +609,8 @@ E. Viennet (Université Paris 13).</p>
|
|||||||
<link HREF="/ScoDoc/static/css/scodoc.css" rel="stylesheet" type="text/css"/>
|
<link HREF="/ScoDoc/static/css/scodoc.css" rel="stylesheet" type="text/css"/>
|
||||||
|
|
||||||
</head><body>%s""" % (
|
</head><body>%s""" % (
|
||||||
SCO_ENCODING,
|
scu.SCO_ENCODING,
|
||||||
CUSTOM_HTML_HEADER_CNX,
|
scu.CUSTOM_HTML_HEADER_CNX,
|
||||||
)
|
)
|
||||||
|
|
||||||
security.declareProtected("View", "standard_html_footer")
|
security.declareProtected("View", "standard_html_footer")
|
||||||
@ -594,8 +622,8 @@ Problème de connexion (identifiant, mot de passe): <em>contacter votre responsa
|
|||||||
<p>Problèmes et suggestions sur le logiciel: <a href="mailto:%s">%s</a></p>
|
<p>Problèmes et suggestions sur le logiciel: <a href="mailto:%s">%s</a></p>
|
||||||
<p><em>ScoDoc est un logiciel libre développé par Emmanuel Viennet.</em></p>
|
<p><em>ScoDoc est un logiciel libre développé par Emmanuel Viennet.</em></p>
|
||||||
</body></html>""" % (
|
</body></html>""" % (
|
||||||
SCO_USERS_LIST,
|
scu.SCO_USERS_LIST,
|
||||||
SCO_USERS_LIST,
|
scu.SCO_USERS_LIST,
|
||||||
)
|
)
|
||||||
|
|
||||||
# sendEmail is not used through the web
|
# sendEmail is not used through the web
|
||||||
@ -640,8 +668,8 @@ Problème de connexion (identifiant, mot de passe): <em>contacter votre responsa
|
|||||||
**kv
|
**kv
|
||||||
):
|
):
|
||||||
"Recuperation des exceptions Zope"
|
"Recuperation des exceptions Zope"
|
||||||
sco_exc_mail = SCO_EXC_MAIL
|
sco_exc_mail = scu.SCO_EXC_MAIL
|
||||||
sco_dev_mail = SCO_DEV_MAIL
|
sco_dev_mail = scu.SCO_DEV_MAIL
|
||||||
# neat (or should I say dirty ?) hack to get REQUEST
|
# neat (or should I say dirty ?) hack to get REQUEST
|
||||||
# in fact, our caller (probably SimpleItem.py) has the REQUEST variable
|
# in fact, our caller (probably SimpleItem.py) has the REQUEST variable
|
||||||
# that we'd like to use for our logs, but does not pass it as an argument.
|
# that we'd like to use for our logs, but does not pass it as an argument.
|
||||||
@ -728,7 +756,7 @@ Problème de connexion (identifiant, mot de passe): <em>contacter votre responsa
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# --- Mail:
|
# --- Mail:
|
||||||
error_traceback_txt = scodoc_html2txt(error_tb)
|
error_traceback_txt = scu.scodoc_html2txt(error_tb)
|
||||||
txt = (
|
txt = (
|
||||||
"""
|
"""
|
||||||
ErrorType: %(error_type)s
|
ErrorType: %(error_type)s
|
||||||
@ -762,7 +790,7 @@ ErrorType: %(error_type)s
|
|||||||
HTTP_USER_AGENT = "na"
|
HTTP_USER_AGENT = "na"
|
||||||
form = REQUEST.get("form", "")
|
form = REQUEST.get("form", "")
|
||||||
HTTP_X_FORWARDED_FOR = REQUEST.get("HTTP_X_FORWARDED_FOR", "")
|
HTTP_X_FORWARDED_FOR = REQUEST.get("HTTP_X_FORWARDED_FOR", "")
|
||||||
svn_version = get_svn_version(self.file_path)
|
svn_version = scu.get_svn_version(self.file_path)
|
||||||
SCOVERSION = VERSION.SCOVERSION
|
SCOVERSION = VERSION.SCOVERSION
|
||||||
|
|
||||||
txt = (
|
txt = (
|
||||||
@ -792,7 +820,7 @@ subversion: %(svn_version)s
|
|||||||
|
|
||||||
def send_debug_alert(self, txt, REQUEST=None):
|
def send_debug_alert(self, txt, REQUEST=None):
|
||||||
"""Send an alert email (bug report) to ScoDoc developpers"""
|
"""Send an alert email (bug report) to ScoDoc developpers"""
|
||||||
if not SCO_EXC_MAIL:
|
if not scu.SCO_EXC_MAIL:
|
||||||
log("send_debug_alert: email disabled")
|
log("send_debug_alert: email disabled")
|
||||||
return
|
return
|
||||||
if REQUEST:
|
if REQUEST:
|
||||||
@ -801,13 +829,13 @@ subversion: %(svn_version)s
|
|||||||
else:
|
else:
|
||||||
URL = "send_debug_alert"
|
URL = "send_debug_alert"
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
subj = Header("[scodoc] exc %s" % URL, SCO_ENCODING)
|
subj = Header("[scodoc] exc %s" % URL, scu.SCO_ENCODING)
|
||||||
msg["Subject"] = subj
|
msg["Subject"] = subj
|
||||||
recipients = [SCO_EXC_MAIL]
|
recipients = [scu.SCO_EXC_MAIL]
|
||||||
msg["To"] = " ,".join(recipients)
|
msg["To"] = " ,".join(recipients)
|
||||||
msg["From"] = "scodoc-alert"
|
msg["From"] = "scodoc-alert"
|
||||||
msg.epilogue = ""
|
msg.epilogue = ""
|
||||||
msg.attach(MIMEText(txt, "plain", SCO_ENCODING))
|
msg.attach(MIMEText(txt, "plain", scu.SCO_ENCODING))
|
||||||
self.sendEmailFromException(msg)
|
self.sendEmailFromException(msg)
|
||||||
log("Sent mail alert:\n" + txt)
|
log("Sent mail alert:\n" + txt)
|
||||||
|
|
||||||
@ -881,7 +909,7 @@ subversion: %(svn_version)s
|
|||||||
"""Liste de id de departements definis par create_dept.sh
|
"""Liste de id de departements definis par create_dept.sh
|
||||||
(fichiers depts/*.cfg)
|
(fichiers depts/*.cfg)
|
||||||
"""
|
"""
|
||||||
filenames = glob.glob(SCODOC_VAR_DIR + "/config/depts/*.cfg")
|
filenames = glob.glob(scu.SCODOC_VAR_DIR + "/config/depts/*.cfg")
|
||||||
ids = [os.path.split(os.path.splitext(f)[0])[1] for f in filenames]
|
ids = [os.path.split(os.path.splitext(f)[0])[1] for f in filenames]
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user