-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Move add_url function definition out of Dash.__init__() #377
Move add_url function definition out of Dash.__init__() #377
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with theses changes once the method is private.
dash/dash.py
Outdated
@@ -217,6 +209,14 @@ def add_url(name, view_func, methods=('GET',)): | |||
self._cached_layout = None | |||
self.routes = [] | |||
|
|||
def add_url(self, name, view_func, methods=('GET',)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make that "private" by prefixing with _
.
@T4rk1n Sorry for the delay, I think this is ready for another look. Thanks! |
@hinnefe2 I think your merge with master went bad, there is a line that should be in |
Thanks, looks good now. 💃 Since this is for wrapping the routes in Then instead of subclassing Dash, you can wrap the routes externally: for view_name, view_method in (
(x, app.server.view_functions[x])
for x in app.routes
if x in app.server.view_functions
):
app.server.view_functions[view_name] = login_required(view_method) @rmarren1 can you have a look too ? |
I like this change. I don't see a drawback to defining Not sure why |
@T4rk1n Ok, I think this is ready for another look. Thanks again for your patience! |
@hinnefe2 Great. We got a new CONTRIBUTING guide, make sure to you have everything on the pre-merge checklist (update version.py and changelogs) to accelerate the merge/release process. |
Alright, changelog is updated and version is bumped, anything else for me to do? |
Looks great, thanks! 🎊 |
Released |
First of all, thanks for a great tool!
This PR moves the
add_url
utility function out of the__init__
method of theDash
class. This change makes it easier to subclassDash
.My use case is adding authentication via flask_login. Pulling
add_url
out lets me subclass like so:Note that each
view_func
is wrapped bylogin_required
so all my dash pages now require authentication.I think this addresses some of the comments in #214.