changeset 394:ce9fa69f81c3

new toggle option method
author casties
date Mon, 08 Nov 2010 15:59:40 +0100
parents bb317af1c197
children e6f3fcb2058f
files documentViewer.py
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/documentViewer.py	Wed Nov 03 15:59:05 2010 +0100
+++ b/documentViewer.py	Mon Nov 08 15:59:40 2010 +0100
@@ -397,6 +397,20 @@
         pt = getattr(self.template, 'info_xml')
         return pt(docinfo=docinfo)
 
+    def getOptionToggle(self, newState=None, optionName='text_options_open', initialState=True):
+        """returns new option state"""
+        opt = self.REQUEST.SESSION.get(optionName,None)
+        if opt is None:
+            # not in session -- initial
+            opt = {'lastState': newState, 'state': initialState}
+        else:
+            if opt['lastState'] != newState:
+                # state in session has changed -- toggle
+                opt['state'] = not opt['state']
+                opt['lastState'] = newState
+        
+        self.REQUEST.SESSION[optionName] = opt
+        return opt['state']
     
     def isAccessible(self, docinfo):
         """returns if access to the resource is granted"""