use logger instead of print as often as possible
[myslice.git] / unfold / composite.py
index 7787551..39be524 100644 (file)
@@ -1,7 +1,7 @@
-from __future__ import print_function
-
 from unfold.plugin import Plugin
 
+from myslice.settings import logger
+
 class Composite (Plugin):
 
     """a simple base class for plugins that contain/arrange a set of other plugins
@@ -13,17 +13,17 @@ if a valid active_domid is not provided
 
     def __init__ (self, sons=None, active_domid=None, *args, **kwds):
         Plugin.__init__ (self, *args, **kwds)
-        self.sons= sons if sons else []
-        self.active_domid=active_domid
+        self.sons = sons if sons else []
+        self.active_domid = active_domid
         # make sure this is valid, unset otherwise, so we always have exactly one active
         self.check_active_domid()
         
     def check_active_domid(self):
         matches= [ son for son in self.sons if son.domid==self.active_domid ]
         if len(matches)!=1: 
-            print("WARNING: %s has %d valid son(s) for being active - expecting 1, resetting"%\
-                (self,len(matches)))
-            self.active_domid=None
+            logger.warning("WARNING: {} has {} valid son(s) for being active - expecting 1, resetting"\
+                           .format(self,len(matches)))
+            self.active_domid = None
         
     def insert (self, plugin):
         self.sons.append(plugin)
@@ -33,9 +33,10 @@ if a valid active_domid is not provided
         # {% for son in sons %} {{ son.rendered }} ...
         def is_active (son,rank):
             # if active_domid is not specified, make the first one active
-            if not self.active_domid: return rank==0
-            return son.domid==self.active_domid
-        ranks=range(len(self.sons))
+            if not self.active_domid:
+                return rank==0
+            return son.domid == self.active_domid
+        ranks = range(len(self.sons))
         env = { 'sons':
                  [ { 'rendered': son.render(request),
                      'rank': rank,