Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
f1352255
Commit
f1352255
authored
Dec 07, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed problems on startup with config session
parent
777c2726
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
16 deletions
+17
-16
__init__.py
cps/__init__.py
+2
-3
config_sql.py
cps/config_sql.py
+15
-13
No files found.
cps/__init__.py
View file @
f1352255
...
@@ -71,7 +71,7 @@ lm.session_protection = 'strong'
...
@@ -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():
...
@@ -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():
...
@@ -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
...
...
cps/config_sql.py
View file @
f1352255
...
@@ -139,6 +139,7 @@ class _ConfigSQL(object):
...
@@ -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):
...
@@ -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):
...
@@ -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):
...
@@ -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):
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment