X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=unfold%2Fplugin.py;h=4fc946abaa2f4447360482e411fadeab18c490bd;hb=40c9be61e737fdee53a3f2ca59a8e8f6dadf3fd1;hp=7ae4745f2cd0b9d79ef33a2b2f8ce6317121f5af;hpb=d685d0cd62cae3d61b49aac84b2437b8950b8373;p=myslice.git diff --git a/unfold/plugin.py b/unfold/plugin.py index 7ae4745f..4fc946ab 100644 --- a/unfold/plugin.py +++ b/unfold/plugin.py @@ -16,8 +16,8 @@ from unfold.prelude import Prelude # . True : to debug all plugin DEBUG= False -DEBUG= [ 'SimpleList' ] -DEBUG=True +#DEBUG= [ 'SimpleList' ] +#DEBUG=True # decorator to deflect calls on Plugin to its Prelude through self.page.prelude def to_prelude (method): @@ -43,10 +43,19 @@ class Plugin: # . page: the context of the request being served # . title: is used visually for displaying the widget #### optional - # . togglable: whether it can be turned on and off (like PleKitToggle) - # . toggled: if togglable, what's the initial status # . visible: if not set the plugin does not show up at all # (not quite sure what this was for) + # . togglable: whether it can be turned on and off by clicking on the title (like PleKitToggle) + # . toggled: whether the plugin should startup open/shown or closed/hidden + #### xxx NOTE : pending move towards a more elaborate mode for 'toggled' + # . toggled: if togglable, what's the initial status; possible values are + # .. True : start up open/hidden + # .. False : start up closed/shown + # .. 'last' : start up as it was the last time that browser showed it (based on 'domid') + # .. None : if not passed to __init__ at all, then the DefaultTaggled() method is called + # .. : anything else, defaults to True + #### xxx NOTE : pending move towards a more elaborate mode for 'toggled' + # #### internal data # . domid: created internally, but can be set at creation time if needed # useful for hand-made css, or for selecting an active plugin in a composite @@ -80,6 +89,9 @@ class Plugin: # do this only once the structure is fine self.page.record_plugin(self) + def __repr__ (self): + return "[%s]:%s"%(self.classname,self.domid) + def _py_classname (self): try: return self.__class__.__name__ except: return 'Plugin' @@ -103,7 +115,7 @@ class Plugin: except: return '%s:"undefined"'%setting else: value=getattr(self,setting,None) - if not value: value = "unknown-setting-%s"%setting + if value is None: value = "unknown-setting-%s"%setting # first try to use to_json method (json.dumps not working on class instances) try: value_json=value.to_json() except: value_json=json.dumps(value,separators=(',',':')) @@ -164,7 +176,12 @@ class Plugin: def render_content (self, request): """Should return an HTML fragment""" template = self.template_file() - env=self.template_env(request) + # start with a fresh one + env={} + # add our own settings as defaults + env.update(self.__dict__) + # then the things explicitly defined in template_env() + env.update(self.template_env(request)) if not isinstance (env,dict): raise Exception, "%s.template_env returns wrong type"%self.classname result=render_to_string (template, env)