diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-18 03:46:55 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-18 03:46:55 +0000 |
commit | 13f948273bc90301932415838d3eb4e663400ce6 (patch) | |
tree | 3a64a2c852f6aa2e5ec24f9d21bcb106a642cae7 | |
parent | 127669b818bec1f59414cbf3a40646eb2cc26a70 (diff) |
automatic import of python-flask-modals
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-flask-modals.spec | 502 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 504 insertions, 0 deletions
@@ -0,0 +1 @@ +/Flask-Modals-0.5.1.tar.gz diff --git a/python-flask-modals.spec b/python-flask-modals.spec new file mode 100644 index 0000000..47d0fd2 --- /dev/null +++ b/python-flask-modals.spec @@ -0,0 +1,502 @@ +%global _empty_manifest_terminate_build 0 +Name: python-Flask-Modals +Version: 0.5.1 +Release: 1 +Summary: Use forms in Bootstrap modals with Flask. +License: MIT License +URL: https://github.com/deb17/flask-modals +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/29/74/6d930d8bc8b22e896114f40834a2163685e5f68b7751bf4861ccd1263008/Flask-Modals-0.5.1.tar.gz +BuildArch: noarch + +Requires: python3-Flask + +%description +## Modals for Flask + +Use forms in Bootstrap modals with Flask. + +### Description + +Plain forms can be boring. Using them in modals is possible, but requires +JavaScript. Normal form submission in modals is problematic. + +This Flask extension eases the process of using forms in Bootstrap modals. +Bootstrap versions 4 and 5 are supported. No JavaScript coding is required on +your part. You can code in pure Python - flashing messages and rendering +templates. + +### Installation + +```Shell +pip install Flask-Modals +``` + +### Setup + +1. Import the `Modal` class and instantiate it in your `app.py` file. + + ```Python + from flask_modals import Modal + + app = Flask(__name__) + modal = Modal(app) + ``` + You will also need a secret key in the app config (not shown). + <br> +2. Alternatively if you are using the application factory pattern: + + ```Python + from flask_modals import Modal + + modal = Modal() + + def create_app(): + app = Flask(__name__) + modal.init_app(app) + ``` + <br> +3. Include the following in the head tag of your base template. + + ```html + {{ modals() }} + ``` + <br> +4. Include the following in the modal body. + + ```html + <div class="modal-body"> + {{ modal_messages() }} + <form method="post"> + ... + ``` + +### Basic usage + +You only need to import the function `render_template_modal` in your `routes.py` +file. Use it instead of `render_template` in the route handler for the page with +the modal form. It takes an extra argument - `modal` (the modal `id` with a default +of `modal-form`). +<br> +The extension works by submitting the modal form twice - first via +ajax and then, if all validations pass, normally. When submiited via ajax, it +passes a field '_ajax' with the form, which can be used as shown below. + +Example route handler: + +```Python +from flask_modals import render_template_modal + +@app.route('/', methods=['GET', 'POST']) +def index(): + + ajax = '_ajax' in request.form # Add this line + form = LoginForm() + if form.validate_on_submit(): + if form.username.data != 'test' or form.password.data != 'pass': + flash('Invalid username or password', 'danger') + return redirect(url_for('index')) + + if ajax: # Add these + return '' # two lines + login_user(user, remember=form.remember_me.data) + + flash('You have logged in!', 'success') + return redirect(url_for('home')) + + # Add this line + return render_template_modal('index.html', form=form) +``` + +### Other usage + +If you want to render a template and not redirect: + +```Python +@app.route('/', methods=['GET', 'POST']) +def index(): + + ajax = '_ajax' in request.form + form = LoginForm() + if form.validate_on_submit(): + if form.username.data != 'test' or form.password.data != 'pass': + flash('Invalid username or password', 'danger') + return render_template_modal('index.html', form=form) + + if ajax: + return '' + login_user(user, remember=form.remember_me.data) + + flash('You have logged in!', 'success') + return render_template_modal('index.html', form=form) + + return render_template_modal('index.html', form=form) +``` +If the above looks verbose, you can use the `response` decorator and +return a context dictionary, like so: + +```Python +from flask_modals import response + +@app.route('/', methods=['GET', 'POST']) +@response('index.html') +def index(): + ... + ... + return {'form': form} +``` +<br> + +### Note + +1. See the examples folder in the repo for more details. + +2. The extension loads the NProgress js library to display a progress bar during +form submission. + + + + +%package -n python3-Flask-Modals +Summary: Use forms in Bootstrap modals with Flask. +Provides: python-Flask-Modals +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-Flask-Modals +## Modals for Flask + +Use forms in Bootstrap modals with Flask. + +### Description + +Plain forms can be boring. Using them in modals is possible, but requires +JavaScript. Normal form submission in modals is problematic. + +This Flask extension eases the process of using forms in Bootstrap modals. +Bootstrap versions 4 and 5 are supported. No JavaScript coding is required on +your part. You can code in pure Python - flashing messages and rendering +templates. + +### Installation + +```Shell +pip install Flask-Modals +``` + +### Setup + +1. Import the `Modal` class and instantiate it in your `app.py` file. + + ```Python + from flask_modals import Modal + + app = Flask(__name__) + modal = Modal(app) + ``` + You will also need a secret key in the app config (not shown). + <br> +2. Alternatively if you are using the application factory pattern: + + ```Python + from flask_modals import Modal + + modal = Modal() + + def create_app(): + app = Flask(__name__) + modal.init_app(app) + ``` + <br> +3. Include the following in the head tag of your base template. + + ```html + {{ modals() }} + ``` + <br> +4. Include the following in the modal body. + + ```html + <div class="modal-body"> + {{ modal_messages() }} + <form method="post"> + ... + ``` + +### Basic usage + +You only need to import the function `render_template_modal` in your `routes.py` +file. Use it instead of `render_template` in the route handler for the page with +the modal form. It takes an extra argument - `modal` (the modal `id` with a default +of `modal-form`). +<br> +The extension works by submitting the modal form twice - first via +ajax and then, if all validations pass, normally. When submiited via ajax, it +passes a field '_ajax' with the form, which can be used as shown below. + +Example route handler: + +```Python +from flask_modals import render_template_modal + +@app.route('/', methods=['GET', 'POST']) +def index(): + + ajax = '_ajax' in request.form # Add this line + form = LoginForm() + if form.validate_on_submit(): + if form.username.data != 'test' or form.password.data != 'pass': + flash('Invalid username or password', 'danger') + return redirect(url_for('index')) + + if ajax: # Add these + return '' # two lines + login_user(user, remember=form.remember_me.data) + + flash('You have logged in!', 'success') + return redirect(url_for('home')) + + # Add this line + return render_template_modal('index.html', form=form) +``` + +### Other usage + +If you want to render a template and not redirect: + +```Python +@app.route('/', methods=['GET', 'POST']) +def index(): + + ajax = '_ajax' in request.form + form = LoginForm() + if form.validate_on_submit(): + if form.username.data != 'test' or form.password.data != 'pass': + flash('Invalid username or password', 'danger') + return render_template_modal('index.html', form=form) + + if ajax: + return '' + login_user(user, remember=form.remember_me.data) + + flash('You have logged in!', 'success') + return render_template_modal('index.html', form=form) + + return render_template_modal('index.html', form=form) +``` +If the above looks verbose, you can use the `response` decorator and +return a context dictionary, like so: + +```Python +from flask_modals import response + +@app.route('/', methods=['GET', 'POST']) +@response('index.html') +def index(): + ... + ... + return {'form': form} +``` +<br> + +### Note + +1. See the examples folder in the repo for more details. + +2. The extension loads the NProgress js library to display a progress bar during +form submission. + + + + +%package help +Summary: Development documents and examples for Flask-Modals +Provides: python3-Flask-Modals-doc +%description help +## Modals for Flask + +Use forms in Bootstrap modals with Flask. + +### Description + +Plain forms can be boring. Using them in modals is possible, but requires +JavaScript. Normal form submission in modals is problematic. + +This Flask extension eases the process of using forms in Bootstrap modals. +Bootstrap versions 4 and 5 are supported. No JavaScript coding is required on +your part. You can code in pure Python - flashing messages and rendering +templates. + +### Installation + +```Shell +pip install Flask-Modals +``` + +### Setup + +1. Import the `Modal` class and instantiate it in your `app.py` file. + + ```Python + from flask_modals import Modal + + app = Flask(__name__) + modal = Modal(app) + ``` + You will also need a secret key in the app config (not shown). + <br> +2. Alternatively if you are using the application factory pattern: + + ```Python + from flask_modals import Modal + + modal = Modal() + + def create_app(): + app = Flask(__name__) + modal.init_app(app) + ``` + <br> +3. Include the following in the head tag of your base template. + + ```html + {{ modals() }} + ``` + <br> +4. Include the following in the modal body. + + ```html + <div class="modal-body"> + {{ modal_messages() }} + <form method="post"> + ... + ``` + +### Basic usage + +You only need to import the function `render_template_modal` in your `routes.py` +file. Use it instead of `render_template` in the route handler for the page with +the modal form. It takes an extra argument - `modal` (the modal `id` with a default +of `modal-form`). +<br> +The extension works by submitting the modal form twice - first via +ajax and then, if all validations pass, normally. When submiited via ajax, it +passes a field '_ajax' with the form, which can be used as shown below. + +Example route handler: + +```Python +from flask_modals import render_template_modal + +@app.route('/', methods=['GET', 'POST']) +def index(): + + ajax = '_ajax' in request.form # Add this line + form = LoginForm() + if form.validate_on_submit(): + if form.username.data != 'test' or form.password.data != 'pass': + flash('Invalid username or password', 'danger') + return redirect(url_for('index')) + + if ajax: # Add these + return '' # two lines + login_user(user, remember=form.remember_me.data) + + flash('You have logged in!', 'success') + return redirect(url_for('home')) + + # Add this line + return render_template_modal('index.html', form=form) +``` + +### Other usage + +If you want to render a template and not redirect: + +```Python +@app.route('/', methods=['GET', 'POST']) +def index(): + + ajax = '_ajax' in request.form + form = LoginForm() + if form.validate_on_submit(): + if form.username.data != 'test' or form.password.data != 'pass': + flash('Invalid username or password', 'danger') + return render_template_modal('index.html', form=form) + + if ajax: + return '' + login_user(user, remember=form.remember_me.data) + + flash('You have logged in!', 'success') + return render_template_modal('index.html', form=form) + + return render_template_modal('index.html', form=form) +``` +If the above looks verbose, you can use the `response` decorator and +return a context dictionary, like so: + +```Python +from flask_modals import response + +@app.route('/', methods=['GET', 'POST']) +@response('index.html') +def index(): + ... + ... + return {'form': form} +``` +<br> + +### Note + +1. See the examples folder in the repo for more details. + +2. The extension loads the NProgress js library to display a progress bar during +form submission. + + + + +%prep +%autosetup -n Flask-Modals-0.5.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-Flask-Modals -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Thu May 18 2023 Python_Bot <Python_Bot@openeuler.org> - 0.5.1-1 +- Package Spec generated @@ -0,0 +1 @@ +4c066c59dcbc30b7471267c2cddb5d50 Flask-Modals-0.5.1.tar.gz |