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

Blueprint name collisions (#1474 issue reopening ) #1760

Open
K-7 opened this issue Nov 25, 2018 · 5 comments
Open

Blueprint name collisions (#1474 issue reopening ) #1760

K-7 opened this issue Nov 25, 2018 · 5 comments

Comments

@K-7
Copy link

K-7 commented Nov 25, 2018

The issue in the following link still persists #1474

Even after changing the endpoint, still the issue persists.

Package Verison
Flask-Admin==1.5.2
Flask == 1.0.2

Initialisation code
admin_control = Admin(name='Saiva', endpoint='bp_admin')
admin_control.init_app(app, index_view=admin.AdminView())

Here Iam overriding the Admin view

Kindly help me out

@apex-omontgomery
Copy link

apex-omontgomery commented Nov 25, 2018

Not sure if it's the right way, but when I use endpoint I specify a name and endpoint value.

# in app/auth/__init.py
from app import db
from app.auth.admin_views import SomeView

def init_admin(f_admin):
    f_admin.add_view(SomeView(db.session, endpoint='create some view', name='Create SomeView'))

Then in my create_app

# in app/__init__.py
def create_app(.....):
    # all the other blueprint registration. 

    ### Admin setup
    from app.auth.routes import MyAdminIndexView
    f_admin = Admin(
        app,                                   # flask app name
        name='Some Dashboard', 
        index_view=MyAdminIndexView(url='/'),
        base_template='my_master.html',
        template_mode='bootstrap3')
        
        
  
    from app.auth import init_admin           # import my views    
    init_admin(f_admin)                        # this call must be after all blueprints
    ###  END ADMIN IMPORT

    return app

Your issue looks like you're specifying the endpoint and name when you instantiate Admin and you should be doing it when you add your views (the conflict is in your views).

@K-7
Copy link
Author

K-7 commented Nov 27, 2018

You were right, thank you for that. Below I have indicated the changes that I did ie. adding endpoint while adding a view

Initialise the module
admin_control = Admin(name='App', url='/admin')
admin_control.init_app(app, index_view=admin.AdminView())

class AdminView(AdminIndexView):
def is_accessible(self):
if not current_user.is_active or not current_user.is_authenticated or not current_user.is_admin:
return False
return True
def inaccessible_callback(self, name, **kwargs):
# redirect to login page if user doesn't have access
return redirect(url_for('bp_user.login'))
`

Add views
admin_control.add_view(UserView(User, db.session, endpoint="user"))
admin_control.add_view(RoleView(Role, db.session, endpoint="role"))

But after making these changes I am getting a new issue. Below I have attached an screenshot
pertaining to it. The menu shows up as Alchemy query object rather than a string

screenshot 2018-11-27 at 10 12 45 pm

Kindly let me know what wrong am I doing !!
@wimo7083

@apex-omontgomery
Copy link

Not sure, but you're add view call is passing in the model, in my case im excluding the model User and defining the constructor to do this:

class UserView(sqla.ModelView):
    can_export = True

    def __init__(self, session, **kwargs):
        # Just call parent class w  ith predefined model.
        super(UserView, self).__init__(User, session, **kwargs)

looks like your init_admin is also different I only pass in the flask_admin = Admin() call.

@K-7
Copy link
Author

K-7 commented Nov 29, 2018

Ok But i want my AdminView to inherit AdminIndexView and pass model in add view. Not sure where I am going wrong

@alanhamlett
Copy link
Member

@K-7 maybe this helps:
https://gist.github.com/alanhamlett/2942ff58b0263e11dcb8d376b149de43

It's my Flask-Admin setup showing some inheritance.

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

No branches or pull requests

3 participants