X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=unfold%2Fplugin.py;h=de84878c1f58d3f26cdffbe55c1726b1903d5f4b;hb=3a4e8104cf076bbbfb5219424f08629a295c4ccd;hp=f9e1ea41b07f380fbc5b3645c2f514fb316af2d8;hpb=2d8d2976d8dba26159f42d10152715160c0c1770;p=myslice.git diff --git a/unfold/plugin.py b/unfold/plugin.py index f9e1ea41..de84878c 100644 --- a/unfold/plugin.py +++ b/unfold/plugin.py @@ -22,6 +22,8 @@ DEBUG= False # decorator to deflect calls on Plugin to its Prelude through self.page.prelude def to_prelude (method): def actual (self, *args, **kwds): + if not self.page: # jordan + return None prelude_method=Prelude.__dict__[method.__name__] return prelude_method(self.page.prelude,*args, **kwds) return actual @@ -32,10 +34,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,13 +71,15 @@ class Plugin: # p=Plugin(foo='bar') # which will result in 'foo' being accessible to the template engine # - def __init__ (self, page, title, domid=None, + 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 @@ -89,7 +97,8 @@ class Plugin: for (k,v) in self.__dict__.items(): print "dbg %s:%s"%(k,v) print "%s init dbg .... END"%self.classname # do this only once the structure is fine - self.page.record_plugin(self) + if self.page: # I assume we can have a None page (Jordan) + self.page.record_plugin(self) def __repr__ (self): return "[%s]:%s"%(self.classname,self.domid) @@ -157,6 +166,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}) @@ -166,7 +176,6 @@ class Plugin: env.update({'persistent_toggle':False,'display_hide_button':True,'display_show_button':False,'display_body':True}) if self.need_debug(): print "rendering plugin.html with env keys %s"%env.keys() - print "rendering plugin.html with env" for (k,v) in env.items(): if "display" in k or "persistent" in k: print k,'->',v result = render_to_string ('plugin.html',env) @@ -251,7 +260,7 @@ class Plugin: def template_file (self): return "undefined_template" def template_env (self, request): return {} - def default_togglable (self): return True + def default_togglable (self): return False def default_toggled (self): return 'persistent' # # tell the framework about requirements (for the document
)