Back to index

plone3  3.1.7
ControllerPageTemplate.py
Go to the documentation of this file.
00001 import os
00002 import Globals
00003 from AccessControl import ClassSecurityInfo
00004 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00005 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate as BaseClass
00006 from Products.CMFCore.permissions import View
00007 from BaseControllerPageTemplate import BaseControllerPageTemplate
00008 from FormAction import FormActionContainer
00009 from FormValidator import FormValidatorContainer
00010 
00011 from urllib import quote
00012 
00013 # ###########################################################################
00014 # Product registration and Add support
00015 manage_addControllerPageTemplateForm = PageTemplateFile('www/cptAdd', globals())
00016 manage_addControllerPageTemplateForm.__name__='manage_addControllerPageTemplateForm'
00017 
00018 
00019 def manage_addControllerPageTemplate(self, id, title=None, text=None,
00020                                     REQUEST=None, submit=None):
00021     """Add a Controller Page Template with optional file content."""
00022 
00023     id = str(id)
00024     if REQUEST is None:
00025         self._setObject(id, ControllerPageTemplate(id, text))
00026         ob = getattr(self, id)
00027         if title:
00028             ob.pt_setTitle(title)
00029         return ob
00030     else:
00031         file = REQUEST.form.get('file')
00032         headers = getattr(file, 'headers', None)
00033         if headers is None or not file.filename:
00034             zpt = ControllerPageTemplate(id)
00035         else:
00036             zpt = ControllerPageTemplate(id, file, headers.get('content_type'))
00037 
00038         self._setObject(id, zpt)
00039 
00040         try:
00041             u = self.DestinationURL()
00042         except AttributeError:
00043             u = REQUEST['URL1']
00044 
00045         if submit == " Add and Edit ":
00046             u = "%s/%s" % (u, quote(id))
00047         REQUEST.RESPONSE.redirect(u+'/manage_main')
00048     return ''
00049 
00050 # ###########################################################################
00051 class ControllerPageTemplate(BaseClass, BaseControllerPageTemplate):
00052 
00053     security = ClassSecurityInfo()
00054     security.declareObjectProtected(View)
00055 
00056     manage_options = (BaseClass.manage_options[:2] + \
00057         ({'label':'Validation',
00058           'action':'manage_formValidatorsForm'},
00059          {'label':'Actions',
00060           'action':'manage_formActionsForm'},) +
00061         BaseClass.manage_options[2:])
00062 
00063     meta_type = 'Controller Page Template'
00064 
00065     _default_content_fn = os.path.join(Globals.package_home(globals()),
00066                                        'www', 'default.html')
00067 
00068     def __init__(self, *args, **kwargs):
00069         self.validators = FormValidatorContainer()
00070         self.actions = FormActionContainer()
00071         return ControllerPageTemplate.inheritedAttribute('__init__')(self, *args, **kwargs)
00072 
00073     def __call__(self, *args, **kwargs):
00074         return self._call(ControllerPageTemplate.inheritedAttribute('__call__'), *args, **kwargs)
00075 
00076     def _notifyOfCopyTo(self, container, op=0):
00077         # BaseClass.inheritedAttribute('notifyOfCopyTo')(self, container, op)
00078         self._base_notifyOfCopyTo(container, op)
00079 
00080     def manage_afterAdd(self, object, container):
00081         BaseClass.inheritedAttribute('manage_afterAdd')(self, object, container)
00082         self._base_manage_afterAdd(object, container)
00083 
00084     def manage_afterClone(self, object):
00085         BaseClass.inheritedAttribute('manage_afterClone')(self, object)
00086         self._base_manage_afterClone(object)
00087 
00088 
00089 Globals.InitializeClass(ControllerPageTemplate)