I would like to make context sensitive help support in my intranet app. There are two elements that define this help system:
1. Context - created by appending /help at the end of current (RESTful) path.
2. Help text - KID files from myproj/templates/help directory tree. Template files are located by matching parts from context path to files from help directory.
For example, for context "/cc/kampanja/1/show/help", following files and/or directories will be searched for:
- templates/help/cc/kampanja/1/show.kid
- templates/help/cc/kampanja/1/show/index.kid
- templates/help/cc/kampanja/1/show/
- templates/help/cc/kampanja/1.kid
- templates/help/cc/kampanja/1/index.kid
- templates/help/cc/kampanja/1/
- templates/help/cc/kampanja.kid
- templates/help/cc/kampanja/index.kid
- templates/help/cc/kampanja/
- templates/help/cc.kid
- templates/help/cc/index.kid
- templates/help/cc/
- templates/help/index.kid
- templates/help/
First one that is found is being served. If system finds directory instead of file then a directory listing is automatically created and returned.
This way I can write most specific help file to the given task the user is performing by simply creating the file in the appropriate location within templates/help tree.
Currently I have a function that I call from all my default() handlers and from help() handler found inside every controller like this:
class KampanjaControler(controllers.Controller):
@turbogears.expose
()
@identity.require(identity.in_group("user"))
def help(self, *vpath, **kw):
return context_sensitive_help()
@turbogears.expose(html=".templates.kampanja")
@
identity.require(identity.in_group("user"))
def default(self, *vpath, **kw):
if vpath and vpath[-1].lower()=='help':
return context_sensitive_help()
...
Simplified version of context_sensitive_help() function looks like this:
base = r'D:\OZ\Projects\ccleads\ccleads\templates\help'
def context_sensitive_help():
parts = cherrypy.request.path.strip(r"\/").split("/")
if parts and parts[-1]=='help':
parts.pop(-1)
while parts:
# Find file ...
req = os.path.join(base, *parts)
if os.path.exists(req + '.kid'):
template = ".templates.help." + (".".join(parts))
return dict(tg_template = template, **get_page_params(base, parts))
# ... or directory
elif os.path.isdir(req):
# Served by explicit index file
if os.path.exists
(os.path.join(req, 'index.kid')):
template = ".templates.help." + (".".join(parts+['index']))
return dict(tg_template = template, **get_page_params(base, parts))
# Served by dynamically generated index file
else:
return dict(tg_template = ".templates.help._index", **get_index_params(base, parts))
parts.pop(-1)
# Served by dynamically generated index file
return dict(tg_template = ".templates.help._index", **get_index_params(base))
My "solution" requires sprinkling of my controller code with context_sensitive_help() calls which I really don't like.
I would like to turn this into CherryPy Filter but don't know how. It should be enough to just install it as _cp_filter on my root controller and that it processes all requests ending with "/help" and returns processed KID template.
Thanks,
Tvrtko
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---
- [TurboGears] Context sensitive help support via CP filter Qvx

