X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=unfold%2Fplugin.py;h=4e97d678617ab9680858e8adbd59d1ba0ca427a9;hb=af7c18aea18be19b7227b25a019af4d257cee7dd;hp=cc2eaeba102ac6e3c1a8d60249da96c36f3515d9;hpb=2deac18823cfd044b8a2b2ec67420f0a2d70a776;p=myslice.git diff --git a/unfold/plugin.py b/unfold/plugin.py index cc2eaeba..4e97d678 100644 --- a/unfold/plugin.py +++ b/unfold/plugin.py @@ -32,10 +32,14 @@ class Plugin: # we just need this to be unique in a page domid=0 - @staticmethod - def newdomid(): + # when a domid is not set by the caller, we name plugins after their respective class as well, + # so as to limit name clashes between different views + # this has to see with the UI storing the last-seen status of plugins based on their id + # put it more bluntly it is recommended that a domid should be set + # and maybe xxx we should just enforce that... + def newdomid(self): Plugin.domid += 1 - return "plugin-%d"%Plugin.domid + return "plugin-%s-%d"%(self.__class__.__name__.lower(),Plugin.domid) ########## # Constructor @@ -65,19 +69,22 @@ class Plugin: # p=Plugin(foo='bar') # which will result in 'foo' being accessible to the template engine # - def __init__ (self, page, title, domid=None, - visible=True, togglable=True, toggled=None, **settings): + def __init__ (self, page, title=None, domid=None, + visible=True, togglable=None, toggled=None, **settings): self.page = page - self.title=title # callers can provide their domid for css'ing - if not domid: domid=Plugin.newdomid() + if not domid: domid=self.newdomid() self.domid=domid + # title is shown when togglable + if not title: title="Plugin title for %s"%domid + self.title=title self.classname=self._py_classname() self.plugin_classname=self._js_classname() self.visible=visible - self.togglable=togglable - if toggled is not None: self.toggled=toggled - else: self.toggled=self.default_toggled() + if togglable is None: self.togglable=self.default_togglable() + else: self.togglable=togglable + if toggled is None: self.toggled=self.default_toggled() + else: self.toggled=toggled # what comes from subclasses for (k,v) in settings.iteritems(): setattr(self,k,v) @@ -156,6 +163,7 @@ class Plugin: self.need_spin=self.start_with_spin() env.update(self.__dict__) # translate high-level 'toggled' into 4 different booleans + self.need_toggle = False if self.toggled=='persistent': # start with everything turned off and let the js callback do its job env.update({'persistent_toggle':True,'display_hide_button':False,'display_show_button':False,'display_body':False}) @@ -250,6 +258,7 @@ class Plugin: def template_file (self): return "undefined_template" def template_env (self, request): return {} + def default_togglable (self): return True def default_toggled (self): return 'persistent' # # tell the framework about requirements (for the document
)