-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Peterson
committed
Aug 29, 2019
1 parent
ba3d26e
commit add798f
Showing
1 changed file
with
12 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from flask_admin import Admin | ||
from flask_admin import helpers as admin_helpers, expose | ||
from flask_security import Security, login_required | ||
from munch import Munch | ||
|
||
from .security import ( | ||
SecureModelView, SecureRedirectIndex, | ||
|
@@ -129,18 +130,19 @@ def add_layout_to_admin(self, admin, app, db, options): | |
|
||
for model_name, view_options_bag in zip_longest( | ||
self.models, self.view_options, fillvalue={}): | ||
view_options_bag = Munch(view_options_bag) | ||
|
||
# Add default view options | ||
if not view_options_bag.get('scaffold_list_columns'): | ||
view_options_bag['scaffold_list_columns'] = \ | ||
view_options_bag.scaffold_list_columns = \ | ||
scaffold_list_columns_respecting_roles | ||
if not view_options_bag.get('scaffold_form'): | ||
view_options_bag['scaffold_form'] = \ | ||
view_options_bag.scaffold_form = \ | ||
scaffold_form_respecting_roles | ||
if not view_options_bag.get('role_only_columns'): | ||
view_options_bag['role_only_columns'] = dict() | ||
view_options_bag.role_only_columns = dict() | ||
if not view_options_bag.get('roles_accepted'): | ||
view_options_bag['roles_accepted'] = self.admin_roles_accepted | ||
view_options_bag.roles_accepted = self.admin_roles_accepted | ||
|
||
# TODO: SQLSoup-specific | ||
model = getattr(db, model_name) | ||
|
@@ -155,14 +157,15 @@ def add_layout_to_admin(self, admin, app, db, options): | |
return admin | ||
|
||
def bootstrap_database(self, app, db): | ||
# TODO: This only works if the psql command is available | ||
# and the database is a postgres database | ||
|
||
try: | ||
database_name = db._metadata._bind.url.database | ||
# TODO: This only works if the psql command is available | ||
# and the database is a postgres database | ||
command_args = ['psql', database_name, '-c', "select * from users;"] | ||
try: | ||
completed = subprocess.run(command_args, capture_output=True) | ||
except TypeError: | ||
except TypeError: # Support py3.6 | ||
completed = subprocess.run(command_args, stdout=subprocess.PIPE) | ||
if re.search('\(0 rows\)', str(completed.stdout)): | ||
print('Detected first usage of admin.') | ||
|
@@ -172,7 +175,7 @@ def bootstrap_database(self, app, db): | |
'user: [email protected], password: password') | ||
print('Have fun!') | ||
except Exception: | ||
exc_type, exc_obj, exc_tb = sys.exc_info() | ||
exc_type, _, exc_tb = sys.exc_info() | ||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] | ||
print('Failed to bootstrap database!') | ||
print(exc_type, fname, exc_tb.tb_lineno) | ||
|
@@ -198,5 +201,6 @@ def add_admin(self, app, db, options): | |
|
||
def add_security(self, app, db, options): | ||
# Initialize flask-security | ||
# TODO: Also sqlsoup specific | ||
user_datastore = SQLSoupUserDataStore(db, db.users, db.roles) | ||
return Security(app, user_datastore) |