git://git.onelab.eu
/
unfold.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rename pluginset into page
[unfold.git]
/
engine
/
plugin.py
diff --git
a/engine/plugin.py
b/engine/plugin.py
index
00b37b7
..
5d39216
100644
(file)
--- a/
engine/plugin.py
+++ b/
engine/plugin.py
@@
-6,7
+6,7
@@
import json
from django.template.loader import render_to_string
from django.template.loader import render_to_string
-from engine.p
luginset import PluginSet
+from engine.p
age import Page
from engine.prelude import Prelude
####################
from engine.prelude import Prelude
####################
@@
-16,13
+16,13
@@
from engine.prelude import Prelude
# . True : to debug all plugin
DEBUG= False
# . True : to debug all plugin
DEBUG= False
-#DEBUG= [ 'S
impl
eList' ]
+#DEBUG= [ 'S
lic
eList' ]
-# decorator to deflect calls on Plugin to its P
luginSet
+# decorator to deflect calls on Plugin to its P
relude through self.page.prelude
def to_prelude (method):
def actual (self, *args, **kwds):
prelude_method=Prelude.__dict__[method.__name__]
def to_prelude (method):
def actual (self, *args, **kwds):
prelude_method=Prelude.__dict__[method.__name__]
- return prelude_method(self.p
luginset
.prelude,*args, **kwds)
+ return prelude_method(self.p
age
.prelude,*args, **kwds)
return actual
class Plugin:
return actual
class Plugin:
@@
-39,7
+39,7
@@
class Plugin:
##########
# Constructor
#### mandatory
##########
# Constructor
#### mandatory
- # . p
luginset
: the context of the request being served
+ # . p
age
: 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)
# . title: is used visually for displaying the widget
#### optional
# . togglable: whether it can be turned on and off (like PleKitToggle)
@@
-55,13
+55,15
@@
class Plugin:
# p=Plugin(foo='bar')
# which will result in 'foo' being accessible to the template engine
#
# p=Plugin(foo='bar')
# which will result in 'foo' being accessible to the template engine
#
- def __init__ (self, p
luginset
, title, domid=None,
+ def __init__ (self, p
age
, title, domid=None,
visible=True, togglable=True, toggled=True, **settings):
visible=True, togglable=True, toggled=True, **settings):
- self.p
luginset = pluginset
+ self.p
age = page
self.title=title
self.title=title
+ # callers can provide their domid for css'ing
if not domid: domid=Plugin.newdomid()
self.domid=domid
if not domid: domid=Plugin.newdomid()
self.domid=domid
- self.classname=self._classname()
+ self.classname=self._py_classname()
+ self.plugin_classname=self._js_classname()
self.visible=visible
self.togglable=togglable
self.toggled=toggled
self.visible=visible
self.togglable=togglable
self.toggled=toggled
@@
-75,12
+77,16
@@
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
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.p
luginset
.record_plugin(self)
+ self.p
age
.record_plugin(self)
- def _classname (self):
+ def _
py_
classname (self):
try: return self.__class__.__name__
except: return 'Plugin'
try: return self.__class__.__name__
except: return 'Plugin'
+ def _js_classname (self):
+ try: return self.plugin_classname ()
+ except: return self._py_classname()
+
##########
def need_debug (self):
if not DEBUG: return False
##########
def need_debug (self):
if not DEBUG: return False
@@
-111,6
+117,11
@@
class Plugin:
result += "}"
return result
result += "}"
return result
+ # as a first approximation, only plugins that are associated with a query
+ # need to be prepared for js - others just get displayed and that's it
+ def is_asynchroneous (self):
+ return 'query' in self.__dict__
+
# returns the html code for that plugin
# in essence, wraps the results of self.render_content ()
def render (self, request):
# returns the html code for that plugin
# in essence, wraps the results of self.render_content ()
def render (self, request):
@@
-122,9
+133,8
@@
class Plugin:
env.update(self.__dict__)
result = render_to_string ('plugin.html',env)
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.is_asynchroneous():
env ['settings_json' ] = self.settings_json()
# compute plugin-specific initialization
js_init = render_to_string ( 'plugin-setenv.js', env )
env ['settings_json' ] = self.settings_json()
# compute plugin-specific initialization
js_init = render_to_string ( 'plugin-setenv.js', env )
@@
-162,8
+172,8
@@
class Plugin:
if self.need_debug():
print "%s: handling requirement %s"%(self.classname,v)
method_name='add_'+k
if self.need_debug():
print "%s: handling requirement %s"%(self.classname,v)
method_name='add_'+k
- method=P
luginSet
.__dict__[method_name]
- method(self.p
luginset
,v)
+ method=P
age
.__dict__[method_name]
+ method(self.p
age
,v)
except AttributeError:
# most likely the object does not have that method defined, which is fine
pass
except AttributeError:
# most likely the object does not have that method defined, which is fine
pass
@@
-173,7
+183,7
@@
class Plugin:
pass
#################### requirements/prelude management
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
@to_prelude
def add_js_files (self):pass
@to_prelude
@@
-221,3
+231,5
@@
class Plugin:
# also 'query_uuid' gets replaced with query.uuid
def json_settings_list (self): return ['json_settings_list-must-be-redefined']
# 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):