2021-05-31 00:14:15 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
"""
|
|
|
|
Module Essais: divers essais pour la migration vers Flask
|
|
|
|
|
|
|
|
Emmanuel Viennet, 2021
|
|
|
|
"""
|
|
|
|
|
|
|
|
from flask import g
|
|
|
|
from flask import current_app
|
|
|
|
|
|
|
|
from app.decorators import (
|
|
|
|
scodoc7func,
|
|
|
|
ScoDoc7Context,
|
|
|
|
permission_required,
|
|
|
|
admin_required,
|
|
|
|
login_required,
|
|
|
|
)
|
|
|
|
from app.auth.models import Permission
|
|
|
|
|
|
|
|
from app.views import notes_bp as bp
|
|
|
|
|
|
|
|
# import sco_core deviendra:
|
2021-06-02 14:50:41 +02:00
|
|
|
from app.scodoc import sco_core
|
2021-05-31 00:14:15 +02:00
|
|
|
|
|
|
|
context = ScoDoc7Context(globals())
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple")
|
|
|
|
@scodoc7func(context)
|
|
|
|
def sco_exemple(etudid="NON"):
|
|
|
|
"""Un exemple de fonction ScoDoc 7"""
|
|
|
|
return """<html>
|
|
|
|
<body><h1>ScoDoc 7 rules !</h1>
|
|
|
|
<p>etudid=%(etudid)s</p>
|
|
|
|
<p>g.scodoc_dept=%(scodoc_dept)s</p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
""" % {
|
|
|
|
"etudid": etudid,
|
|
|
|
"scodoc_dept": g.scodoc_dept,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# En ScoDoc 7, on a souvent des vues qui en appellent d'autres
|
|
|
|
# avec context.sco_exemple( etudid="E12" )
|
|
|
|
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple2")
|
|
|
|
@login_required
|
|
|
|
@scodoc7func(context)
|
|
|
|
def sco_exemple2():
|
|
|
|
return "Exemple 2" + context.sco_exemple(etudid="deux")
|
|
|
|
|
|
|
|
|
|
|
|
# Test avec un seul argument REQUEST positionnel
|
|
|
|
@bp.route("/<scodoc_dept>/Scolarite/sco_get_version")
|
|
|
|
@scodoc7func(context)
|
|
|
|
def sco_get_version(REQUEST):
|
|
|
|
return sco_core.sco_get_version(REQUEST)
|
|
|
|
|
|
|
|
|
|
|
|
# Fonction ressemblant à une méthode Zope protégée
|
|
|
|
@bp.route("/<scodoc_dept>/Scolarite/sco_test_view")
|
|
|
|
@scodoc7func(context)
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
def sco_test_view(REQUEST=None):
|
|
|
|
return """Vous avez vu sco_test_view !"""
|