Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flask_admin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ def __init__(
# Register with application
if app is not None:
self._init_extension()
# Make theme available via current_app
app.config["theme"] = self.theme

def _validate_admin_host_and_subdomain(self):
if self.subdomain is not None and self.host is not None:
Expand Down
1 change: 1 addition & 0 deletions flask_admin/form/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __call__(self, field, **kwargs):
"_gettext": gettext,
"_ngettext": ngettext,
"h": h,
"theme": current_app.config["theme"],
}
)

Expand Down
12 changes: 6 additions & 6 deletions flask_admin/templates/bootstrap4/admin/lib.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@
{% set direct_error = h.is_field_error(field.errors) %}
{% set prepend = kwargs.pop('prepend', None) %}
{% set append = kwargs.pop('append', None) %}
<div class="form-group {{ kwargs.get('column_class', '') }}">
<label for="{{ field.id }}" class="control-label {% if field.widget.input_type == 'checkbox' %}d-block mb-0{% endif %}">{{ field.label.text }}
<div class="form-group {% if theme.horizontal %}row {% endif %}{{ kwargs.get('column_class', '') }}">
<label for="{{ field.id }}" class="col-form-label {% if theme.horizontal %}col-sm-2 {% endif %}{% if field.widget.input_type == 'checkbox' %}d-block mb-0{% endif %}">{{ field.label.text }}
{% if h.is_required_form_field(field) %}
<strong class="text-danger"">&#42;</strong>
<strong class="text-danger">&#42;</strong>
{%- else -%}
&nbsp;
{%- endif %}
</label>
{% if prepend or append %}
<div class="input-group">
{% if prepend or append or theme.horizontal %}
<div class="{% if prepend or append %}input-group {% endif %}{% if theme.horizontal %}col-sm-10{% endif %}">
{%- if prepend -%}
<div class="input-group-prepend">
{{ prepend }}
Expand Down Expand Up @@ -162,7 +162,7 @@
{{ field.description|safe }}
</small>
{% endif %}
{% if prepend or append %}
{% if prepend or append or theme.horizontal %}
</div>
{% endif %}
{% if caller %}
Expand Down
1 change: 1 addition & 0 deletions flask_admin/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BootstrapTheme(Theme):
base_template: str = "admin/base.html"
swatch: str = "default"
fluid: bool = False
horizontal: bool = False


Bootstrap4Theme = partial(BootstrapTheme, folder="bootstrap4")