Back to index

plone3  3.1.7
demoregistry.py
Go to the documentation of this file.
00001 # Copyright (c) 2005-2007
00002 # Authors: KSS Project Contributors (see docs/CREDITS.txt)
00003 #
00004 # This program is free software; you can redistribute it and/or modify
00005 # it under the terms of the GNU General Public License version 2 as published
00006 # by the Free Software Foundation.
00007 #
00008 # This program is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 # GNU General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU General Public License
00014 # along with this program; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00016 # 02111-1307, USA.
00017 
00018 
00019 from kss.core.plugins.core.demo.zopeconfig import KSSCoreDemos
00020 from reStructuredText import HTML
00021 from zope.dottedname.resolve import resolve
00022 from kss.core import KSSView
00023 
00024 class DemoRegistry(KSSView):
00025 
00026     def getDemo(self, viewname):
00027         kssdemos = KSSCoreDemos().demos
00028         for demo in kssdemos:
00029             if demo.page_url==viewname + '.html':
00030                 return demo
00031         return None
00032 
00033     def getHTMLHelp(self, viewname):
00034         demo = self.getDemo(viewname)
00035         packagePath = self.getPackagePath(viewname)
00036         helpfile = demo.helpfile
00037         if not packagePath or not helpfile:
00038             return ''
00039         file = open(packagePath + '/' + helpfile)
00040         rtext = file.read()
00041         file.close()
00042         html = HTML(rtext)
00043         return html
00044 
00045     def getPackagePath(self, viewname):
00046         demo = self.getDemo(viewname)
00047         packageName = demo.packageName
00048         if not packageName:
00049             return None
00050         module = resolve(packageName)
00051         packagePath = '/'.join(module.__file__.split('/')[:-1])
00052         return packagePath
00053 
00054     def displayHelp(self, viewname):
00055         html = '<h1>Description</h1><div>%s</div>' % self.getHTMLHelp(viewname)
00056         self.getCommandSet('core').replaceInnerHTML('div#help', html)
00057         self.getCommandSet('core').addClass('a#displayHelp', 'hidden')
00058         self.getCommandSet('core').removeClass('a#hideHelp', 'hidden')
00059         return self.render()
00060 
00061     def hideHelp(self):
00062         self.getCommandSet('core').replaceInnerHTML('div#help', '')
00063         self.getCommandSet('core').removeClass('a#displayHelp', 'hidden')
00064         self.getCommandSet('core').addClass('a#hideHelp', 'hidden')
00065         return self.render()