Page accueil (suppressions essais).

This commit is contained in:
Emmanuel Viennet 2021-08-17 22:11:35 +02:00
parent a96ee67294
commit c8df244d4c
10 changed files with 19 additions and 339 deletions

View File

@ -65,18 +65,12 @@ def create_app(config_class=DevConfig):
app.register_blueprint(auth_bp, url_prefix="/auth")
from app.views import essais_bp
app.register_blueprint(essais_bp, url_prefix="/Essais")
from app.main import bp as main_bp
from app.views import scodoc_bp
from app.views import scolar_bp
from app.views import notes_bp
from app.views import users_bp
from app.views import absences_bp
app.register_blueprint(main_bp) # XXX à enlever en production #sco8
# https://scodoc.fr/ScoDoc
app.register_blueprint(scodoc_bp)
# https://scodoc.fr/ScoDoc/RT/Scolarite/...

View File

@ -29,7 +29,7 @@ _l = _
@bp.route("/login", methods=["GET", "POST"])
def login():
if current_user.is_authenticated:
return redirect(url_for("main.index"))
return redirect(url_for("scodoc.index"))
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(user_name=form.user_name.data).first()
@ -39,7 +39,7 @@ def login():
login_user(user, remember=form.remember_me.data)
next_page = request.args.get("next")
if not next_page or url_parse(next_page).netloc != "":
next_page = url_for("main.index")
next_page = url_for("scodoc.index")
return redirect(next_page)
return render_template("auth/login.html", title=_("Sign In"), form=form)
@ -47,7 +47,7 @@ def login():
@bp.route("/logout")
def logout():
logout_user()
return redirect(url_for("main.index"))
return redirect(url_for("scodoc.index"))
@bp.route("/create_user", methods=["GET", "POST"])
@ -61,7 +61,7 @@ def create_user():
db.session.add(user)
db.session.commit()
flash("User {} created".format(user.user_name))
return redirect(url_for("main.index"))
return redirect(url_for("scodoc.index"))
return render_template(
"auth/register.html", title=u"Création utilisateur", form=form
)
@ -70,7 +70,7 @@ def create_user():
@bp.route("/reset_password_request", methods=["GET", "POST"])
def reset_password_request():
if current_user.is_authenticated:
return redirect(url_for("main.index"))
return redirect(url_for("scodoc.index"))
form = ResetPasswordRequestForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
@ -90,10 +90,10 @@ def reset_password_request():
@bp.route("/reset_password/<token>", methods=["GET", "POST"])
def reset_password(token):
if current_user.is_authenticated:
return redirect(url_for("main.index"))
return redirect(url_for("scodoc.index"))
user = User.verify_reset_password_token(token)
if not user:
return redirect(url_for("main.index"))
return redirect(url_for("scodoc.index"))
form = ResetPasswordForm()
if form.validate_on_submit():
user.set_password(form.password.data)

View File

@ -1,8 +0,0 @@
# main Blueprint
Quelques essais pour la migration.
TODO: Ne sera pas conservé.

View File

@ -1,6 +0,0 @@
# -*- coding: UTF-8 -*
from flask import Blueprint
bp = Blueprint("main", __name__)
from app.main import routes

View File

@ -1,192 +0,0 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# ScoDoc
#
# Copyright (c) 1999 - 2021 Emmanuel Viennet. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Emmanuel Viennet emmanuel.viennet@viennet.net
#
##############################################################################
"""
Module main: essais divers
Emmanuel Viennet, 2021
"""
import io
import pprint
from pprint import pprint as pp
import functools
import six.moves._thread # essai
from zipfile import ZipFile
import flask
from flask import request, render_template, redirect
from flask_login import login_required
import werkzeug
from app.main import bp
from app.decorators import scodoc7func, admin_required
from app.scodoc import VERSION
context = None # temporaire pour #sco8
# -------------------------------------------------------------
#
# ESSAIS DIVERS pour #sco8
#
# -------------------------------------------------------------
@bp.route("/")
@bp.route("/index")
def index():
return render_template(
"main/index.html",
title=u"Essai Flask",
current_app=flask.current_app,
flask=flask,
werzeug=werkzeug,
)
@bp.route("/test_vue")
@login_required
def test_vue():
return """Vous avez vu. <a href="/">Retour à l'accueil</a>"""
def get_request_infos():
return [
"<p>request.base_url=%s</p>" % request.base_url,
"<p>request.url_root=%s</p>" % request.url_root,
"<p>request.query_string=%s</p>" % request.query_string,
]
D = {"count": 0}
# @app.route("/")
# @app.route("/index")
# def index():
# sleep(8)
# D["count"] = D.get("count", 0) + 1
# return "Hello, World! %s count=%s" % (thread.get_ident(), D["count"])
@bp.route("/zopefunction", methods=["POST", "GET"])
@login_required
@scodoc7func(context)
def a_zope_function(y, x="defaut", REQUEST=None):
"""Une fonction typique de ScoDoc7"""
H = get_request_infos() + [
"<p><b>x=<tt>%s</tt></b></p>" % x,
"<p><b>y=<tt>%s</tt></b></p>" % y,
"<p><b>URL=<tt>%s</tt></b></p>" % REQUEST.URL,
"<p><b>QUERY_STRING=<tt>%s</tt></b></p>" % REQUEST.QUERY_STRING,
"<p><b>AUTHENTICATED_USER=<tt>%s</tt></b></p>" % REQUEST.AUTHENTICATED_USER,
]
H.append("<p><b>form=<tt>%s</tt></b></p>" % REQUEST.form)
H.append("<p><b>form[x]=<tt>%s</tt></b></p>" % REQUEST.form.get("x", "non fourni"))
return "\n".join(H)
@bp.route("/zopeform_get")
@scodoc7func(context)
def a_zope_form_get(REQUEST=None):
H = [
"""<h2>Formulaire GET</h2>
<form action="%s" method="get">
x : <input type="text" name="x"/><br/>
y : <input type="text" name="y"/><br/>
fichier : <input type="file" name="fichier"/><br/>
<input type="submit" value="Envoyer"/>
</form>
"""
% flask.url_for("main.a_zope_function")
]
return "\n".join(H)
@bp.route("/zopeform_post")
@scodoc7func(context)
def a_zope_form_post(REQUEST=None):
H = [
"""<h2>Formulaire POST</h2>
<form action="%s" method="post" enctype="multipart/form-data">
x : <input type="text" name="x"/><br/>
y : <input type="text" name="y"/><br/>
fichier : <input type="file" name="fichier"/><br/>
<input type="submit" value="Envoyer"/>
</form>
"""
% flask.url_for("main.a_zope_function")
]
return "\n".join(H)
@bp.route("/ScoDoc/<dept_id>/Scolarite/Notes/formsemestre_statux")
@scodoc7func(context)
def formsemestre_statux(dept_id=None, formsemestre_id=None, REQUEST=None):
"""Essai méthode de département
Le contrôle d'accès doit vérifier les bons rôles : ici Ens<dept_id>
"""
return u"""dept_id=%s , formsemestre_id=%s <a href="/">Retour à l'accueil</a>""" % (
dept_id,
formsemestre_id,
)
@bp.route("/hello/world")
def hello():
H = get_request_infos() + [
"<p>Hello, World! %s count=%s</p>"
% (six.moves._thread.get_ident(), D["count"]),
]
# print(pprint.pformat(dir(request)))
return "\n".join(H)
@bp.route("/getzip")
def getzip():
"""Essai renvoi d'un ZIP en Flask"""
# La version Zope:
# REQUEST.RESPONSE.setHeader("content-type", "application/zip")
# REQUEST.RESPONSE.setHeader("content-length", size)
# REQUEST.RESPONSE.setHeader(
# "content-disposition", 'attachement; filename="monzip.zip"'
# )
zipdata = io.StringIO()
zipfile = ZipFile(zipdata, "w")
zipfile.writestr("fichier1", "un contenu")
zipfile.writestr("fichier2", "deux contenus")
zipfile.close()
data = zipdata.getvalue()
size = len(data)
# open("/tmp/toto.zip", "w").write(data)
# Flask response:
r = flask.Response(response=data, status=200, mimetype="application/zip")
r.headers["Content-Type"] = "application/zip"
r.headers["content-length"] = size
r.headers["content-disposition"] = 'attachement; filename="monzip.zip"'
return r

View File

@ -24,8 +24,7 @@
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="{{ url_for('main.index') }}">Home</a></li>
<li><a href="{{ url_for('main.hello') }}">Hello</a></li>
<li><a href="{{ url_for('scodoc.index') }}">Home</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
{% if current_user.is_anonymous %}

View File

@ -2,7 +2,7 @@
{% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %}
<h2>ScoDoc: gestion scolarité</h2>
<h2>ScoDoc: gestion scolarité (version développement)</h2>
{% if not current_user.is_anonymous %}
<p>Bonjour <font color="red"><b>{{current_user.get_nomcomplet()}}</b>
@ -24,6 +24,11 @@
{% endfor %}
</ul>
<p>
<font color="red">Ceci est une version pour développeurs,
ne pas utiliser en production !</font>
</p>
{% if current_user.is_authenticated %}
<form action="table_etud_in_accessible_depts" method="POST">
<b>Chercher étudiant:</b>
@ -33,8 +38,8 @@
</form>
{% endif %}
<div style="margin-top: 1cm; font-size: 120%;">
<p><a href="/ScoDoc/static/mobile">Version mobile (expérimentale, à vos risques et périls)</a></p>
<div style="margin-top: 1cm;">
<p><a href="/ScoDoc/static/mobile">Charger la version mobile (expérimentale)</a></p>
</div>
{% endblock %}

View File

@ -10,9 +10,9 @@ scolar_bp = Blueprint("scolar", __name__)
notes_bp = Blueprint("notes", __name__)
users_bp = Blueprint("users", __name__)
absences_bp = Blueprint("absences", __name__)
essais_bp = Blueprint("essais", __name__)
from app.views import scodoc, notes, scolar, absences, users, essais
from app.views import scodoc, notes, scolar, absences, users
# Cette fonction est bien appelée avant toutes les requêtes
# de tous les blueprints

View File

@ -1,113 +0,0 @@
# -*- coding: UTF-8 -*
"""
Module Essais: divers essais pour la migration vers Flask
Emmanuel Viennet, 2021
"""
import flask
from flask import g
from flask import current_app
from flask import render_template
from flask import request
from flask import url_for
from app.decorators import (
scodoc,
scodoc7func,
ScoDoc7Context,
permission_required,
admin_required,
login_required,
)
from app.auth.models import Permission
from app.views import essais_bp as bp
from app.scodoc import sco_cache
from app.scodoc import sco_exceptions
context = ScoDoc7Context(globals())
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple")
@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,
}
# 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")
@scodoc
@login_required
@scodoc7func(context)
def sco_exemple3(toto):
return "Exemple 3: toto=" + toto
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple4")
@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")
@scodoc
@scodoc7func(context)
def sco_get_version(REQUEST):
return "ok"
# Fonction ressemblant à une méthode Zope protégée
@bp.route("/<scodoc_dept>/Scolarite/sco_test_view")
@scodoc
@permission_required(Permission.ScoView)
@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")
# Tests formulaires avec checkbox et GET
@bp.route("/testcheckbox", methods=["GET"])
def testcheckbox():
# args = request.args
return render_template("essais/testcheckbox.html")
# 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"
),
)

View File

@ -42,6 +42,7 @@ from app.scodoc.sco_permissions import Permission
from app.views import scodoc_bp as bp
@bp.route("/")
@bp.route("/ScoDoc")
@bp.route("/ScoDoc/index")
def index():