Fixed problems on startup with config session
This commit is contained in:
parent
777c2726d3
commit
f13522559d
|
@ -71,7 +71,7 @@ lm.session_protection = 'strong'
|
||||||
|
|
||||||
ub.init_db(cli.settingspath)
|
ub.init_db(cli.settingspath)
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
config = config_sql.load_configuration(ub.Scoped_Session)
|
config = config_sql.load_configuration()
|
||||||
|
|
||||||
web_server = WebServer()
|
web_server = WebServer()
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ def create_app():
|
||||||
log.info('Starting Calibre Web...')
|
log.info('Starting Calibre Web...')
|
||||||
Principal(app)
|
Principal(app)
|
||||||
lm.init_app(app)
|
lm.init_app(app)
|
||||||
app.secret_key = os.getenv('SECRET_KEY', config_sql.get_flask_session_key(ub.Scoped_Session))
|
app.secret_key = os.getenv('SECRET_KEY', config.get_flask_session_key())
|
||||||
|
|
||||||
web_server.init_app(app, config)
|
web_server.init_app(app, config)
|
||||||
|
|
||||||
|
@ -114,7 +114,6 @@ def create_app():
|
||||||
services.goodreads_support.connect(config.config_goodreads_api_key,
|
services.goodreads_support.connect(config.config_goodreads_api_key,
|
||||||
config.config_goodreads_api_secret,
|
config.config_goodreads_api_secret,
|
||||||
config.config_use_goodreads)
|
config.config_use_goodreads)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@babel.localeselector
|
@babel.localeselector
|
||||||
|
|
|
@ -139,6 +139,7 @@ class _ConfigSQL(object):
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
def __init__(self, session):
|
def __init__(self, session):
|
||||||
self._session = session
|
self._session = session
|
||||||
|
self._session.expire_on_commit = False
|
||||||
self._settings = None
|
self._settings = None
|
||||||
self.db_configured = None
|
self.db_configured = None
|
||||||
self.config_calibre_dir = None
|
self.config_calibre_dir = None
|
||||||
|
@ -241,6 +242,14 @@ class _ConfigSQL(object):
|
||||||
def get_mail_server_configured(self):
|
def get_mail_server_configured(self):
|
||||||
return not bool(self.mail_server == constants.DEFAULT_MAIL_SERVER)
|
return not bool(self.mail_server == constants.DEFAULT_MAIL_SERVER)
|
||||||
|
|
||||||
|
def get_flask_session_key(self):
|
||||||
|
flask_settings = self._session.query(_Flask_Settings).one_or_none()
|
||||||
|
if flask_settings == None:
|
||||||
|
flask_settings = _Flask_Settings(os.urandom(32))
|
||||||
|
self._session.add(flask_settings)
|
||||||
|
self._session.commit()
|
||||||
|
return flask_settings.flask_session_key
|
||||||
|
|
||||||
|
|
||||||
def set_from_dictionary(self, dictionary, field, convertor=None, default=None, encode=None):
|
def set_from_dictionary(self, dictionary, field, convertor=None, default=None, encode=None):
|
||||||
'''Possibly updates a field of this object.
|
'''Possibly updates a field of this object.
|
||||||
|
@ -273,6 +282,10 @@ class _ConfigSQL(object):
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
'''Load all configuration values from the underlying storage.'''
|
'''Load all configuration values from the underlying storage.'''
|
||||||
|
#own = False
|
||||||
|
#if not self._session:
|
||||||
|
# self._session = ub.Scoped_Session()
|
||||||
|
# own = True
|
||||||
s = self._read_from_storage() # type: _Settings
|
s = self._read_from_storage() # type: _Settings
|
||||||
for k, v in s.__dict__.items():
|
for k, v in s.__dict__.items():
|
||||||
if k[0] != '_':
|
if k[0] != '_':
|
||||||
|
@ -395,8 +408,8 @@ def _migrate_database(session):
|
||||||
_migrate_table(session, _Flask_Settings)
|
_migrate_table(session, _Flask_Settings)
|
||||||
|
|
||||||
|
|
||||||
def load_configuration(Session):
|
def load_configuration():
|
||||||
session = Session()
|
session = ub.Scoped_Session()
|
||||||
_migrate_database(session)
|
_migrate_database(session)
|
||||||
|
|
||||||
if not session.query(_Settings).count():
|
if not session.query(_Settings).count():
|
||||||
|
@ -410,15 +423,4 @@ def load_configuration(Session):
|
||||||
session.query(ub.User).filter(ub.User.mature_content != True). \
|
session.query(ub.User).filter(ub.User.mature_content != True). \
|
||||||
update({"denied_tags": conf.config_mature_content_tags}, synchronize_session=False)
|
update({"denied_tags": conf.config_mature_content_tags}, synchronize_session=False)
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
def get_flask_session_key(Session):
|
|
||||||
session = Session()
|
|
||||||
flask_settings = session.query(_Flask_Settings).one_or_none()
|
|
||||||
if flask_settings == None:
|
|
||||||
flask_settings = _Flask_Settings(os.urandom(32))
|
|
||||||
session.add(flask_settings)
|
|
||||||
session.commit()
|
|
||||||
session.close()
|
|
||||||
return flask_settings.flask_session_key
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user