diff --git a/app/__init__.py b/app/__init__.py index 754cfa880..ffaedae58 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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/... diff --git a/app/auth/routes.py b/app/auth/routes.py index b4b98a4ea..d13f3e6e2 100644 --- a/app/auth/routes.py +++ b/app/auth/routes.py @@ -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/", 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) diff --git a/app/main/README.md b/app/main/README.md deleted file mode 100644 index 0f4acc044..000000000 --- a/app/main/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# main Blueprint - -Quelques essais pour la migration. - -TODO: Ne sera pas conservé. - - - diff --git a/app/main/__init__.py b/app/main/__init__.py deleted file mode 100644 index a27dd27d7..000000000 --- a/app/main/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: UTF-8 -* -from flask import Blueprint - -bp = Blueprint("main", __name__) - -from app.main import routes diff --git a/app/main/routes.py b/app/main/routes.py deleted file mode 100644 index 8323ef2da..000000000 --- a/app/main/routes.py +++ /dev/null @@ -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. Retour à l'accueil""" - - -def get_request_infos(): - return [ - "

request.base_url=%s

" % request.base_url, - "

request.url_root=%s

" % request.url_root, - "

request.query_string=%s

" % 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() + [ - "

x=%s

" % x, - "

y=%s

" % y, - "

URL=%s

" % REQUEST.URL, - "

QUERY_STRING=%s

" % REQUEST.QUERY_STRING, - "

AUTHENTICATED_USER=%s

" % REQUEST.AUTHENTICATED_USER, - ] - H.append("

form=%s

" % REQUEST.form) - H.append("

form[x]=%s

" % REQUEST.form.get("x", "non fourni")) - - return "\n".join(H) - - -@bp.route("/zopeform_get") -@scodoc7func(context) -def a_zope_form_get(REQUEST=None): - H = [ - """

Formulaire GET

-
- x :
- y :
- fichier :
- -
- """ - % 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 = [ - """

Formulaire POST

-
- x :
- y :
- fichier :
- -
- """ - % flask.url_for("main.a_zope_function") - ] - return "\n".join(H) - - -@bp.route("/ScoDoc//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 - """ - return u"""dept_id=%s , formsemestre_id=%s Retour à l'accueil""" % ( - dept_id, - formsemestre_id, - ) - - -@bp.route("/hello/world") -def hello(): - H = get_request_infos() + [ - "

Hello, World! %s count=%s

" - % (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 diff --git a/app/templates/base.html b/app/templates/base.html index 321d41ac5..1b48464b2 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -24,8 +24,7 @@