1
0
forked from ScoDoc/ScoDoc
ScoDoc-Front/app/views/essais.py

114 lines
2.6 KiB
Python
Raw Normal View History

# -*- coding: UTF-8 -*
"""
Module Essais: divers essais pour la migration vers Flask
Emmanuel Viennet, 2021
"""
2021-07-12 22:38:30 +02:00
import flask
from flask import g
from flask import current_app
2021-07-12 22:38:30 +02:00
from flask import render_template
from flask import request
2021-07-28 08:12:57 +02:00
from flask import url_for
from app.decorators import (
2021-08-13 00:34:58 +02:00
scodoc,
scodoc7func,
ScoDoc7Context,
permission_required,
admin_required,
login_required,
)
from app.auth.models import Permission
from app.views import essais_bp as bp
2021-07-19 19:53:01 +02:00
from app.scodoc import sco_cache
2021-07-28 08:12:57 +02:00
from app.scodoc import sco_exceptions
context = ScoDoc7Context(globals())
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple")
2021-08-13 00:34:58 +02:00
@scodoc
@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,
}
2021-06-21 10:17:16 +02:00
# En ScoDoc 7, on avait des vues qui en appellaient d'autres
# avec context.sco_exemple( etudid="E12" )
2021-07-19 19:53:01 +02:00
# @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")
2021-08-13 00:34:58 +02:00
@scodoc
@login_required
@scodoc7func(context)
def sco_exemple3(toto):
return "Exemple 3: toto=" + toto
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple4")
2021-08-13 00:34:58 +02:00
@scodoc
@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")
2021-08-13 00:34:58 +02:00
@scodoc
@scodoc7func(context)
def sco_get_version(REQUEST):
2021-07-19 19:53:01 +02:00
return "ok"
# Fonction ressemblant à une méthode Zope protégée
@bp.route("/<scodoc_dept>/Scolarite/sco_test_view")
2021-08-13 00:34:58 +02:00
@scodoc
@permission_required(Permission.ScoView)
2021-08-13 00:34:58 +02:00
@scodoc7func(context)
def sco_test_view(REQUEST=None):
return """Vous avez vu sco_test_view !"""
@bp.route("/essrep")
def essrep():
return flask.Response(status=200, response="Bonjour pépé %s" + u"papa")
2021-07-12 22:38:30 +02:00
# Tests formulaires avec checkbox et GET
@bp.route("/testcheckbox", methods=["GET"])
def testcheckbox():
# args = request.args
return render_template("essais/testcheckbox.html")
2021-07-28 08:12:57 +02:00
# Test exception
@bp.route("/test_exception_value_error", methods=["GET"])
def test_exception_value_error():
raise sco_exceptions.ScoValueError(
"hello",
dest_url=url_for(
"notes.formsemestre_status", scodoc_dept="RT", formsemestre_id="SEM38882"
),
)