forked from ScoDoc/DocScoDoc
88 lines
2.0 KiB
Python
88 lines
2.0 KiB
Python
# -*- 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 essais_bp as bp
|
|
|
|
# import sco_core deviendra:
|
|
from app.scodoc import sco_core
|
|
|
|
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 avait des vues qui en appellaient 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")
|
|
|
|
|
|
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple3")
|
|
@login_required
|
|
@scodoc7func(context)
|
|
def sco_exemple3(toto):
|
|
return "Exemple 3: toto=" + toto
|
|
|
|
|
|
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple4")
|
|
@login_required
|
|
@scodoc7func(context)
|
|
def sco_exemple4(toto):
|
|
return "Exemple 4: " + sco_exemple3(toto)
|
|
|
|
|
|
# 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 !"""
|
|
|
|
|
|
import flask
|
|
|
|
|
|
@bp.route("/essrep")
|
|
def essrep():
|
|
return flask.Response(status=200, response="Bonjour pépé %s" + u"papa")
|