1
0
forked from ScoDoc/ScoDoc

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 Flask
from flask import abort, flash, has_request_context from flask import abort, flash, has_request_context
from flask import render_template from flask import render_template
# from flask.json import JSONEncoder
from flask.logging import default_handler from flask.logging import default_handler
from flask_bootstrap import Bootstrap
from flask_caching import Cache from flask_caching import Cache
from flask_json import FlaskJSON, json_response from flask_json import FlaskJSON, json_response
from flask_login import LoginManager, current_user from flask_login import LoginManager, current_user
@ -34,6 +30,7 @@ from flask_sqlalchemy import SQLAlchemy
from jinja2 import select_autoescape from jinja2 import select_autoescape
import sqlalchemy as sa import sqlalchemy as sa
import werkzeug.debug import werkzeug.debug
from wtforms.fields import HiddenField
from flask_cas import CAS from flask_cas import CAS
@ -59,8 +56,6 @@ login.login_view = "auth.login"
login.login_message = "Identifiez-vous pour accéder à cette page." login.login_message = "Identifiez-vous pour accéder à cette page."
mail = Mail() mail = Mail()
bootstrap = Bootstrap()
# moment = Moment()
CACHE_TYPE = os.environ.get("CACHE_TYPE") CACHE_TYPE = os.environ.get("CACHE_TYPE")
cache = Cache( cache = Cache(
@ -304,7 +299,6 @@ def create_app(config_class=DevConfig):
login.init_app(app) login.init_app(app)
mail.init_app(app) mail.init_app(app)
app.extensions["mail"].debug = 0 # disable copy of mails to stderr app.extensions["mail"].debug = 0 # disable copy of mails to stderr
bootstrap.init_app(app)
cache.init_app(app) cache.init_app(app)
sco_cache.CACHE = cache sco_cache.CACHE = cache
if CACHE_TYPE: # non default 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(503, postgresql_server_error)
app.register_error_handler(APIInvalidParams, handle_invalid_usage) 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 from app.auth import bp as auth_bp
app.register_blueprint(auth_bp, url_prefix="/auth") app.register_blueprint(auth_bp, url_prefix="/auth")

View File

@ -212,7 +212,7 @@ def sco_header(
<script> <script>
window.onload=function(){{enableTooltips("gtrcontent")}}; window.onload=function(){{enableTooltips("gtrcontent")}};
var SCO_URL="{scu.ScoURL()}"; const SCO_URL="{scu.ScoURL()}";
</script>""" </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 -*- #} {# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %} {% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block app_content %} {% block app_content %}

View File

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

View File

@ -1,5 +1,5 @@
{% extends "base.j2" %} {% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block app_content %} {% block app_content %}
<h1>Chargement des configurations CAS des utilisateurs</h1> <h1>Chargement des configurations CAS des utilisateurs</h1>

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #} {# -*- mode: jinja-html -*- #}
{% extends "base.j2" %} {% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block app_content %} {% block app_content %}
<h1>Demande d'un nouveau mot de passe</h1> <h1>Demande d'un nouveau mot de passe</h1>

View File

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

View File

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

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 -*- #} {# -*- mode: jinja-html -*- #}
{% extends 'bootstrap/base.html' %} {% extends 'babase.j2' %}
{% block styles %} {% block styles %}
{{super()}} {{super()}}
@ -92,6 +92,6 @@
<script src="{{scu.STATIC_DIR}}/libjs/qtip/jquery.qtip-3.0.3.min.js"></script> <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 src="{{scu.STATIC_DIR}}/js/scodoc.js"></script>
<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> </script>
{% endblock %} {% endblock %}

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #} {# -*- mode: jinja-html -*- #}
{% extends "sco_page.j2" %} {% extends "sco_page.j2" %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block app_content %} {% block app_content %}
<h2>Référentiels de compétences chargés</h2> <h2>Référentiels de compétences chargés</h2>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
{% extends 'base.j2' %} {% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block app_content %} {% block app_content %}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #} {# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %} {% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block title %}Une erreur est survenue !{% endblock %} {% block title %}Une erreur est survenue !{% endblock %}

View File

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

View File

@ -1,5 +1,5 @@
{% extends 'base.j2' %} {% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block app_content %} {% block app_content %}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
{# -*- mode: jinja-html -*- #} {# -*- mode: jinja-html -*- #}
{% extends 'bootstrap/base.html' %} {% extends 'babase.j2' %}
{% block styles %} {% block styles %}
{{super()}} {{super()}}
@ -52,7 +52,7 @@
<script> <script>
window.onload = function () { enableTooltips("gtrcontent") }; 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> </script>
{% endblock %} {% endblock %}

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #} {# -*- mode: jinja-html -*- #}
{% extends 'base.j2' %} {% extends 'base.j2' %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block app_content %} {% block app_content %}
<h2>ScoDoc 9 - suivi scolarité</h2> <h2>ScoDoc 9 - suivi scolarité</h2>

View File

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

View File

@ -1,6 +1,6 @@
{# -*- mode: jinja-html -*- #} {# -*- mode: jinja-html -*- #}
{% extends "base.j2" %} {% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block app_content %} {% block app_content %}
<h1>Créer un rôle</h1> <h1>Créer un rôle</h1>

View File

@ -1,7 +1,7 @@
{# -*- mode: jinja-html -*- #} {# -*- mode: jinja-html -*- #}
{# -*- Edition des rôles/permissions -*- #} {# -*- Edition des rôles/permissions -*- #}
{% extends "base.j2" %} {% extends "base.j2" %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'wtf.j2' as wtf %}
{% block styles %} {% block styles %}
{{super()}} {{super()}}

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 flake8==6.1.0
Flask==2.3.3 Flask==2.3.3
flask-babel==4.0.0 flask-babel==4.0.0
Flask-Bootstrap==3.3.7.1
Flask-Caching==2.0.2 Flask-Caching==2.0.2
Flask-HTTPAuth==4.8.0 Flask-HTTPAuth==4.8.0
Flask-JSON==0.4.0 Flask-JSON==0.4.0