witten
/
luminotes
Archived
1
0
Fork 0
This repository has been archived on 2023-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
luminotes/controller/Session_storage.py

30 lines
900 B
Python
Raw Normal View History

import cherrypy
from psycopg2 import ProgrammingError
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()
def load( self, *args, **kwargs ):
try:
return PostgreSQLStorage.load( self, *args, **kwargs )
# catch "ProgrammingError: no results to fetch" from self.cursor.fetchall()
except ProgrammingError:
return None
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()