Skip to content

Commit 5d546b1

Browse files
committed
Refactor is_accessible
Now, no more if statements are used. Also, this should be more readable, and even faster, as in case of any False value, the method can return early. modified: examples/auth/app.py
1 parent c96258e commit 5d546b1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/auth/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ def __str__(self):
5555
# Create customized model view class
5656
class MyModelView(sqla.ModelView):
5757
def is_accessible(self):
58-
if not current_user.is_active or not current_user.is_authenticated:
59-
return False
60-
return current_user.has_role('superuser')
58+
return (current_user.is_active and
59+
current_user.is_authenticated and
60+
current_user.has_role('superuser')
61+
)
6162

6263
def _handle_view(self, name, **kwargs):
6364
"""

0 commit comments

Comments
 (0)