Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Belgian Biodiversity Platform
cputils
Commits
18d0c152
Commit
18d0c152
authored
Sep 22, 2016
by
Julien Cigar
🤘
Browse files
attach session to request, release session in plugin
parent
54b9fa94
Changes
2
Hide whitespace changes
Inline
Side-by-side
plugins/sa_plugin.py
View file @
18d0c152
...
...
@@ -48,6 +48,7 @@ class SAEnginePlugin(plugins.SimplePlugin):
self
.
config
=
config
self
.
bus
.
subscribe
(
'get-session'
,
self
.
get_session
)
self
.
bus
.
subscribe
(
'release-session'
,
self
.
release_session
)
def
start
(
self
):
self
.
bus
.
log
(
'SAEnginePlugin: Starting up DB access'
)
...
...
@@ -95,4 +96,7 @@ class SAEnginePlugin(plugins.SimplePlugin):
self
.
sa_engine
=
None
def
get_session
(
self
):
return
self
.
sa_session
return
self
.
sa_session
()
def
release_session
(
self
):
self
.
sa_session
.
remove
()
tools/sa_tool.py
View file @
18d0c152
...
...
@@ -10,7 +10,6 @@ class SATool(cherrypy.Tool):
def
__init__
(
self
):
super
(
SATool
,
self
).
__init__
(
'on_start_resource'
,
self
.
bind_session
,
priority
=
20
)
self
.
session
=
None
def
_setup
(
self
):
super
(
SATool
,
self
).
_setup
()
...
...
@@ -18,11 +17,8 @@ class SATool(cherrypy.Tool):
self
.
remove_session
,
priority
=
80
)
def
bind_session
(
self
):
self
.
session
=
cherrypy
.
engine
.
publish
(
'get-session'
)
.
pop
()
cherrypy
.
request
.
db
=
cherrypy
.
engine
.
publish
(
'get-session'
)
def
remove_session
(
self
):
if
not
self
.
session
:
return
self
.
session
.
remove
()
self
.
session
=
None
cherrypy
.
request
.
db
=
None
cherrypy
.
engine
.
publish
(
'release-session'
)
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