Back to index

plone3  3.1.7
ControllerPageTemplateFile.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 """Zope object encapsulating a controlled page templates that comes from the
00015    filesystem.
00016 """
00017 
00018 import os
00019 from AccessControl import ClassSecurityInfo
00020 from Products.CMFCore.permissions import View
00021 from Products.PageTemplates.PageTemplateFile import PageTemplateFile as BaseClass
00022 from Products.PageTemplates.TALES import CompilerError
00023 from BaseControllerPageTemplate import BaseControllerPageTemplate
00024 from FSControllerBase import FSControllerBase
00025 from utils import log, logException
00026 
00027 
00028 class ControllerPageTemplateFile(BaseClass, BaseControllerPageTemplate, FSControllerBase):
00029     """Wrapper for Controller Page Template"""
00030 
00031     meta_type = 'Controller Page Template (File)'
00032 
00033     manage_options=(
00034         ({'label':'Customize', 'action':'manage_main'},
00035          {'label':'Test', 'action':'ZScriptHTML_tryForm'},
00036          {'label':'Validation','action':'manage_formValidatorsForm'},
00037          {'label':'Actions','action':'manage_formActionsForm'},
00038         ))
00039 
00040     security = ClassSecurityInfo()
00041     security.declareObjectProtected(View)
00042 
00043     def __init__(self, filename, _prefix=None, **kw):
00044         filename = os.path.normpath(filename)
00045         if not os.path.splitext(filename)[1]:
00046             filename = filename + '.cpt'
00047         retval = ControllerPageTemplateFile.inheritedAttribute('__init__')(self, filename, _prefix, **kw)
00048 
00049         self.id = os.path.splitext(os.path.basename(filename))[0]
00050         self.filepath = self.filename
00051         try:
00052             self._read_action_metadata(self.getId(), self.filepath)
00053             self._read_validator_metadata(self.getId(), self.filepath)
00054             return retval
00055         except (ValueError, CompilerError), e:
00056             log(summary='metadata error', text='file = %s' % self.filepath)
00057             raise
00058 
00059 
00060     def _updateFromFS(self):
00061         # workaround for Python 2.1 multiple inheritance lameness
00062         return self._baseUpdateFromFS()
00063 
00064     
00065     def _readMetadata(self):
00066         # workaround for Python 2.1 multiple inheritance lameness
00067         return self._baseReadMetadata()
00068 
00069         
00070     def _readFile(self, reparse):
00071         BaseClass._readFile(self, reparse)
00072         self._readMetadata()
00073 
00074 
00075     security.declarePrivate('manage_afterAdd')
00076     def manage_afterAdd(self, object, container):
00077         try:
00078             BaseClass.manage_afterAdd(self, object, container)
00079             # Re-read .metadata after adding so that we can do validation checks
00080             # using information in portal_form_controller.  Since manage_afterAdd
00081             # is not guaranteed to run, we also call these in __init__
00082             self._read_action_metadata(self.getId(), self.filepath)
00083             self._read_validator_metadata(self.getId(), self.filepath)
00084         except:
00085             log(summary='metadata error', text='file = %s' % self.filepath)
00086             logException()
00087             raise
00088 
00089 
00090     def __call__(self, *args, **kwargs):
00091         return self._call(ControllerPageTemplateFile.inheritedAttribute('__call__'), *args, **kwargs)
00092 
00093 
00094     security.declarePublic('writableDefaults')
00095     def writableDefaults(self):
00096         """Can default actions and validators be modified?"""
00097         return 0