Back to index

plone3  3.1.7
FSControllerValidator.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE
00011 #
00012 # THIS FILE CONTAINS MODIFIED CODE FROM ZOPE 2.6.2
00013 ##############################################################################
00014 """ Customizable controlled python scripts that come from the filesystem.
00015 """
00016 
00017 import Globals
00018 from AccessControl import ClassSecurityInfo
00019 from OFS.Cache import Cacheable
00020 from Products.CMFCore.DirectoryView import registerFileExtension, registerMetaType
00021 from Products.CMFCore.permissions import View
00022 from Products.CMFCore.utils import getToolByName
00023 from Script import FSPythonScript as BaseClass
00024 from ControllerValidator import ControllerValidator
00025 from ControllerBase import ControllerBase
00026 from utils import logException
00027 from interfaces import IControllerValidator
00028 
00029 from zope.interface import implements
00030 
00031 class FSControllerValidator (BaseClass, ControllerBase):
00032     """FSControllerValidators act like Controller Python Scripts but are not
00033     directly modifiable from the management interface."""
00034 
00035     meta_type = 'Filesystem Controller Validator'
00036 
00037     implements(IControllerValidator)
00038 
00039     manage_options=(
00040            (
00041             {'label':'Customize', 'action':'manage_main'},
00042             {'label':'Test', 'action':'ZScriptHTML_tryForm'},
00043            ) + Cacheable.manage_options)
00044 
00045     is_validator = 1
00046 
00047     # Use declarative security
00048     security = ClassSecurityInfo()
00049     security.declareObjectProtected(View)
00050 
00051     def __init__(self, id, filepath, fullname=None, properties=None):
00052         BaseClass.__init__(self, id, filepath, fullname, properties)
00053         self.filepath = filepath
00054         self._read_action_metadata(self.getId(), filepath)
00055 
00056 
00057     def __call__(self, *args, **kwargs):
00058         result = FSControllerValidator.inheritedAttribute('__call__')(self, *args, **kwargs)
00059         return result
00060 
00061 
00062     security.declarePrivate('manage_afterAdd')
00063     def manage_afterAdd(self, object, container):
00064         try:
00065             BaseClass.manage_afterAdd(self, object, container)
00066         except:
00067             logException()
00068             raise
00069 
00070 
00071     def _createZODBClone(self):
00072         """Create a ZODB (editable) equivalent of this object."""
00073         obj = ControllerValidator(self.getId())
00074         obj.write(self.read())
00075         return obj
00076 
00077 
00078     security.declarePublic('writableDefaults')
00079     def writableDefaults(self):
00080         """Can default actions and validators be modified?"""
00081         return 0
00082 
00083     def _getState(self):
00084         return getToolByName(self, 'portal_form_controller').getState(self, is_validator=1)
00085 
00086 Globals.InitializeClass(FSControllerValidator)
00087 
00088 registerFileExtension('vpy', FSControllerValidator)
00089 registerMetaType('Controller Validator', FSControllerValidator)