Back to index

plone3  3.1.7
FSControllerPageTemplate.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 validated page templates that come from the filesystem.
00015 """
00016 
00017 import copy
00018 from zope.tales.tales import CompilerError
00019 
00020 import Globals, Acquisition
00021 from AccessControl import ClassSecurityInfo
00022 from OFS.Cache import Cacheable
00023 from Products.PageTemplates.ZopePageTemplate import Src
00024 from Products.CMFCore.DirectoryView import registerFileExtension, registerMetaType
00025 from Products.CMFCore.permissions import View
00026 from Products.CMFCore.FSPageTemplate import FSPageTemplate as BaseClass
00027 from BaseControllerPageTemplate import BaseControllerPageTemplate
00028 from ControllerPageTemplate import ControllerPageTemplate
00029 from FSControllerBase import FSControllerBase
00030 from utils import log, logException
00031 
00032 class FSControllerPageTemplate(FSControllerBase, BaseClass, BaseControllerPageTemplate):
00033     """Wrapper for Controller Page Template"""
00034 
00035     meta_type = 'Filesystem Controller Page Template'
00036 
00037     manage_options=(
00038         ({'label':'Customize', 'action':'manage_main'},
00039          {'label':'Test', 'action':'ZScriptHTML_tryForm'},
00040          {'label':'Validation','action':'manage_formValidatorsForm'},
00041          {'label':'Actions','action':'manage_formActionsForm'},
00042         ) + Cacheable.manage_options)
00043 
00044     security = ClassSecurityInfo()
00045     security.declareObjectProtected(View)
00046 
00047 
00048     def __init__(self, id, filepath, fullname=None, properties=None):
00049         BaseClass.__init__(self, id, filepath, fullname, properties)
00050         self.filepath = filepath
00051         try:
00052             self._read_action_metadata(self.getId(), filepath)
00053             self._read_validator_metadata(self.getId(), filepath)
00054         except (ValueError, CompilerError), e:
00055             log(summary='metadata error', text='file = %s' % filepath)
00056             raise
00057 
00058         
00059     def _updateFromFS(self):
00060         # workaround for Python 2.1 multiple inheritance lameness
00061         return self._baseUpdateFromFS()
00062 
00063     
00064     def _readMetadata(self):
00065         # workaround for Python 2.1 multiple inheritance lameness
00066         return self._baseReadMetadata()
00067 
00068 
00069     def _readFile(self, reparse):
00070         BaseClass._readFile(self, reparse)
00071         self._readMetadata()
00072 
00073 
00074     security.declarePrivate('manage_afterAdd')
00075     def manage_afterAdd(self, object, container):
00076         try:
00077             BaseClass.manage_afterAdd(self, object, container)
00078             # Re-read .metadata after adding so that we can do validation checks
00079             # using information in portal_form_controller.  Since manage_afterAdd
00080             # is not guaranteed to run, we also call these in __init__
00081             self._read_action_metadata(self.getId(), self.filepath)
00082             self._read_validator_metadata(self.getId(), self.filepath)
00083         except:
00084             log(summary='metadata error', text='file = %s' % self.filepath)
00085             logException()
00086             raise
00087 
00088 
00089     def __call__(self, *args, **kwargs):
00090         return self._call(FSControllerPageTemplate.inheritedAttribute('__call__'), *args, **kwargs)
00091 
00092 
00093     def _createZODBClone(self):
00094         """Create a ZODB (editable) equivalent of this object."""
00095         obj = ControllerPageTemplate(self.getId(), self._text, self.content_type)
00096         obj.expand = 0
00097         obj.write(self.read())
00098         obj.validators = copy.copy(Acquisition.aq_base(self.validators))
00099         obj.actions = copy.copy(Acquisition.aq_base(self.actions))
00100         return obj
00101 
00102 
00103     security.declarePublic('writableDefaults')
00104     def writableDefaults(self):
00105         """Can default actions and validators be modified?"""
00106         return 0
00107 
00108 _s = Src()
00109 
00110 setattr(FSControllerPageTemplate, 'source.xml', _s)
00111 setattr(FSControllerPageTemplate, 'source.html', _s)
00112 
00113 del _s
00114 
00115 Globals.InitializeClass(FSControllerPageTemplate)
00116 
00117 registerFileExtension('cpt', FSControllerPageTemplate)
00118 registerMetaType('Controller Page Template', FSControllerPageTemplate)