a pass on quickfilter, at least it displays something related to the input 'criterias'
[unfold.git] / engine / plugin.py
index 92bbe6c..8f817a5 100644 (file)
@@ -6,7 +6,7 @@ import json
 
 from django.template.loader import render_to_string
 
-from engine.pluginset import PluginSet
+from engine.page import Page
 from engine.prelude import Prelude
 
 #################### 
@@ -16,13 +16,13 @@ from engine.prelude import Prelude
 # . True : to debug all plugin
 
 DEBUG= False
-#DEBUG= [ 'SimpleList' ]
+DEBUG= [ 'QuickFilter' ]
 
-# decorator to deflect calls on Plugin to its PluginSet
+# decorator to deflect calls on Plugin to its Prelude through self.page.prelude
 def to_prelude (method):
     def actual (self, *args, **kwds):
         prelude_method=Prelude.__dict__[method.__name__]
-        return prelude_method(self.pluginset.prelude,*args, **kwds)
+        return prelude_method(self.page.prelude,*args, **kwds)
     return actual
 
 class Plugin:
@@ -39,7 +39,7 @@ class Plugin:
     ########## 
     # Constructor
     #### mandatory
-    # . pluginset: the context of the request being served
+    # . 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)
@@ -55,10 +55,11 @@ class Plugin:
     # p=Plugin(foo='bar')
     # which will result in 'foo' being accessible to the template engine
     # 
-    def __init__ (self, pluginset, title, domid=None,
+    def __init__ (self, page, title, domid=None,
                   visible=True, togglable=True, toggled=True, **settings):
-        self.pluginset = pluginset
+        self.page = page
         self.title=title
+        # callers can provide their domid for css'ing 
         if not domid: domid=Plugin.newdomid()
         self.domid=domid
         self.classname=self._py_classname()
@@ -76,7 +77,7 @@ 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.pluginset.record_plugin(self)
+        self.page.record_plugin(self)
 
     def _py_classname (self): 
         try:    return self.__class__.__name__
@@ -116,6 +117,15 @@ class Plugin:
         result += "}"
         return result
 
+    # as a first approximation, only plugins that are associated with a query
+    # need to be prepared for js - meaning their json settings get exposed to js
+    # others just get displayed and that's it
+    def export_json_settings (self):
+        return 'query' in self.__dict__
+    
+    def start_with_spin (self):
+        return self.export_json_settings()
+
     # returns the html code for that plugin
     # in essence, wraps the results of self.render_content ()
     def render (self, request):
@@ -124,12 +134,13 @@ class Plugin:
         # shove this into plugin.html
         env = {}
         env ['plugin_content']= plugin_content
+        # need_spin is used in plugin.html
+        self.need_spin=self.start_with_spin()
         env.update(self.__dict__)
         result = render_to_string ('plugin.html',env)
 
-        # as a first approximation we're only concerned with plugins that are associated with a query
-        # other simpler plugins that only deal with layout do not need this
-        if 'query' in self.__dict__:
+        # export this only for relevant plugins
+        if self.export_json_settings():
             env ['settings_json' ] = self.settings_json()
             # compute plugin-specific initialization
             js_init = render_to_string ( 'plugin-setenv.js', env )
@@ -166,9 +177,10 @@ class Plugin:
             for (k,v) in d.iteritems():
                 if self.need_debug():
                     print "%s: handling requirement %s"%(self.classname,v)
+                # e.g. js_files -> add_js_files
                 method_name='add_'+k
-                method=PluginSet.__dict__[method_name]
-                method(self.pluginset,v)
+                method=Page.__dict__[method_name]
+                method(self.page,v)
         except AttributeError: 
             # most likely the object does not have that method defined, which is fine
             pass
@@ -178,7 +190,7 @@ class Plugin:
             pass
 
     #################### requirements/prelude management
-    # just forward to self.pluginset - see decorator above
+    # just forward to our prelude instance - see decorator above
     @to_prelude
     def add_js_files (self):pass
     @to_prelude
@@ -226,5 +238,13 @@ class Plugin:
     # also 'query_uuid' gets replaced with query.uuid
     def json_settings_list (self): return ['json_settings_list-must-be-redefined']
 
-    # might also define this one; see e.g. slicelist.py that piggybacks simplelist js code
-    # def plugin_classname (self):
+    # might also define these ones:
+    #
+    # see e.g. slicelist.py that piggybacks simplelist js code
+    # def plugin_classname (self)
+    #
+    # whether we export the json settings to js
+    # def export_json_settings (self)
+    #
+    # whether we show an initial spinner
+    # def start_with_spin (self)