X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=unfold%2Fcomposite.py;h=39be5240ae0490185ddf15770ee9e3b460122ac7;hb=02a8b0acf7a47f0cb740239d0a035a4e53f1af19;hp=16e28f30071ada65fa8afe92c606ebf319f3342c;hpb=1aea42c3668602aacfe22bc762ee939672129f53;p=unfold.git diff --git a/unfold/composite.py b/unfold/composite.py index 16e28f30..39be5240 100644 --- a/unfold/composite.py +++ b/unfold/composite.py @@ -1,26 +1,29 @@ from unfold.plugin import Plugin -# this is a simple base class for plugins that contain/arrange a set of other plugins -# sons is expected to be a list of the contained plugins, and -# active_domid is the domid for the one son that should be displayed as active -# some subclasses of Composite, like e.g. Tabs, will not behave as expected -# if a valid active_domid is not provided +from myslice.settings import logger class Composite (Plugin): + """a simple base class for plugins that contain/arrange a set of other plugins +sons is expected to be a list of the contained plugins, and +active_domid is the domid for the one son that should be displayed as active +some subclasses of Composite, like e.g. Tabs, will not behave as expected +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) @@ -30,9 +33,10 @@ class Composite (Plugin): # {% 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,