[ home | blog home | recent activity ]
Some plugins can do all their functionality in one callback and don't have any need to store state. These are your simple plugins that do things like count how many words there are in an entry and then store that number in the entry object's properties. More complex plugins do some stuff in one callback, then need to store their state, and do some other things in another callback.
In PyBlosxom 0.8 and prior, you could do this by storing the state in global variables on the plugin module like this:
state = {}
def cb_date_head(args):
global state
if state.has_key(...):
...
def cb_filelist(args):
global state
...
state["blah"] = "blahblah"
This is "ok" for previous versions of PyBlosxom. In future versions (post 0.8), this is not ok and the official way to maintain state is to store state information on the Request object in the data dict using a unique key:
STATE_KEY = "myplugin_state"
def cb_date_head(args):
request = args["request"]
data = request.getData()
if data.has_key(STATE_KEY) and data[STATE_KEY]["blah"] == "blahblah":
...
def cb_filelist(args):
request = args["request"]
data = request.getData()
data[STATE_KEY] = {}
data[STATE_KEY]["blah"] = "blahblah"
changelog
Comments:
Post a new comment:
Three things:
If you can't for some reason post a comment, send me an email: willg at bluesock dot org.
pyblosxom::1.5-dev git-master
Copyright 1996 to 2012, Will Guaraldi Kahn-Greene, under the Creative Commons BY-SA 3.0 license

Will's Blog by William Kahn-Greene is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.