Added "get_visible_items" method to associations container
authorThierry Florac <thierry.florac@onf.fr>
Wed, 07 Mar 2018 09:48:42 +0100
changeset 445 ad73bd24079f
parent 444 a20522cd41f6
child 446 4ce676e4859f
Added "get_visible_items" method to associations container
src/pyams_content/component/association/container.py
src/pyams_content/component/association/interfaces/__init__.py
--- a/src/pyams_content/component/association/container.py	Tue Mar 06 16:55:05 2018 +0100
+++ b/src/pyams_content/component/association/container.py	Wed Mar 07 09:48:42 2018 +0100
@@ -17,7 +17,7 @@
 
 # import interfaces
 from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationTarget, \
-    ASSOCIATION_CONTAINER_KEY, IAssociationInfo
+    ASSOCIATION_CONTAINER_KEY, IAssociationItem, IAssociationInfo
 from pyams_content.features.checker.interfaces import IContentChecker
 from zope.annotation.interfaces import IAnnotations
 from zope.location.interfaces import ISublocations
@@ -56,6 +56,9 @@
             # make sure that association item is correctly indexed
             index_object(value)
 
+    def get_visible_items(self):
+        return filter(lambda x: IAssociationItem(x).visible, self.values())
+
 
 @adapter_config(context=IAssociationTarget, provides=IAssociationContainer)
 def association_container_factory(target):
--- a/src/pyams_content/component/association/interfaces/__init__.py	Tue Mar 06 16:55:05 2018 +0100
+++ b/src/pyams_content/component/association/interfaces/__init__.py	Wed Mar 07 09:48:42 2018 +0100
@@ -71,6 +71,9 @@
     def append(self, value, notify=True):
         """Append given value to container"""
 
+    def get_visible_items(self):
+        """Get list of visible items"""
+
 
 class IAssociationTarget(IAttributeAnnotatable):
     """Associations container target interface"""