Abandonne Flask-Bootstrap

This commit is contained in:
Emmanuel Viennet 2023-11-15 20:38:51 +01:00
parent 1a841c3e6d
commit a821add6a6
51 changed files with 370 additions and 122 deletions

View File

@ -19,11 +19,7 @@ from flask import current_app, g, request
from flask import Flask
from flask import abort, flash, has_request_context
from flask import render_template
# from flask.json import JSONEncoder
from flask.logging import default_handler
from flask_bootstrap import Bootstrap
from flask_caching import Cache
from flask_json import FlaskJSON, json_response
from flask_login import LoginManager, current_user
@ -34,6 +30,7 @@ from flask_sqlalchemy import SQLAlchemy
from jinja2 import select_autoescape
import sqlalchemy as sa
import werkzeug.debug
from wtforms.fields import HiddenField
from flask_cas import CAS
@ -59,8 +56,6 @@ login.login_view = "auth.login"
login.login_message = "Identifiez-vous pour accéder à cette page."
mail = Mail()
bootstrap = Bootstrap()
# moment = Moment()
CACHE_TYPE = os.environ.get("CACHE_TYPE")
cache = Cache(
@ -304,7 +299,6 @@ def create_app(config_class=DevConfig):
login.init_app(app)
mail.init_app(app)
app.extensions["mail"].debug = 0 # disable copy of mails to stderr
bootstrap.init_app(app)
cache.init_app(app)
sco_cache.CACHE = cache
if CACHE_TYPE: # non default
@ -320,6 +314,12 @@ def create_app(config_class=DevConfig):
app.register_error_handler(503, postgresql_server_error)
app.register_error_handler(APIInvalidParams, handle_invalid_usage)
# Add some globals
# previously in Flask-Bootstrap:
app.jinja_env.globals["bootstrap_is_hidden_field"] = lambda field: isinstance(
field, HiddenField
)
from app.auth import bp as auth_bp
app.register_blueprint(auth_bp, url_prefix="/auth")
@ -549,8 +549,8 @@ def truncate_database():
CREATE OR REPLACE FUNCTION reset_sequences(username IN VARCHAR) RETURNS void AS $$
DECLARE
statements CURSOR FOR
SELECT sequence_name
FROM information_schema.sequences
SELECT sequence_name
FROM information_schema.sequences
ORDER BY sequence_name ;
BEGIN
FOR stmt IN statements LOOP

View File

@ -95,7 +95,7 @@ _HTML_BEGIN = f"""<!DOCTYPE html>
<title>%(page_title)s</title>
<link type="text/css" rel="stylesheet" href="{scu.STATIC_DIR}/libjs/jquery-ui-1.10.4.custom/css/smoothness/jquery-ui-1.10.4.custom.min.css" />
<link href="{scu.STATIC_DIR}/css/scodoc.css" rel="stylesheet" type="text/css" />
<link href="{scu.STATIC_DIR}/css/menu.css" rel="stylesheet" type="text/css" />
<script src="{scu.STATIC_DIR}/libjs/menu.js"></script>
@ -212,7 +212,7 @@ def sco_header(
<script>
window.onload=function(){{enableTooltips("gtrcontent")}};
var SCO_URL="{scu.ScoURL()}";
const SCO_URL="{scu.ScoURL()}";
</script>"""
)

1
app/static/libjs/bootstrap Symbolic link
View File

@ -0,0 +1 @@
bootstrap-3.1.1-dist

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
@ -12,7 +12,7 @@
<p>ScoDoc est un logiciel libre écrit en
<a href="http://www.python.org" target="_blank" rel="noopener noreferrer">Python</a>.
Information et documentation sur
Information et documentation sur
<a href="https://scodoc.org" target="_blank" rel="noopener>scodoc.org</a>.
</p>
@ -37,4 +37,4 @@
{{ logo|safe }}
</div>
{% endblock %}
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}

View File

@ -1,5 +1,5 @@
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Chargement des configurations CAS des utilisateurs</h1>
@ -17,15 +17,15 @@
<li style="margin-bottom:8px;">Vous modifiez cette feuille avec votre logiciel préféré.
Vous pouvez supprimer des lignes, mais pas en ajouter.
<br>
On peut remplir ou modifier le contenu des colonnes <tt>active</tt>,
On peut remplir ou modifier le contenu des colonnes <tt>active</tt>,
<tt>cas_id</tt>, <tt>cas_allow_login</tt>, <tt>cas_allow_scodoc_login</tt>,
et <tt>email_institutionnel</tt>
<br>
Les autres colonnes sont là pour information et seront ignorées à l'import,
Les autres colonnes sont là pour information et seront ignorées à l'import,
sauf évidemment <tt>user_name</tt> qui sert à repérer l'utilisateur.
<br>
(Note: <tt>active</tt> active ou désactive le compte, sans lien avec CAS, mais il
est commode de réviser la liste des utilisateurs actifs à l'occasion de la configuration CAS.
(Note: <tt>active</tt> active ou désactive le compte, sans lien avec CAS, mais il
est commode de réviser la liste des utilisateurs actifs à l'occasion de la configuration CAS.
Pareil pour <tt>email_institutionnel</tt>)
</li>
@ -49,4 +49,4 @@
</ul>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% macro render_field(field, auth_name=None) %}
<tr style="">
@ -50,4 +50,4 @@
<input type="submit" value="Valider">
<input type="submit" name="cancel" value="Annuler" style="margin-left: 1em;>
</form>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
@ -27,4 +27,4 @@ En cas d'oubli de votre mot de passe ScoDoc
<p class="help">L'accès à ScoDoc est strictement réservé aux personnels de
l'établissement. Les étudiants n'y ont pas accès. Pour toute information,
contactez la personne responsable de votre établissement.</p>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Création utilisateur</h1>
@ -9,4 +9,4 @@
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Changez votre mot de passe ScoDoc</h1>
@ -14,4 +14,4 @@
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Demande d'un nouveau mot de passe</h1>
@ -11,13 +11,13 @@
</div>
{% if is_cas_enabled %}
<div style="margin-top: 12px; color: red;">
<p>Attention: ce mécanisme permet de changer le mot de passe ScoDoc
<p>Attention: ce mécanisme permet de changer le mot de passe ScoDoc
mais ne changera pas votre mot de passe sur le système de l'établissement.
</p>
<p>
Si vous vous connectez via vos identifiants de l'université (CAS), passez
Si vous vous connectez via vos identifiants de l'université (CAS), passez
par la procédure de celle-ci (ENT ou autre).
</p>
</div>
{% endif %}
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>{{ "Désactiver" if u.active else "Activer" }} l'utilisateur {{ u.get_nomplogin() }} ?</h1>
@ -15,4 +15,4 @@
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
@ -45,14 +45,14 @@
or current_user.has_permission(Permission.UsersAdmin, user.dept)
) %}
<li><a class="stdlink" href="{{
url_for( 'users.form_change_password',
url_for( 'users.form_change_password',
scodoc_dept=g.scodoc_dept, user_name=user.user_name)
}}">modifier le mot de passe ou l'adresse mail</a>
</li>
{% endif %}
{% if current_user.has_permission(Permission.UsersAdmin, dept) %}
<li><a class="stdlink" href="{{
url_for('users.create_user_form', scodoc_dept=g.scodoc_dept,
url_for('users.create_user_form', scodoc_dept=g.scodoc_dept,
user_name=user.user_name, edit=1)
}}">modifier ce compte et ses rôles</a>
</li>
@ -62,7 +62,7 @@
or current_user.has_permission(Permission.UsersAdmin, user.dept)
) %}
<li><a class="stdlink" href="{{
url_for('users.toggle_active_user', scodoc_dept=g.scodoc_dept,
url_for('users.toggle_active_user', scodoc_dept=g.scodoc_dept,
user_name=user.user_name)
}}">{{"désactiver" if user.active else "activer"}} ce compte</a>
</li>
@ -105,4 +105,4 @@
{% endif %}
{% endblock %}
{% endblock %}

34
app/templates/babase.j2 Normal file
View File

@ -0,0 +1,34 @@
{% block doc -%}
<!DOCTYPE html>
<html{% block html_attribs %}{% endblock html_attribs %}>
{%- block html %}
<head>
{%- block head %}
<title>{% block title %}{{title|default}}{% endblock title %}</title>
{%- block metas %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{%- endblock metas %}
{%- block styles %}
<!-- Bootstrap -->
<link href="{{scu.STATIC_DIR}}/libjs/bootstrap/css/bootstrap.css" rel="stylesheet">
{%- endblock styles %}
{%- endblock head %}
</head>
<body{% block body_attribs %}{% endblock body_attribs %}>
{% block body -%}
{% block navbar %}
{%- endblock navbar %}
{% block content -%}
{%- endblock content %}
{% block scripts %}
<script src="{{scu.STATIC_DIR}}/jQuery/jquery.js"></script>
<script src="{{scu.STATIC_DIR}}/libjs/bootstrap/js/bootstrap.js"></script>
{%- endblock scripts %}
{%- endblock body %}
</body>
{%- endblock html %}
</html>
{% endblock doc -%}

View File

@ -1,5 +1,5 @@
{# -*- mode: jinja-html -*- #}
{% extends 'bootstrap/base.html' %}
{% extends 'babase.j2' %}
{% block styles %}
{{super()}}
@ -32,8 +32,8 @@
<li><a href="{{ url_for('scodoc.configuration') }}">Configuration</a></li>
{% endif %}
{% if g.scodoc_dept %}
<li><a href="{{
url_for('scolar.index_html', scodoc_dept=g.scodoc_dept)
<li><a href="{{
url_for('scolar.index_html', scodoc_dept=g.scodoc_dept)
}}">Dept. {{ g.scodoc_dept }}</a></li>
{% endif %}
{% if not current_user.is_anonymous and
@ -92,6 +92,6 @@
<script src="{{scu.STATIC_DIR}}/libjs/qtip/jquery.qtip-3.0.3.min.js"></script>
<script src="{{scu.STATIC_DIR}}/js/scodoc.js"></script>
<script>
var SCO_URL = "{{ url_for('scolar.index_html', scodoc_dept=g.scodoc_dept)[:-11] }}";
const SCO_URL = "{{ url_for('scolar.index_html', scodoc_dept=g.scodoc_dept)[:-11] }}";
</script>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "sco_page.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}
@ -53,4 +53,4 @@
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Associer un référentiel de compétences</h1>
@ -15,7 +15,7 @@
Référentiel actuellement associé:
{% if formation.referentiel_competence is not none %}
<b>{{ formation.referentiel_competence.specialite_long }}</b>
<a href="{{
<a href="{{
url_for('notes.refcomp_desassoc_formation', scodoc_dept=g.scodoc_dept, formation_id=formation.id)
}}" class="stdlink">supprimer</a>
{% else %}
@ -35,4 +35,4 @@
}}">passer par cette page</a>.
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Charger un référentiel de compétences</h1>
@ -28,4 +28,4 @@
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "sco_page.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h2>Référentiels de compétences chargés</h2>
@ -32,4 +32,4 @@
ScoDoc importe le format XML généré par Orébut, et peut exporter une représentation JSON.
</p>
{% endblock %}
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Configuration du Service d'Authentification Central (CAS)</h1>

View File

@ -1,5 +1,5 @@
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Configuration des codes de décision exportés vers Apogée</h1>
@ -20,4 +20,4 @@
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% macro render_field(field, with_label=True) %}
<div>
@ -130,4 +130,4 @@
{% endfor %}
</div>
</form>
{% endblock %}
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}
@ -81,4 +81,4 @@ div.validation-buttons {
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% macro render_field(field, with_label=True) %}
<div>

View File

@ -1,5 +1,5 @@
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
@ -18,4 +18,4 @@
</form>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Créer un département</h1>
@ -12,4 +12,4 @@
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}
@ -59,4 +59,4 @@
var as_utilisateurs = new bsn.AutoSuggest('utilisateur', responsables_options);
</script>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}
@ -88,4 +88,4 @@
}
}
</script>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Ajout entreprise</h1>
@ -55,4 +55,4 @@
document.getElementById("ville").value = ''
}
</script>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}
@ -72,7 +72,7 @@
<label for="${newFieldName}">Responsable (*)</label>
<input class="form-control" id="${newFieldName}" name="${newFieldName}" type="text" value="" placeholder="Tapez le nom du responsable de formation">
<div class="btn btn-default btn-remove" onclick="deleteForm('${newFieldName}')">Retirer</div>
</li>
</li>
`);
var as_r = new bsn.AutoSuggest(newFieldName, responsables_options);
});
@ -85,4 +85,4 @@
}
}
</script>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}
@ -65,4 +65,4 @@
document.getElementById("ville").value = response.etablissement.libelle_commune
}
</script>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Validation entreprise</h1>
@ -12,4 +12,4 @@
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}
@ -195,7 +195,7 @@
Code postal : {{ entreprise.codepostal }}<br>
Ville : {{ entreprise.ville }}<br>
Pays : {{ entreprise.pays }}<br>
<a href="{{ url_for('entreprises.fiche_entreprise', entreprise_id=entreprise.id) }}"
<a href="{{ url_for('entreprises.fiche_entreprise', entreprise_id=entreprise.id) }}"
rel="noopener noreferrer" target="_blank"
>Fiche entreprise</a>
</div>
@ -222,7 +222,7 @@
Code postal : {{ site.codepostal }}<br>
Ville : {{ site.ville }}<br>
Pays : {{ site.pays }}<br>
<a href="{{ url_for('entreprises.fiche_entreprise', entreprise_id=site.entreprise_id)
<a href="{{ url_for('entreprises.fiche_entreprise', entreprise_id=site.entreprise_id)
}}" rel="noopener noreferrer" target="_blank"
>Fiche entreprise</a>
</div>
@ -264,4 +264,4 @@
{% endif %}
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
{% include 'entreprises/nav.j2' %}
@ -14,4 +14,4 @@
</div>
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block title %}Une erreur est survenue !{% endblock %}
@ -12,14 +12,14 @@
<p><tt style="font-size:60%">{{date}}</tt></p>
<p> Si le problème persiste, contacter l'administrateur de votre site,
ou <b>l'assistance sur <a href="{{ scu.SCO_DISCORD_ASSISTANCE
ou <b>l'assistance sur <a href="{{ scu.SCO_DISCORD_ASSISTANCE
}}">le canal Discord</a></b>.
</p>
{% if 'scodoc_dept' in g %}
<p>Pour aider à corriger le problème, nous vous
<b>remercions d'envoyer ce rapport d'erreur</b>
(qui contient des données anonymisées sur votre configuration):
<form method="POST" action="{{ url_for( 'scolar.sco_dump_and_send_db',
<form method="POST" action="{{ url_for( 'scolar.sco_dump_and_send_db',
scodoc_dept=g.scodoc_dept ) }}">
<input type="hidden" name="request_url" value="{{request_url}}">
<input type="hidden" name="traceback_str_base64" value="{{traceback_str_base64}}">
@ -38,4 +38,4 @@
<a href="{{ url_for('scodoc.index') }}">retour à la page d'accueil</a>
</p>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
@ -17,4 +17,4 @@
{% endif %}
</p>
{% endblock %}
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
@ -15,4 +15,4 @@
<button type="submit">Veuillez vous reconnecter</button>
</form>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>{{ title }}</h1>
@ -12,4 +12,4 @@
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# Association d'ECTS à une UE par parcours #}
{% extends "sco_page.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}

View File

@ -1,5 +1,5 @@
{% extends "sco_page.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}

View File

@ -1,5 +1,5 @@
{% extends "sco_page.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}

View File

@ -1,5 +1,5 @@
{% extends "sco_page.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
@ -54,4 +54,4 @@
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,5 +1,5 @@
{# -*- mode: jinja-html -*- #}
{% extends 'bootstrap/base.html' %}
{% extends 'babase.j2' %}
{% block styles %}
{{super()}}
@ -52,7 +52,7 @@
<script>
window.onload = function () { enableTooltips("gtrcontent") };
var SCO_URL = "{{ url_for('scolar.index_html', scodoc_dept=g.scodoc_dept)[:-11] }}";
const SCO_URL = "{{ url_for('scolar.index_html', scodoc_dept=g.scodoc_dept)[:-11] }}";
</script>
{% endblock %}
{% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h2>ScoDoc 9 - suivi scolarité</h2>
@ -53,7 +53,7 @@
</form>
{% endif %}
<!--
<!--
<div style="margin-top: 1cm;">
<p><a href="/ScoDoc/static/mobile">Charger la version mobile (expérimentale)</a></p>
</div> -->
@ -63,4 +63,4 @@
<a href="{{scu.SCO_WEBSITE}}">le logiciel libre ScoDoc.</a>
</div>
{% endblock %}
{% endblock %}

View File

@ -1,4 +1,4 @@
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% macro render_field(field) %}
<tr>
@ -77,4 +77,4 @@
</ul>
</li>
</ul>
</div>
</div>

View File

@ -1,12 +1,12 @@
{# -*- mode: jinja-html -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Créer un rôle</h1>
<div class="help">
Un rôle est associé à un ensemble de permissions.
Un rôle est associé à un ensemble de permissions.
Les utilisateurs peuvent avoir un ou plusieurs rôles dans chaque département.
</div>
@ -19,4 +19,4 @@ Les utilisateurs peuvent avoir un ou plusieurs rôles dans chaque département.
</div>
{% endblock %}
{% endblock %}

View File

@ -1,7 +1,7 @@
{# -*- mode: jinja-html -*- #}
{# -*- Edition des rôles/permissions -*- #}
{% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% import 'wtf.j2' as wtf %}
{% block styles %}
{{super()}}
@ -14,7 +14,7 @@
<div class="help">Les rôles sont associés à un ensemble de permissions. Chaque
utilisateur peut avoir un nombre quelconque de rôles <em>dans chaque
département</em>.
département</em>.
Sur cette page vous pouvez modifier les permissions associée à chaque rôle, ou créer de nouveaux rôles.
Les rôles <b>en gras</b> sont les rôles standards de ScoDoc.
@ -38,7 +38,7 @@ Les rôles <b>en gras</b> sont les rôles standards de ScoDoc.
</div>
{% for permission_name in permissions_names %}
<div class="re-row re-row-perm">
<div class="re-cell permission-titre" style="position: relative;">
<div class="re-cell permission-titre" style="position: relative;">
<div class="with_scoplement">
<div><a class="discretelink" href="{{
url_for('scodoc.permission_info', perm_name=permission_name)
@ -51,7 +51,7 @@ Les rôles <b>en gras</b> sont les rôles standards de ScoDoc.
{% for role in roles %}
<div class="re-cell {{'role-standard' if role.name in SCO_ROLES_DEFAULTS else ''}}">
<label>
<input type="checkbox"
<input type="checkbox"
name="{{role.id}}-{{Permission.get_by_name(permission_name)}}"
data-role="{{role.name}}"
data-permission="{{permission_name}}"
@ -100,13 +100,13 @@ async function associe_role_permission(event) {
}
}
document.querySelectorAll("label").forEach(btn => {
btn.addEventListener("mousedown", (event) => { event.preventDefault() })
document.querySelectorAll("label").forEach(btn => {
btn.addEventListener("mousedown", (event) => { event.preventDefault() })
});
document.querySelectorAll(".re-cell input").forEach(input => {
input.addEventListener("input", associe_role_permission)
input.addEventListener("input", associe_role_permission)
});
</script>
{% endblock %}
{% endblock %}

214
app/templates/wtf.j2 Normal file
View File

@ -0,0 +1,214 @@
{# was wtf.html in Flask-Bootstrap #}
{% macro form_errors(form, hiddens=True) %}
{%- if form.errors %}
{%- for fieldname, errors in form.errors.items() %}
{%- if bootstrap_is_hidden_field(form[fieldname]) and hiddens or
not bootstrap_is_hidden_field(form[fieldname]) and hiddens != 'only' %}
{%- for error in errors %}
<p class="error">{{error}}</p>
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endmacro %}
{% macro _hz_form_wrap(horizontal_columns, form_type, add_group=False, required=False) %}
{% if form_type == "horizontal" %}
{% if add_group %}<div class="form-group{% if required %} required{% endif %}">{% endif %}
<div class="col-{{horizontal_columns[0]}}-offset-{{horizontal_columns[1]}}
col-{{horizontal_columns[0]}}-{{horizontal_columns[2]}}
">
{% endif %}
{{caller()}}
{% if form_type == "horizontal" %}
{% if add_group %}</div>{% endif %}
</div>
{% endif %}
{% endmacro %}
{% macro form_field(field,
form_type="basic",
horizontal_columns=('lg', 2, 10),
button_map={}) %}
{# this is a workaround hack for the more straightforward-code of just passing required=required parameter. older versions of wtforms do not have
the necessary fix for required=False attributes, but will also not set the required flag in the first place. we skirt the issue using the code below #}
{% if field.flags.required and not required in kwargs %}
{% set kwargs = dict(required=True, **kwargs) %}
{% endif %}
{% if field.widget.input_type == 'checkbox' %}
{% call _hz_form_wrap(horizontal_columns, form_type, True, required=required) %}
<div class="checkbox">
<label>
{{field()|safe}} {{field.label.text|safe}}
</label>
</div>
{% endcall %}
{%- elif field.type == 'RadioField' -%}
{# note: A cleaner solution would be rendering depending on the widget,
this is just a hack for now, until I can think of something better #}
{% call _hz_form_wrap(horizontal_columns, form_type, True, required=required) %}
{% for item in field -%}
<div class="radio">
<label>
{{item|safe}} {{item.label.text|safe}}
</label>
</div>
{% endfor %}
{% endcall %}
{%- elif field.type == 'SubmitField' -%}
{# deal with jinja scoping issues? #}
{% set field_kwargs = kwargs %}
{# note: same issue as above - should check widget, not field type #}
{% call _hz_form_wrap(horizontal_columns, form_type, True, required=required) %}
{{field(class='btn btn-%s' % button_map.get(field.name, 'default'),
**field_kwargs)}}
{% endcall %}
{%- elif field.type == 'FormField' -%}
{# note: FormFields are tricky to get right and complex setups requiring
these are probably beyond the scope of what this macro tries to do.
the code below ensures that things don't break horribly if we run into
one, but does not try too hard to get things pretty. #}
<fieldset>
<legend>{{field.label}}</legend>
{%- for subfield in field %}
{% if not bootstrap_is_hidden_field(subfield) -%}
{{ form_field(subfield,
form_type=form_type,
horizontal_columns=horizontal_columns,
button_map=button_map) }}
{%- endif %}
{%- endfor %}
</fieldset>
{% else -%}
<div class="form-group {% if field.errors %} has-error{% endif -%}
{%- if field.flags.required %} required{% endif -%}
">
{%- if form_type == "inline" %}
{{field.label(class="sr-only")|safe}}
{% if field.type == 'FileField' %}
{{field(**kwargs)|safe}}
{% else %}
{{field(class="form-control", **kwargs)|safe}}
{% endif %}
{% elif form_type == "horizontal" %}
{{field.label(class="control-label " + (
" col-%s-%s" % horizontal_columns[0:2]
))|safe}}
<div class=" col-{{horizontal_columns[0]}}-{{horizontal_columns[2]}}">
{% if field.type == 'FileField' %}
{{field(**kwargs)|safe}}
{% else %}
{{field(class="form-control", **kwargs)|safe}}
{% endif %}
</div>
{%- if field.errors %}
{%- for error in field.errors %}
{% call _hz_form_wrap(horizontal_columns, form_type, required=required) %}
<p class="help-block">{{error}}</p>
{% endcall %}
{%- endfor %}
{%- elif field.description -%}
{% call _hz_form_wrap(horizontal_columns, form_type, required=required) %}
<p class="help-block">{{field.description|safe}}</p>
{% endcall %}
{%- endif %}
{%- else -%}
{{field.label(class="control-label")|safe}}
{% if field.type == 'FileField' %}
{{field(**kwargs)|safe}}
{% else %}
{{field(class="form-control", **kwargs)|safe}}
{% endif %}
{%- if field.errors %}
{%- for error in field.errors %}
<p class="help-block">{{error}}</p>
{%- endfor %}
{%- elif field.description -%}
<p class="help-block">{{field.description|safe}}</p>
{%- endif %}
{%- endif %}
</div>
{% endif %}
{% endmacro %}
{# valid form types are "basic", "inline" and "horizontal" #}
{% macro quick_form(form,
action="",
method="post",
extra_classes=None,
role="form",
form_type="basic",
horizontal_columns=('lg', 2, 10),
enctype=None,
button_map={},
id="",
novalidate=False) %}
{#-
action="" is what we want, from http://www.ietf.org/rfc/rfc2396.txt:
4.2. Same-document References
A URI reference that does not contain a URI is a reference to the
current document. In other words, an empty URI reference within a
document is interpreted as a reference to the start of that document,
and a reference containing only a fragment identifier is a reference
to the identified fragment of that document. Traversal of such a
reference should not result in an additional retrieval action.
However, if the URI reference occurs in a context that is always
intended to result in a new request, as in the case of HTML's FORM
element, then an empty URI reference represents the base URI of the
current document and should be replaced by that URI when transformed
into a request.
-#}
{#- if any file fields are inside the form and enctype is automatic, adjust
if file fields are found. could really use the equalto test of jinja2
here, but latter is not available until 2.8
warning: the code below is guaranteed to make you cry =(
#}
{%- set _enctype = [] %}
{%- if enctype is none -%}
{%- for field in form %}
{%- if field.type == 'FileField' %}
{#- for loops come with a fairly watertight scope, so this list-hack is
used to be able to set values outside of it #}
{%- set _ = _enctype.append('multipart/form-data') -%}
{%- endif %}
{%- endfor %}
{%- else %}
{% set _ = _enctype.append(enctype) %}
{%- endif %}
<form
{%- if action != None %} action="{{action}}"{% endif -%}
{%- if id %} id="{{id}}"{% endif -%}
{%- if method %} method="{{method}}"{% endif %}
class="form
{%- if extra_classes %} {{extra_classes}}{% endif -%}
{%- if form_type == "horizontal" %} form-horizontal
{%- elif form_type == "inline" %} form-inline
{%- endif -%}
"
{%- if _enctype[0] %} enctype="{{_enctype[0]}}"{% endif -%}
{%- if role %} role="{{role}}"{% endif -%}
{%- if novalidate %} novalidate{% endif -%}
>
{{ form.hidden_tag() }}
{{ form_errors(form, hiddens='only') }}
{%- for field in form %}
{% if not bootstrap_is_hidden_field(field) -%}
{{ form_field(field,
form_type=form_type,
horizontal_columns=horizontal_columns,
button_map=button_map) }}
{%- endif %}
{%- endfor %}
</form>
{%- endmacro %}

View File

@ -27,7 +27,6 @@ execnet==2.0.2
flake8==6.1.0
Flask==2.3.3
flask-babel==4.0.0
Flask-Bootstrap==3.3.7.1
Flask-Caching==2.0.2
Flask-HTTPAuth==4.8.0
Flask-JSON==0.4.0