Skip to content

Commit

Permalink
Merge pull request #1 from helloflask/master
Browse files Browse the repository at this point in the history
keeup
  • Loading branch information
serensoner authored Oct 2, 2023
2 parents df8f61b + 85dd170 commit c96fded
Show file tree
Hide file tree
Showing 131 changed files with 46,758 additions and 15,780 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ['3.7', '3.8', '3.9', '3.10']
python: ['3.8', '3.9', '3.10', '3.11']
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
16 changes: 14 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
Changelog
=========

2.3.1
-----

Release date: -

- Upgrade to Bootstrap 5.3.2, Bootswatch 5.3.1, and Bootstrap Icons 1.11.1.


2.3.0
-----

Release date: -
Release date: 2023/7/24

- Drop Python 3.7 support, and test against Python 3.11.
- Render enums in tables by their labels.
- Support creating action URLs for dict data (`#268 <https://github.com/helloflask/bootstrap-flask/issues/268>`__).
- Upgrade to Bootstrap 5.3.0, Bootstrap Icons 1.10.5, and Popper 2.11.8.


2.2.0
Expand Down Expand Up @@ -46,7 +58,7 @@ Release date: 2022/2/27

Release date: 2022/1/27

- Remove extra quotaion mark in ``render_nav_item``
- Remove extra quotation mark in ``render_nav_item``
(`#201 <https://github.com/helloflask/bootstrap-flask/pull/201>`__).
- Fix signature of ``Bootstrap.__init__()`` incompatible with older version
(`#198 <https://github.com/helloflask/bootstrap-flask/pull/198>`__).
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Current version on PyPI](https://img.shields.io/pypi/v/bootstrap-flask)](https://pypi.org/project/bootstrap-flask/)
[![Build status](https://github.com/helloflask/bootstrap-flask/workflows/build/badge.svg)](https://github.com/helloflask/bootstrap-flask/actions)
[![Coverage Status](https://coveralls.io/repos/github/helloflask/bootstrap-flask/badge.svg?branch=master)](https://coveralls.io/github/helloflask/bootstrap-flask?branch=master)
[![Open Collective](https://img.shields.io/opencollective/all/bootstrap-flask)](https://opencollective.com/bootstrap-flask)

Bootstrap-Flask is a collection of Jinja macros for Bootstrap 4 & 5 and Flask. It helps you to
render Flask-related data and objects to Bootstrap markup HTML more easily:
Expand Down Expand Up @@ -79,7 +80,7 @@ docs for more details.

Live demos of the latest release are:
- [Examples with Bootstrap 4](http://173.212.198.217/)
- [Examples with Bootstrap 5](http://173.212.227.186/)
- [Examples with Bootstrap 5](http://109.205.179.12/)


## Donate
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
comment: false

27 changes: 16 additions & 11 deletions docs/macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ API
:param horizontal_columns: When using the horizontal layout, layout forms
like this. Must be a 3-tuple of ``(column-type,
left-column-size, right-column-size)``.
:param button_style: Set button style for ``SubmitField``. Accept Bootstrap button style name (i.e. primary,
:param button_style: Set button style for ``SubmitField``. Accept Bootstrap button style name (i.e. primary,
secondary, outline-success, etc.), default to ``primary`` (e.g. ``btn-primary``). This will
overwrite config ``BOOTSTRAP_BTN_STYLE``.
:param button_size: Set button size for ``SubmitField``. Accept Bootstrap button size name: sm, md, lg, block,
Expand Down Expand Up @@ -181,7 +181,7 @@ API
:param enctype: ``<form>`` enctype attribute. If ``None``, will
automatically be set to ``multipart/form-data`` if a
:class:`~wtforms.fields.FileField` or :class:`~wtforms.fields.MultipleFileField` is present in the form.
:param button_style: Set button style for ``SubmitField``. Accept Bootstrap button style name (i.e. primary,
:param button_style: Set button style for ``SubmitField``. Accept Bootstrap button style name (i.e. primary,
secondary, outline-success, etc.), default to ``primary`` (e.g. ``btn-primary``). This will
overwrite config ``BOOTSTRAP_BTN_STYLE``.
:param button_size: Set button size for ``SubmitField``. Accept Bootstrap button size name: sm, md, lg, block,
Expand Down Expand Up @@ -274,7 +274,7 @@ API
if nothing more specific is said for the div column of the rendered field.
:param col_map: A dictionary, mapping field.name to a class definition that should be applied to
the div column that contains the field. For example: ``col_map={'username': 'col-md-2'})``.
:param button_style: Set button style for ``SubmitField``. Accept Bootstrap button style name (i.e. primary,
:param button_style: Set button style for ``SubmitField``. Accept Bootstrap button style name (i.e. primary,
secondary, outline-success, etc.), default to ``primary`` (e.g. ``btn-primary``). This will
overwrite config ``BOOTSTRAP_BTN_STYLE``.
:param button_size: Set button size for ``SubmitField``. Accept Bootstrap button size name: sm, md, lg, block,
Expand Down Expand Up @@ -447,11 +447,12 @@ When you call ``flash('message', 'category')``, there are 8 category options ava

primary, secondary, success, danger, warning, info, light, dark.

If you want to use HTML in your message body, just wrapper your message string with ``flask.Markup`` to tell Jinja it's safe:
If you want to use HTML in your message body, just wrapper your message string with ``markupsafe.Markup`` to tell Jinja it's safe:

.. code-block:: python
from flask import flash, Markup
from flask import flash
from markupsafe import Markup
@app.route('/test')
def test():
Expand Down Expand Up @@ -496,7 +497,7 @@ API
urlize_columns=None,\
show_actions=False,\
actions_title='Actions',\
model=None,\
model=None,\
custom_actions=None,\
view_url=None,\
edit_url=None,\
Expand All @@ -519,7 +520,9 @@ API
using ``|urlize``. Is overruled by ``safe_columns`` parameter. Default is ``None``.
WARNING: Only use this for sanitized user data to prevent XSS attacks.
:param show_actions: Whether to display the actions column. Default is ``False``.
:param model: The model used to build custom_action, view, edit, delete URLs.
:param model: An optional model used to build custom_action, view, edit,
delete URLs. Set this if you need to pull the URL arguments from
a different SQLAlchemy class indexed with the same primary key.
:param actions_title: Title for the actions column header. Default is ``'Actions'``.
:param custom_actions: A list of tuples for creating custom action buttons, where each tuple contains
('Title Text displayed on hover', 'bootstrap icon name', 'URL tuple or fixed URL string')
Expand All @@ -541,8 +544,10 @@ an URL tuple in the form of ``('endpoint', [('url_parameter_name', ':db_model_fi
it's a variable, otherwise it will becomes a fixed value). ``db_model_fieldname`` may also contain dots to access
relationships and their fields (e.g. ``user.name``).

Remember to set the ``model`` when setting this URLs, so that Bootstrap-Flask will know where to get the actual value
when building the URL.
By default, Bootstrap-Flask will take the fields from the row data provided.
Alternatively, you may set the ``model``, in which case a record from that
model, indexed with the same primary key, will be used to get the actual
value when building the URL.

For example, for the view below:

Expand All @@ -563,13 +568,13 @@ Here is the full example:
@app.route('/test')
def test():
data = Message.query.all()
return render_template('test.html', data=data, Message=Message)
return render_template('test.html', data=data)
.. code-block:: jinja
{% from 'bootstrap4/table.html' import render_table %}
{{ render_table(data, model=Message, view_url=('view_message', [('message_id', ':id')])) }}
{{ render_table(data, view_url=('view_message', [('message_id', ':id')])) }}
The following arguments are expect to accpet an URL tuple:

Expand Down
2 changes: 1 addition & 1 deletion examples/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Now go to http://localhost:5000.
Live demos of the latest release are:

- `Examples with Bootstrap 4 <http://173.212.198.217/>`_
- `Examples with Bootstrap 5 <http://173.212.227.186/>`_
- `Examples with Bootstrap 5 <http://109.205.179.12/>`_

Overview of icons
-----------------
Expand Down
17 changes: 12 additions & 5 deletions examples/bootstrap4/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request, flash, Markup, redirect, url_for
from enum import Enum
from flask import Flask, render_template, request, flash, redirect, url_for
from markupsafe import Markup
from flask_wtf import FlaskForm, CSRFProtect
from wtforms.validators import DataRequired, Length, Regexp
from wtforms.fields import *
Expand Down Expand Up @@ -121,17 +123,21 @@ class BootswatchForm(FlaskForm):
submit = SubmitField()


class MyCategory(Enum):
CAT1 = 'Category 1'
CAT2 = 'Category 2'


class Message(db.Model):
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.Text, nullable=False)
author = db.Column(db.String(100), nullable=False)
category = db.Column(db.String(100), nullable=False)
category = db.Column(db.Enum(MyCategory), default=MyCategory.CAT1, nullable=False)
draft = db.Column(db.Boolean, default=False, nullable=False)
create_time = db.Column(db.Integer, nullable=False, unique=True)


@app.before_first_request
def before_first_request_func():
with app.app_context():
db.drop_all()
db.create_all()
for i in range(20):
Expand All @@ -151,9 +157,10 @@ def before_first_request_func():
m = Message(
text=f'Message {i+1} {url}',
author=f'Author {i+1}',
category=f'Category {i+1}',
create_time=4321*(i+1)
)
if i % 2:
m.category = MyCategory.CAT2
if i % 4:
m.draft = True
db.session.add(m)
Expand Down
Loading

0 comments on commit c96fded

Please sign in to comment.