syrusakbary / Flask-SuperAdmin

The best admin interface framework for Flask. With scaffolding for MongoEngine, Django and SQLAlchemy.
Other
643 stars 134 forks source link

Optionnal endpoint namespace support #120

Open noirbizarre opened 10 years ago

noirbizarre commented 10 years ago

Hi!

Using Flask-SuperAdmin, I've been having a lot of url name collision with automatic endpoint creation for ModelAdmin. To avoid collision, I wanted to prefix all URLs names with admin. and keep the index view at root.

This PR is doing that. It does not modify the default behavior but allow to easily prefix all admin views endpoints with a common prefix so I can write this:

admin = Admin(app, namespace='admin')
admin.add_view(MyView(endpoint='testadmin'))
admin.add_view(MyView())
admin.register(User)
url_for('admin.index')  # The IndexView is in the namespace root
url_for('admin.testadmin.index')
url_for('admin.myview.index')
url_for('admin.user.list')

This way I can keep the user.list url name for the non-admin view without manually specifying an endpoint for each view.

I'm ready to discuss this choice and the other alternatives you can offer.

(I also renamed the setup() into setup_admin() in test_model.py because it was call twice).