Back to index

plone3  3.1.7
ttwapi.py
Go to the documentation of this file.
00001 from zope.app.component.hooks import getSite, setSite
00002 from zope import event
00003 from zope.app.publication.zopepublication import BeforeTraverseEvent
00004 
00005 from kss.core import KSSView
00006 from kss.core.interfaces import IKSSView
00007 from kss.core.unicode_quirks import force_unicode
00008 
00009 def startKSSCommands(context, request):
00010     view = KSSView(context, request)
00011     # Alec suggested we should fire the BeforeTraverseEvent, but after
00012     # debugging for a while I stopped caring about the event and think
00013     # that setSite() is the only thing we're interested in.
00014     setSite(view)
00015     return view
00016 
00017 def getKSSCommandSet(name):
00018     view = retrieveView()
00019     cs = view.getCommandSet(name)
00020     return cs
00021 
00022 def renderKSSCommands():
00023     view = retrieveView()
00024     return view.render()
00025 
00026 def retrieveView():
00027     #because the view registers itself as a site,
00028     #we can retrieve it...
00029     site = getSite()
00030     if not IKSSView.providedBy(site):
00031         raise LookupError(
00032             "You haven't initialized the KSS response yet, "
00033             "do so by calling startKSSCommands(context, request).")
00034     return site
00035 
00036