Skip to content
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

Can't use multiple Admin instances with different Bootstrap themes (FLASK_ADMIN_SWATCH) #2423

Closed
princerb opened this issue Apr 3, 2024 · 14 comments Β· Fixed by #2462
Closed

Comments

@princerb
Copy link
Contributor

princerb commented Apr 3, 2024

❓ How can we use different Bootstrap themes through multiple Admin instances?

πŸ‘¨β€πŸ’» This is how I tried to do it:

...
app.config['FLASK_ADMIN_SWATCH'] = 'cerulean'
admin1 = Admin(app, endpoint='admin1')
app.config['FLASK_ADMIN_SWATCH'] = 'cosmo'
admin2 = Admin(app, endpoint='admin2')
...

❌ But this does NOT work, I wrote this to clarify what I want to do with my issue.
Thanks!

@princerb
Copy link
Contributor Author

princerb commented Apr 3, 2024

If I solve, will PRs be viewed/merged soon?

@hasansezertasan
Copy link
Member

If I solve, will PRs be viewed/merged soon?

The repo is inactive for almost over six months, so O don't think it'll be merged quickly.

@samuelhwilliams
Copy link
Contributor

This feels like a useful feature. I'm not sure yet how easy or hard it would be to support this, but if you've got ideas I'd be happy to hear them and would be willing to help review any PR you do put up. Would be good to understand your proposed approach first.

@princerb
Copy link
Contributor Author

princerb commented Jul 6, 2024

I've got the idea and the way to implement it in a safe way, I am just looking for time to work on it. But I am sure I will contribute and create my PR soon)

@hasansezertasan
Copy link
Member

hasansezertasan commented Jul 19, 2024

This problem may also occur when setting up FLASK_ADMIN_FLUID_LAYOUT since it's directly taken from the flask config.

I believe the best fix for this problem could be like this:

admin1 = Admin(
    app,
    endpoint='admin1',
    swatch='cerulean', # Instead of `FLASK_ADMIN_SWATCH`
    fluid=True, # Instead of `FLASK_ADMIN_FLUID_LAYOUT`
)
admin2 = Admin(
    app,
    endpoint='admin2',
    swatch='cosmo', # Instead of `FLASK_ADMIN_SWATCH`
    fluid=False, # Instead of `FLASK_ADMIN_FLUID_LAYOUT`
)

Pas the settings to the Admin instance. WDYT about this @princerb?

@samuelhwilliams
Copy link
Contributor

samuelhwilliams commented Jul 19, 2024

I had a look at this and it might be something we could get into the v2 release. Here's a possible approach: #2462

As I've coded it, it's a breaking change. We could make this a bit softer and wrap the breaking change if we really wanted to - although since we're planning a v2.0.0 release, now's a fair time to get it in.


I think it's ideal to wrap all of the configuration around what template 'mode' to use, and its configuration (swatch, fluid, etc) in a single config object and pass this in.

We then expose it to all of the templates. This should make it easier for people to hook in their own template modes.

@princerb
Copy link
Contributor Author

I actually already made the reslover changes for this, just needed to write the end of the example ) [the button that switches even the current theme]

@princerb
Copy link
Contributor Author

@samuelhwilliams as I see you created a complete new configuration class for the Bootstrap options, while I used a new param to Admin which is bootswatch_theme. I think your approach also is awesome πŸ‘

@samuelhwilliams
Copy link
Contributor

I'd love to see what you've done so far or what you're planning - if you've covered some use cases that I haven't, we can take the best of both :)

@princerb
Copy link
Contributor Author

#2463

@princerb
Copy link
Contributor Author

But mine is quite simple one. Your approach gives the project a seperate and full control over the theming. But there is a catch, you added also folder param, are we also going to plan to use different Bootstrap versions along along the different Admin instances?

@samuelhwilliams
Copy link
Contributor

samuelhwilliams commented Jul 19, 2024

But there is a catch, you added also folder param, are we also going to plan to use different Bootstrap versions along along the different Admin instances?

I don't think we need to. We might not even have to. But with my approach it becomes trivial to make it possible - and I think the more interesting idea is where someone has multiple admin instances for different groups of users. These could be user-provided template configs that point at their own private set of templates configured for each user group specifically. It feels fairly flexible without really costing us much. Each admin instance can we styled exactly the way it wants/needs to be.

@princerb
Copy link
Contributor Author

I thought about this when I am making changes, but there were going to be more core changed needed to be done. I haven't really structured this feature in my head, but I think it requires the changes through the Boostrap template folders and some alternations when creating and registering the Blueprint from the base.

@princerb
Copy link
Contributor Author

princerb commented Jul 19, 2024

But there is a catch, you added also folder param, are we also going to plan to use different Bootstrap versions along along the different Admin instances?

I don't think we need to. We might not even have to. But with my approach it becomes trivial to make it possible - and I think the more interesting idea is where someone has multiple admin instances for different groups of users. These could be user-provided template configs that point at their own private set of templates configured for each user group specifically. It feels fairly flexible without really costing us much. Each admin instance can we styled exactly the way it wants/needs to be.

My guess is that when the users use multiple Admin instances, they might also want to use different Bootstrap versions if need. But your reply sounds fair πŸ‘

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

Successfully merging a pull request may close this issue.

3 participants