Skip to content

Commit

Permalink
Ensure containers for temporary data. (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmsdev authored Sep 29, 2023
1 parent 5077dd5 commit d7ec249
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
23 changes: 23 additions & 0 deletions Products/zms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def registerDirectory(_context, name, directory=None, recursive=False,
def initialize(context):
"""Initialize the product."""

create_session_storage_if_neccessary(context)
try:
"""Try to register the product."""

Expand Down Expand Up @@ -338,3 +339,25 @@ def translate_path(s):
if s.startswith('/++resource++zms_/'):
l = ['plugins', 'www']+s.split('/')[2:]
return os.sep.join([ZMS_HOME]+l)

def create_session_storage_if_neccessary(context):
"""
Ensure containers for temporary data.
"""
from OFS.Folder import Folder
from Products.Transience.Transience import TransientObjectContainer

app = context.getApplication()
if not 'temp_folder' in app:
# Adding a 'folder' is a just fallback
# if a 'mount_point' is not available
# like usually configured via zope.conf
temp_folder = Folder('temp_folder')
app._setObject('temp_folder', temp_folder)
if not 'session_data' in app.temp_folder:
container = TransientObjectContainer(
'session_data',
title='Session Data Container',
timeout_mins=20
)
app.temp_folder._setObject('session_data', container)
32 changes: 2 additions & 30 deletions Products/zms/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,36 +827,8 @@ def get_session(context):
"""
Get http-session.
"""
request = getattr( context, 'REQUEST', None)
if request.get('SESSION', None) == None:
create_session_storage_if_neccessary(context)
session = request.get('SESSION',request.environ.get('beaker.session',None))
return session

security.declarePublic('create_session_storage_if_neccessary')
def create_session_storage_if_neccessary(context):
"""
Ensure containers for temporary data.
"""
from OFS.Folder import Folder
from Products.Transience.Transience import TransientObjectContainer

root = context.getPhysicalRoot()
if not 'temp_folder' in root:
# Adding a 'folder' is a just fallback
# if a 'mount_point' is not available
# like usually configured via zope.conf
temp_folder = Folder('temp_folder')
root._setObject('temp_folder', temp_folder)
# writeLog( context, 'Missing temp_folder added')
if not 'session_data' in root.temp_folder:
container = TransientObjectContainer(
'session_data',
title='Session Data Container',
timeout_mins=20
)
root.temp_folder._setObject('session_data', container)
# writeLog( context, 'Missing session_data-container added')
request = context.REQUEST
return request.get('SESSION',request.environ.get('beaker.session',None))

security.declarePublic('get_session_value')
def get_session_value(context, key, defaultValue=None):
Expand Down

0 comments on commit d7ec249

Please sign in to comment.