Added illustration's "has_data" method to check is illustration is provided for at least one language
authorThierry Florac <thierry.florac@onf.fr>
Fri, 15 Jun 2018 11:03:40 +0200
changeset 686 43ebbd99dd62
parent 685 081cb4c45d29
child 687 2a176cd699ac
Added illustration's "has_data" method to check is illustration is provided for at least one language
src/pyams_content/component/illustration/__init__.py
src/pyams_content/component/illustration/interfaces/__init__.py
--- a/src/pyams_content/component/illustration/__init__.py	Fri Jun 15 11:03:03 2018 +0200
+++ b/src/pyams_content/component/illustration/__init__.py	Fri Jun 15 11:03:40 2018 +0200
@@ -66,6 +66,14 @@
             if IImage.providedBy(data):
                 alsoProvides(data, IResponsiveImage)
 
+    def has_data(self):
+        if not self._data:
+            return False
+        for data in self._data.values():
+            if bool(data):
+                return True
+        return False
+
 
 @adapter_config(context=IBasicIllustrationTarget, provides=IIllustration)
 def basic_illustration_factory(context):
--- a/src/pyams_content/component/illustration/interfaces/__init__.py	Fri Jun 15 11:03:03 2018 +0200
+++ b/src/pyams_content/component/illustration/interfaces/__init__.py	Fri Jun 15 11:03:40 2018 +0200
@@ -45,6 +45,9 @@
                                    description=_("Image or video content"),
                                    required=False)
 
+    def has_data(self):
+        """Check if data is provided in any language"""
+
     title = I18nTextLineField(title=_("Legend"),
                               required=False)