2008-10-29 21:26:22 +00:00
|
|
|
import cherrypy
|
2008-10-29 22:09:45 +00:00
|
|
|
from psycopg2 import ProgrammingError
|
2008-10-29 21:26:22 +00:00
|
|
|
from cherrypy.filters.sessionfilter import PostgreSQLStorage
|
|
|
|
|
|
|
|
|
|
|
|
class Session_storage( PostgreSQLStorage ):
|
|
|
|
"""
|
|
|
|
A wrapper for CherryPy's PostgreSQLStorage class that commits the current transaction to the
|
|
|
|
database so session changes actually take effect.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__( self ):
|
|
|
|
self.db = cherrypy.root.database.get_connection()
|
|
|
|
self.cursor = self.db.cursor()
|
|
|
|
|
2008-10-29 22:09:45 +00:00
|
|
|
def load( self, *args, **kwargs ):
|
|
|
|
try:
|
2008-10-29 22:33:15 +00:00
|
|
|
return PostgreSQLStorage.load( self, *args, **kwargs )
|
2008-10-29 22:09:45 +00:00
|
|
|
# catch "ProgrammingError: no results to fetch" from self.cursor.fetchall()
|
|
|
|
except ProgrammingError:
|
|
|
|
return None
|
|
|
|
|
2008-10-29 21:26:22 +00:00
|
|
|
def save( self, *args, **kwargs ):
|
|
|
|
PostgreSQLStorage.save( self, *args, **kwargs )
|
|
|
|
self.db.commit()
|
|
|
|
|
|
|
|
def clean_up( self, *args, **kwargs ):
|
|
|
|
PostgreSQLStorage.clean_up( self, *args, **kwargs )
|
|
|
|
self.db.commit()
|