Index: quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/plonetabs.py
===================================================================
--- quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/plonetabs.py	(revision 3244)
+++ quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/plonetabs.py	(revision 3437)
@@ -24,5 +24,5 @@
 from Products.statusmessages.interfaces import IStatusMessage
 
-from quintagroup.plonetabs.config import *
+from quintagroup.plonetabs.config import PROPERTY_SHEET, FIELD_NAME
 from quintagroup.plonetabs import messageFactory as _
 from interfaces import IPloneTabsControlPanel
@@ -39,4 +39,5 @@
 cookie_name = 'ploneTabsMode'
 
+
 class PloneTabsControlPanel(PloneKSSView):
 
@@ -60,8 +61,6 @@
         postback = True
         errors = {}
-        context = aq_inner(self.context)
 
         form = self.request.form
-        action = form.get("action", "")
         submitted = form.get('form.submitted', False)
 
@@ -148,5 +147,5 @@
             IStatusMessage(self.request).addStatusMessage(
                 _(u"'${id}' action successfully added.",
-                  mapping={'id':action.id}), type="info")
+                  mapping={'id': action.id}), type="info")
             self.redirect(search="category=%s" % cat_name)
             return False
@@ -179,5 +178,5 @@
         else:
             errs.update(self.processErrors(errors,
-                sufix='_%s' % id)) # add edit form sufix to error ids
+                sufix='_%s' % id))  # add edit form sufix to error ids
             IStatusMessage(self.request).addStatusMessage(
                 _(u"Please correct the indicated errors."), type="error")
@@ -214,5 +213,5 @@
             self.moveAction(id, cat_name, steps=1)
             IStatusMessage(self.request).addStatusMessage(
-                _(u"'${id}' action moved up.", mapping={'id': id}), type="info")
+               _(u"'${id}' action moved up.", mapping={'id': id}), type="info")
             self.redirect(search="category=%s" % cat_name)
             return False
@@ -247,5 +246,5 @@
         """Redirect to @@plonetabs-controlpanel configlet"""
         if not url:
-            portal_url =  getMultiAdapter((self.context, self.request),
+            portal_url = getMultiAdapter((self.context, self.request),
                 name=u"plone_portal_state").portal_url()
             url = '%s/%s' % (portal_url, "@@plonetabs-controlpanel")
@@ -302,5 +301,5 @@
         """See interface"""
         tool = getToolByName(self.context, "portal_actions")
-        return len(tool.listActions(categories=[category,])) > 0
+        return len(tool.listActions(categories=[category, ])) > 0
 
     def getPortalActions(self, category="portal_tabs"):
@@ -322,5 +321,6 @@
         site_properties = getToolByName(self.context,
                                         "portal_properties").site_properties
-        return not site_properties.getProperty("disable_folder_sections", False)
+        return not site_properties.getProperty("disable_folder_sections",
+                                               False)
 
     def isNotFoldersGenerated(self):
@@ -364,5 +364,5 @@
         query = {}
         rootPath = getNavigationRoot(context)
-        query['path'] = {'query' : rootPath, 'depth' : 1}
+        query['path'] = {'query': rootPath, 'depth': 1}
         query['portal_type'] = utils.typesToList(context)
 
@@ -388,5 +388,5 @@
         excludedIds = {}
         for id in idsNotToList:
-            excludedIds[id]=1
+            excludedIds[id] = 1
 
         rawresult = portal_catalog.searchResults(**query)
@@ -396,9 +396,9 @@
             if not excludedIds.has_key(item.getId):
                 id, item_url = get_view_url(item)
-                data = {'name'       : utils.pretty_title_or_id(context, item),
-                        'id'         : id,
-                        'url'        : item_url,
+                data = {'name': utils.pretty_title_or_id(context, item),
+                        'id': id,
+                        'url': item_url,
                         'description': item.Description,
-                        'exclude_from_nav' : item.exclude_from_nav}
+                        'exclude_from_nav': item.exclude_from_nav}
                 result.append(data)
 
@@ -426,12 +426,18 @@
     def portal_tabs(self):
         """See global-sections viewlet"""
-        actions = context_state = getMultiAdapter((self.context, self.request),
-            name=u"plone_context_state").actions()
+        actions = getMultiAdapter((self.context, self.request),
+                                   name=u'plone_context_state').actions()
+        actions_tabs = []
+        try:
+            # Plone 4 and higher
+            import plone.app.upgrade
+            plone.app.upgrade  # pyflakes
+        except ImportError:
+            actions_tabs = actions
+        if not actions_tabs and 'portal_tabs' in actions:
+            actions_tabs = actions['portal_tabs']
+
         portal_tabs_view = getMultiAdapter((self.context, self.request),
             name="portal_tabs_view")
-        if 'portal_tabs' in actions:
-            actions_tabs = actions['portal_tabs']
-        else:
-            actions_tabs = []
         return portal_tabs_view.topLevelTabs(actions=actions_tabs)
 
@@ -513,5 +519,6 @@
         ksscore = self.getCommandSet("core")
         content = self.getGeneratedTabs()
-        ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('roottabs'), content)
+        ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('roottabs'),
+                                 content)
 
         # update global-sections viewlet
@@ -531,7 +538,6 @@
 
         if obj_id not in portal.objectIds():
-            raise KSSExplicitError, \
-                  _(u"Object with '${id}' id doesn't exist in portal root.",
-                    mapping={'id': obj_id})
+            raise KSSExplicitError("Object with %s id doesn't" +\
+                                   " exist in portal root." % obj_id)
 
         if checked == '1':
@@ -548,9 +554,9 @@
                 value="invisible")
             message = _(u"'${id}' object was included into navigation.",
-                        mapping={'id':obj_id})
+                        mapping={'id': obj_id})
         else:
             ksscore.addClass(ksscore.getHtmlIdSelector(id), value="invisible")
             message = _(u"'${id}' object was excluded from navigation.",
-                        mapping={'id':obj_id})
+                        mapping={'id': obj_id})
 
         # update global-sections viewlet
@@ -574,9 +580,9 @@
                 value="invisible")
             message = _(u"'${id}' action is now visible.",
-                        mapping={'id':act_id})
+                        mapping={'id': act_id})
         else:
             ksscore.addClass(ksscore.getHtmlIdSelector(id), value="invisible")
             message = _(u"'${id}' action is now invisible.",
-                        mapping={'id':act_id})
+                        mapping={'id': act_id})
         self.updatePage(cat_name)
 
@@ -602,5 +608,5 @@
         # issue portal status message
         self.kss_issueMessage(_(u"'${id}' action successfully removed.",
-                                mapping={'id':act_id}))
+                                mapping={'id': act_id}))
 
     @kssaction
@@ -615,5 +621,4 @@
         # if not errors find (or create) category and set action to it
         ksscore = self.getCommandSet('core')
-        kssplone = self.getCommandSet('plone')
         if not errors:
             action = self.addAction(cat_name, data)
@@ -621,7 +626,8 @@
             # update client
             # add one more action to actions list
-            content = self.getActionsList(category=cat_name, tabs=[action,])
-            ksscore.insertHTMLAsLastChild(ksscore.getHtmlIdSelector('tabslist'),
-                 content)
+            content = self.getActionsList(category=cat_name, tabs=[action, ])
+            ksscore.insertHTMLAsLastChild(
+                                         ksscore.getHtmlIdSelector('tabslist'),
+                                         content)
 
             # update reorder controls
@@ -646,5 +652,5 @@
 
             message = _(u"'${id}' action successfully added.",
-                        mapping={'id':action.id})
+                        mapping={'id': action.id})
             msgtype = "info"
 
@@ -655,6 +661,6 @@
             if errors.has_key('id') or errors.has_key('available_expr'):
                 self.kss_toggleCollapsible(
-                    ksscore.getCssSelector('form[name=addaction_form] '
-                                           '.headerAdvanced'), collapse='false')
+                   ksscore.getCssSelector('form[name=addaction_form] '
+                                          '.headerAdvanced'), collapse='false')
 
             message = _(u"Please correct the indicated errors.")
@@ -678,6 +684,6 @@
         # collapse advanced section
         self.kss_toggleCollapsible(
-            ksscore.getCssSelector('form[name=addaction_form] .headerAdvanced'),
-            collapse='true')
+           ksscore.getCssSelector('form[name=addaction_form] .headerAdvanced'),
+                                  collapse='true')
 
         # reset form inputs
@@ -705,5 +711,5 @@
         # update client
         ksscore = self.getCommandSet("core")
-        content = self.getActionsList(category=cat_name, tabs=[action_info,])
+        content = self.getActionsList(category=cat_name, tabs=[action_info, ])
         ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content)
 
@@ -722,5 +728,5 @@
         # update client
         ksscore = self.getCommandSet("core")
-        content = self.getActionsList(category=cat_name, tabs=[action,])
+        content = self.getActionsList(category=cat_name, tabs=[action, ])
         ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content)
 
@@ -743,5 +749,4 @@
         html_id = '%s%s%s' % (self.prefix, id, self.sufix)
         ksscore = self.getCommandSet('core')
-        kssplone = self.getCommandSet('plone')
         if not errors:
             action = self.updateAction(id, cat_name, data)
@@ -749,9 +754,9 @@
             # update client
             # replace action item with updated one
-            content = self.getActionsList(category=cat_name, tabs=[action,])
+            content = self.getActionsList(category=cat_name, tabs=[action, ])
             ksscore.replaceHTML(ksscore.getHtmlIdSelector(html_id), content)
 
             message = _(u"'${id}' action successfully updated.",
-                        mapping={'id':action.id})
+                        mapping={'id': action.id})
             msgtype = "info"
 
@@ -820,5 +825,5 @@
     def copyAction(self, action):
         """Copy action to dictionary"""
-        action_info = {'description':action.description}
+        action_info = {'description': action.description}
         for attr in ACTION_ATTRS:
             action_info[attr] = getattr(action, attr)
@@ -842,5 +847,5 @@
             chooser.checkName(data['id'], self.context)
         except Exception, e:
-            errors['id'] = self._formatError(e, **{'id':data['id']})
+            errors['id'] = self._formatError(e, **{'id': data['id']})
 
         # validate action name
@@ -968,7 +973,6 @@
             category = self.getActionCategory(cat_name)
         except Exception:
-            raise KSSExplicitError, \
-                  _(u"'${cat_name}' action category does not exist.",
-                    mapping={'cat_name': cat_name})
+            raise KSSExplicitError(u"%s action category does not exist." %\
+                                   cat_name)
 
         # extract action id from given list item id on client
@@ -978,7 +982,6 @@
             action = category[action_id]
         except Exception:
-            raise KSSExplicitError, \
-                  _(u"No '${id}' action in '${cat_name}' category.",
-                    mapping={'id': action_id, 'cat_name': cat_name})
+            raise KSSExplicitError("No %s action in %s category." %\
+                                              (action_id, cat_name))
 
         return (action_id, category, action)
@@ -1001,5 +1004,6 @@
                 '.error-container' % (id, UI_ATTRS.get(name, name)))
         else:
-            field_selector = ksscore.getCssSelector('form[name=addaction_form] '
+            field_selector = ksscore.getCssSelector('form' +\
+                '[name=addaction_form] '
                 '.field-%s' % UI_ATTRS.get(name, name))
             field_error_selector = ksscore.getCssSelector('form[name='
@@ -1023,17 +1027,16 @@
                                            selector)
         if collapsed is not None:
-            data = command.addParam('collapsed', collapsed)
+            command.addParam('collapsed', collapsed)
         if expanded is not None:
-            data = command.addParam('expanded', expanded)
+            command.addParam('expanded', expanded)
         if collapse is not None:
-            data = command.addParam('collapse', collapse)
+            command.addParam('collapse', collapse)
 
     def kss_resetForm(self, selector):
         """KSS Server command to reset form on client"""
-        command = self.commands.addCommand('plonetabs-resetForm', selector)
 
     def kss_blur(self, selector):
         """KSS Server command to remove focus from input"""
-        command = self.commands.addCommand('plonetabs-blur', selector)
+        self.commands.addCommand('plonetabs-blur', selector)
 
     def kss_replaceOrInsert(self, selector, parentSelector, html,
@@ -1044,23 +1047,24 @@
         command = self.commands.addCommand('plonetabs-replaceOrInsert',
             selector)
-        data = command.addParam('selector', parentSelector)
-        data = command.addHtmlParam('html', html)
-        data = command.addParam('withKssSetup', withKssSetup)
+        command.addParam('selector', parentSelector)
+        command.addHtmlParam('html', html)
+        command.addParam('withKssSetup', withKssSetup)
         if alternativeHTML:
-            data = command.addHtmlParam('alternativeHTML', alternativeHTML)
+            command.addHtmlParam('alternativeHTML', alternativeHTML)
         if selectorType:
-            data = command.addParam('selectorType', selectorType)
+            command.addParam('selectorType', selectorType)
         if position:
-            data = command.addParam('position', position)
+            command.addParam('position', position)
         if positionSelector:
-            data = command.addParam('positionSelector', positionSelector)
+            command.addParam('positionSelector', positionSelector)
         if positionSelectorType:
-            data = command.addParam('positionSelectorType',
-                                    positionSelectorType)
+            command.addParam('positionSelectorType',
+                              positionSelectorType)
 
     def kss_issueMessage(self, message, msgtype="info"):
         """"Issues portal status message and removes it afte 10 seconds"""
         ksscore = self.getCommandSet('core')
-        self.getCommandSet('plone').issuePortalMessage(message, msgtype=msgtype)
+        self.getCommandSet('plone').issuePortalMessage(message,
+                                                       msgtype=msgtype)
         self.kss_timeout(
             ksscore.getHtmlIdSelector('kssPortalMessage'),
@@ -1071,5 +1075,5 @@
     def kss_timeout(self, selector, **kw):
         """KSS Server command to execute plonetabs-timeout client action"""
-        command = self.commands.addCommand('plonetabs-timeout', selector, **kw)
+        self.commands.addCommand('plonetabs-timeout', selector, **kw)
 
     def renderViewlet(self, manager, name):
@@ -1117,5 +1121,5 @@
         """Delete action with given id from given category"""
         category = self.getActionCategory(cat_name)
-        category.manage_delObjects(ids=[id,])
+        category.manage_delObjects(ids=[id, ])
         return True
 
@@ -1125,7 +1129,7 @@
             category = self.getActionCategory(cat_name)
             if steps > 0:
-                category.moveObjectsUp([id,], steps)
+                category.moveObjectsUp([id, ], steps)
             else:
-                category.moveObjectsDown([id,], abs(steps))
+                category.moveObjectsDown([id, ], abs(steps))
             return True
         return False
@@ -1170,7 +1174,7 @@
         #ksszope = self.getCommandSet("zope")
         #ksszope.refreshViewlet(
-            #self.getCommandSet("core").getHtmlIdSelector("portal-siteactions"),
-            #"plone.portalheader",
-            #"plone.site_actions")
+           #self.getCommandSet("core").getHtmlIdSelector("portal-siteactions"),
+           #"plone.portalheader",
+           #"plone.site_actions")
 
     def updateUserPageSection(self):
@@ -1183,4 +1187,5 @@
             "plone.personal_bar")
 
+
 class PloneTabsMode(BrowserView):
 
