Back to index

plone3  3.1.7
referencebrowser_insertHistory.py
Go to the documentation of this file.
00001 ##parameters=path, history_length=20
00002 
00003 # Insert 'at_url' into the list of visited path in front.
00004 # The history is stored as list of tuples
00005 # (relative path to Zope root, relative_path to Plone portal root)
00006 
00007 history = context.REQUEST.SESSION.get('atrefbrowserwidget_history', [])
00008 portal_path = context.portal_url.getPortalObject().absolute_url(1)
00009 
00010 # remove existing entries
00011 for i, tp in enumerate(history):
00012     if path == tp[0]:
00013         del history[i]
00014         break
00015 
00016 # generate a friendly path for UI representation        
00017 visible_path = context.absolute_url(1)
00018 visible_path = visible_path.replace(portal_path, '')
00019 
00020 # insert at the head of the history list
00021 history.insert(0, (path, visible_path))
00022 
00023 # cut off oversized history
00024 history = history[:history_length]
00025 
00026 # put it back into the session
00027 history = context.REQUEST.SESSION.set('atrefbrowserwidget_history', history)