Skip to content

feat: Initial Bootstrap 5 theme implementation - foundational UI port #2642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

filippolauria
Copy link

@filippolauria filippolauria commented Jul 24, 2025

This PR provides a Bootstrap 5 port of the existing Bootstrap 4 theme, adapting Flask-Admin's UI components to work with Bootstrap 5 while maintaining some sort of backward compatibility.

Changes Made

Template & Macro Adaptation

  • Ported all Bootstrap 4 templates and macros to Bootstrap 5 equivalents
  • Updated CSS classes and component structures to match BS5 specifications
  • Migrated all macros for Bootstrap 5 compatibility

JavaScript Modernization

  • Ported form.js to bind "widgets" (right now it's just Select2) to Bootstrap 5 components
    • EDIT: Select2 is fully supported and working in modal contexts too
  • Ported modal.js for modal dialog management
  • Ported filter.js and details_filter.js for enhanced filtering
  • Ported action.js for bulk actions and tooltip initialization

UI Component Porting

  • Adapted list, create, edit, and details views to Bootstrap 5
  • Ported inline field management components
  • Migrated row actions and bulk actions interfaces
  • Updated modal operations (create, edit, details) for BS5

Static Assets

  • Integrated Bootstrap 5 and Bootswatch theme files
  • Implemented toast notifications replacing old alert system
  • Added popover support with proper initialization

Current Status

This is a partial port with the following limitations:

  • Select2: Basic integration completed
  • Redis console: Adapted but not fully tested
  • File admin: Adaptation completed, requires thorough testing
  • Others third party components are old newer versions should be used in the future

Static File Verification

All new static files (Bootstrap, Bootswatch themes, Select2, etc.) can be verified against official distributions by comparing SHA hashes with CDN and official release versions.

Future Work

This port establishes the foundation for removing jQuery dependency by preparing integration points for modern JavaScript alternatives (i.e. Choices.js) to replace Select2 in future iterations.

Example Application

Includes comprehensive example demonstrating all ported features: modal operations, inline editing, filtering, search, export functionality, and multi-level navigation.

The example is an enhanced port of the original Bootstrap 4 example. Screenshots below showcase the key functionality:

List filtering and bulk actions
This screenshot shows list filtering capabilities and bulk actions applied to selected records (one record selected in this case):

Bootstrap 5 list view with filtering and bulk actions

Inline editing with modal creation
Demonstrates creating a new organization with inline user addition. The trash icon (top right) allows removing the added user for demonstration purposes:

image

Theme switching and Select2 integration
Shows the United Bootswatch theme and demonstrates Select2 functionality in modal creation:

Modal creation with Select2 using United theme

Link to relevant issues or previous PRs

Other contributors have attempted to achieve this result (#2350 #2163). This PR aims to initiate the definitive introduction of Bootstrap 5 support by providing a comprehensive foundation for the migration.

these are practically unchanged from the Bootstrap 4 templates
Removed custom CSS from admin.css in favor of Bootstrap 5 classes. Updated base.html to use the right static files and included popover and toast message handling.
…ration

Migrated macros to BS5 and created form.js to bind widgets to Bootstrap 5 components. Added select2 support (non-functional in modals). Planning to replace select2 with native JS solutions to remove jQuery dependency.
Added action.js to handle bulk actions and initialize tooltips for column descriptions. TODO: review implementation.
… scripts

Introduced modal.js for modal management and details_filter.js for details model filtering.
Example includes modal operations, inline models editing, filtering, search, export, Select2 integration, and multi-level navigation to demonstrate all BS5 components.
@ElLorans
Copy link
Contributor

can you run tox --e style?

@ElLorans ElLorans added the theme label Jul 25, 2025
…older (e.g., 'bootstrap4', 'bootstrap5').

This function is essential for UI components, like widgets, that need to adapt their rendering based on the configured theme.

The implementation is robust and supports multi-admin applications by inspecting the current request's endpoint (`request.endpoint`) and matching it against the endpoints of the views registered within each `Admin` instance.

If the helper is called from outside an admin-related view (e.g., a public homepage) or outside a request context, it falls back to using the theme of the first registered `Admin` instance.

TODO:
- A caching mechanism should be added to avoid re-scanning the admin views on every call, which currently involves a nested loop.
improved the development environment setup to support both `pip` and `uv`.
@filippolauria
Copy link
Author

Continued development on this PR.

I've styled the FileUploadInput and ImageUploadInput widgets to provide responsive, theme-aware defaults for Bootstrap 5, while preserving the ability for users to provide their own custom templates.

Here are some screenshots from the "Forms" example demonstrating the new default look:

FileUploadInput (Bootstrap 5)
image

ImageUploadInput (Bootstrap 5)
image

@ElLorans
Copy link
Contributor

Is this PR ready for review or do you plan to keep working on it? A 64k PR is somewhat too complex, I fear

@filippolauria
Copy link
Author

@ElLorans I may be mistaken because I did this very quickly, but the only files I created/modified are:

  • template files for Bootstrap 5
  • a few "core" Python files
  • a couple of examples
  • some static JavaScript and CSS files
    The rest are the latest versions of third-party components
    (you can verify this by comparing the checksums with the official versions).

The following line of code counts roughly how many lines of code were actually affected by this PR (TL;DR <5k)

$ wc -l $(git diff upstream/master --name-only | grep -E 'templates/bootstrap5|examples|\.py|static/admin/.*/bootstrap5')
    40 examples/bootstrap5/README.rst
     0 examples/bootstrap5/__init__.py
   326 examples/bootstrap5/app.py
     2 examples/bootstrap5/requirements.txt
   340 examples/forms-files-images/main.py
    12 examples/forms-files-images/pyproject.toml
   660 flask_admin/form/upload.py
   243 flask_admin/helpers.py
    16 flask_admin/static/admin/css/bootstrap5/admin.css
    57 flask_admin/static/admin/css/bootstrap5/rediscli.css
    19 flask_admin/static/admin/css/bootstrap5/submenu.css
   237 flask_admin/static/admin/js/bootstrap5/actions.js
   116 flask_admin/static/admin/js/bootstrap5/details_filter.js
   317 flask_admin/static/admin/js/bootstrap5/filters.js
   185 flask_admin/static/admin/js/bootstrap5/form.js
    82 flask_admin/static/admin/js/bootstrap5/modal.js
   149 flask_admin/static/admin/js/bootstrap5/rediscli.js
    51 flask_admin/templates/bootstrap5/admin/actions.html
   145 flask_admin/templates/bootstrap5/admin/base.html
    12 flask_admin/templates/bootstrap5/admin/file/form.html
   199 flask_admin/templates/bootstrap5/admin/file/list.html
    20 flask_admin/templates/bootstrap5/admin/file/modals/form.html
     3 flask_admin/templates/bootstrap5/admin/index.html
    79 flask_admin/templates/bootstrap5/admin/layout.html
   414 flask_admin/templates/bootstrap5/admin/lib.html
     1 flask_admin/templates/bootstrap5/admin/master.html
    44 flask_admin/templates/bootstrap5/admin/model/create.html
   100 flask_admin/templates/bootstrap5/admin/model/details.html
    81 flask_admin/templates/bootstrap5/admin/model/edit.html
    17 flask_admin/templates/bootstrap5/admin/model/inline_field_list.html
     4 flask_admin/templates/bootstrap5/admin/model/inline_form.html
    77 flask_admin/templates/bootstrap5/admin/model/inline_list_base.html
   193 flask_admin/templates/bootstrap5/admin/model/layout.html
   268 flask_admin/templates/bootstrap5/admin/model/list.html
    34 flask_admin/templates/bootstrap5/admin/model/modals/create.html
    45 flask_admin/templates/bootstrap5/admin/model/modals/details.html
    33 flask_admin/templates/bootstrap5/admin/model/modals/edit.html
    57 flask_admin/templates/bootstrap5/admin/model/row_actions.html
    28 flask_admin/templates/bootstrap5/admin/rediscli/console.html
    32 flask_admin/templates/bootstrap5/admin/rediscli/response.html
     3 flask_admin/templates/bootstrap5/admin/static.html
    55 flask_admin/theme.py
  4796 total

@ElLorans
Copy link
Contributor

ElLorans commented Aug 1, 2025

Thanks. About my first question, is the PR ready for review or do you need any final tweaks?

@filippolauria
Copy link
Author

You can review it. Just consider what I wrote above: I only managed to integrate Select2. I didn't integrate x-editable and datepicker. So this PR is somewhat of a starting point on which, hopefully, other contributors will also start contributing.

@ElLorans
Copy link
Contributor

ElLorans commented Aug 1, 2025

Unfortunately and understandibly, everybody prefers his own frontend theme PR. Maybe we can coordinate here #2647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants