src/pyams_skin/interfaces/extension.py
changeset 508 eb708d0e9298
parent 506 08196fe15f4a
child 576 998a3b7cac64
--- a/src/pyams_skin/interfaces/extension.py	Wed Jan 16 19:13:01 2019 +0100
+++ b/src/pyams_skin/interfaces/extension.py	Wed Jan 16 23:39:45 2019 +0100
@@ -12,7 +12,7 @@
 
 __docformat__ = 'restructuredtext'
 
-from zope.interface import Interface
+from zope.interface import Interface, invariant, Invalid
 from zope.schema import Bool, Choice, TextLine
 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
 
@@ -29,7 +29,6 @@
 
 ACTIVATION_MODES = SimpleVocabulary([SimpleTerm(k, title=v) for k, v in ACTIVATION_MODES_LABELS.items()])
 
-
 GOOGLE_TAGS_INFO_KEY = 'pyams_skin.tagmanager_info'
 
 
@@ -54,6 +53,11 @@
                                      description=_("Cookie value matching user's cookies reject"),
                                      required=False)
 
+    @invariant
+    def check_cookie(self):
+        if self.on_accepted_cookie and not (self.cookie_name and self.rejected_cookie_value):
+            raise Invalid(_("You must specify cookie name and reject value !!"))
+
     container_id = TextLine(title=_("Container ID"),
                             description=_("Google Tag Manager container ID (may start with 'GTM-')"),
                             required=False)
@@ -93,6 +97,11 @@
                                      description=_("Cookie value matching user's cookies reject"),
                                      required=False)
 
+    @invariant
+    def check_cookie(self):
+        if self.on_accepted_cookie and not (self.cookie_name and self.rejected_cookie_value):
+            raise Invalid(_("You must specify cookie name and reject value !!"))
+
     website_id = TextLine(title=_("Web site ID"),
                           description=_("Google Analytics web site ID"),
                           required=False)
@@ -128,6 +137,11 @@
                                      description=_("Cookie value matching user's cookies reject"),
                                      required=False)
 
+    @invariant
+    def check_cookie(self):
+        if self.on_accepted_cookie and not (self.cookie_name and self.rejected_cookie_value):
+            raise Invalid(_("You must specify cookie name and reject value !!"))
+
     account_id = TextLine(title=_("Account ID"),
                           description=_("UserReport account ID, available in 'initSite' code snippet"),
                           required=False)