Added assertion about added slot row ID
authorThierry Florac <thierry.florac@onf.fr>
Fri, 21 Sep 2018 18:08:45 +0200
changeset 186 ffec02eb6ef0
parent 185 857fe719736a
child 187 a50dc986331b
Added assertion about added slot row ID
src/pyams_portal/template.py
--- a/src/pyams_portal/template.py	Fri Sep 21 17:14:27 2018 +0200
+++ b/src/pyams_portal/template.py	Fri Sep 21 18:08:45 2018 +0200
@@ -12,37 +12,31 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
-from pyams_portal.interfaces import IPortalTemplateContainer, IPortalTemplateContainerConfiguration, \
-    IPortalTemplate, IPortalTemplateConfiguration, IPortalPortletsConfiguration, IPortlet, IPortletConfiguration, \
-    PORTLETS_CONFIGURATION_KEY, TEMPLATE_CONTAINER_CONFIGURATION_KEY, TEMPLATE_CONFIGURATION_KEY
-from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent
-from zope.traversing.interfaces import ITraversable
-
-# import packages
 from persistent import Persistent
 from persistent.list import PersistentList
 from persistent.mapping import PersistentMapping
-from pyams_portal.portlet import PortalPortletsConfiguration
-from pyams_portal.slot import SlotConfiguration
-from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
-from pyams_utils.registry import get_local_registry, get_utility
-from pyams_utils.request import check_request
-from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
 from pyramid.threadlocal import get_current_registry
 from zope.componentvocabulary.vocabulary import UtilityVocabulary
 from zope.container.contained import Contained
 from zope.container.folder import Folder
 from zope.interface import implementer
+from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent
 from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
+from zope.traversing.interfaces import ITraversable
 
 from pyams_portal import _
+from pyams_portal.interfaces import IPortalPortletsConfiguration, IPortalTemplate, IPortalTemplateConfiguration, \
+    IPortalTemplateContainer, IPortalTemplateContainerConfiguration, IPortlet, IPortletConfiguration, \
+    PORTLETS_CONFIGURATION_KEY, TEMPLATE_CONFIGURATION_KEY, TEMPLATE_CONTAINER_CONFIGURATION_KEY
+from pyams_portal.portlet import PortalPortletsConfiguration
+from pyams_portal.slot import SlotConfiguration
+from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter
+from pyams_utils.registry import get_local_registry, get_utility
+from pyams_utils.request import check_request
+from pyams_utils.vocabulary import vocabulary_config
 
 
 #
@@ -160,10 +154,10 @@
                 self.slot_names.remove(slot_name)
             if slot_name in self.slot_config:
                 del self.slot_config[slot_name]
-        for index in range(row_id, self.rows-1):
-            self.slot_order[index] = self.slot_order[index+1]
+        for index in range(row_id, self.rows - 1):
+            self.slot_order[index] = self.slot_order[index + 1]
         if self.rows > 0:
-            del self.slot_order[self.rows-1]
+            del self.slot_order[self.rows - 1]
         self.rows -= 1
 
     # slots management
@@ -197,6 +191,7 @@
         self.slot_names.append(slot_name)
         if row_id is None:
             row_id = 0
+        assert 0 <= row_id < self.rows
         # init slots order
         if row_id not in self.slot_order:
             self.slot_order[row_id] = PersistentList()