Back to index

plone3  3.1.7
commandinspector.py
Go to the documentation of this file.
00001 # Copyright (c) 2006-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 from zope.interface import implements
00019 from kss.core.interfaces import IKSSCommandView
00020 
00021 class CommandInspectorView(object):
00022     '''Inspector view of a command.
00023     
00024     This enables debugging checks. Returns commands
00025     as a list of dicts.
00026 
00027     Look at the tests to see what checks this makes possible.
00028     '''
00029     implements(IKSSCommandView)
00030 
00031     def __init__(self, context, request):
00032         self.context = context
00033         self.request = request
00034 
00035         # Force parameters content to be unicode
00036         for command in context:
00037             for param in command.getParams():
00038                 param.force_content_unicode()
00039     
00040     def render(self):
00041         result = []
00042         for command in self.context:
00043             d = dict(command.__dict__)
00044             # params are converted to a dict from a list.
00045             # Also get rid of "none" params that were only a hack for xml
00046             d['params'] = dict([(param.name, param.content) for param in d['params'] if param.name != 'none'])
00047             result.append(d)
00048         return result