[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ZPTPage - ZPTPage.py:1.1.2.1 ZPTPage.pyc:1.1.2.1 ZPTPageEdit.py:1.1.2.1 ZPTPageEdit.pyc:1.1.2.1 ZPTPageEval.py:1.1.2.1 ZPTPageEval.pyc:1.1.2.1 __init__.py:1.1.2.1 __init__.pyc:1.1.2.1 edit.pt:1.1.2.1
Stephan Richter
srichter@cbu.edu
Mon, 21 Jan 2002 17:00:51 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ZPTPage
In directory cvs.zope.org:/tmp/cvs-serv23517
Added Files:
Tag: Zope-3x-branch
ZPTPage.py ZPTPage.pyc ZPTPageEdit.py ZPTPageEdit.pyc
ZPTPageEval.py ZPTPageEval.pyc __init__.py __init__.pyc
edit.pt
Log Message:
- Add a very simple ZPT Page as content object. It does not do security
yet, so someone should look at it.
- Also, even though I have tested the code via the Web, there are no unit
tests yet; I will provide them later.
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.py ===
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
from Interface import Interface
from Persistence import Persistent
from Zope.PageTemplate.PageTemplate import PageTemplate
from Zope.App.Security.IAttributeRolePermissionManageable \
import IAttributeRolePermissionManageable
class IZPTPage(Interface):
"""ZPT Pages are a persistent implementation of Page Templates.
Note: I introduced some new methods whose functionality is
actually already covered by some other methods but I
want to start inforcing a common coding standard.
"""
def setSource(text):
"""Save the source of the page template.
"""
def getSource():
"""Get the source of the page template.
"""
class ZPTPage(Persistent, PageTemplate):
""" """
__implements__ = IZPTPage
def __init__(self, text=''):
""" """
self.setSource(text)
############################################################
# Implementation methods for interface
# Zope.App.OFS.ZPTPage.ZPTPage.IZPTPage
def getSource(self):
'''See interface IZPTPage'''
return self.read()
def setSource(self, text):
'''See interface IZPTPage'''
self.pt_edit(text, 'text/html')
#
############################################################
_need__name__=1
_v_last_read = 0
_default_bindings = {'name_subpath': 'traverse_subpath'}
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.pyc ===
-í
īK<c s| d k l Z d k l Z
d k l Z d k l Z d e f d YZ " d e e f d YZ d S( ( s Interface( s
Persistent( s PageTemplate( s" IAttributeRolePermissionManageables IZPTPagec s& d Z d Z d Z RS( s ZPT Pages are a persistent implementation of Page Templates.
Note: I introduced some new methods whose functionality is
actually already covered by some other methods but I
want to start inforcing a common coding standard.
c s
d S( s. Save the source of the page template.
N( ( s text( ( s5 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.pys setSource s c s
d S( s- Get the source of the page template.
N( ( ( ( s5 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.pys getSource s ( s __doc__s setSources getSource( ( ( s5 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.pys IZPTPage s s ZPTPagec sb " d Z # % e Z ( d d Z 1 d Z 6 d Z = d Z > d Z @ h d d <Z RS( s s c s ( ) * | i | d S( s N( s selfs setSources text( s selfs text( ( s5 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.pys __init__( s c s 1 2 3 | i Sd S( s See interface IZPTPageN( s selfs read( s self( ( s5 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.pys getSource1 s c s 6 7 8 | i | d d S( s See interface IZPTPages text/htmlN( s selfs pt_edits text( s selfs text( ( s5 /opt/Zope3/lib/python/Zope/A!
pp/OFS/ZPTPage/ZPTPage.pys setSource6 s i i s traverse_subpaths name_subpath( s __doc__s IZPTPages __implements__s __init__s getSources setSources
_need__name__s _v_last_reads _default_bindings( ( ( s5 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.pys ZPTPage" s N( s Interfaces Persistences
Persistents Zope.PageTemplate.PageTemplates PageTemplates4 Zope.App.Security.IAttributeRolePermissionManageables" IAttributeRolePermissionManageables IZPTPages ZPTPage( s" IAttributeRolePermissionManageables Interfaces IZPTPages ZPTPages
Persistents PageTemplate( ( s5 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPage.pys ? s
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEdit.py ===
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
"""
Define view component for ZPT page editing.
"""
from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
from Zope.PageTemplate.PageTemplateFile import PageTemplateFile
class ZPTPageEdit( AttributePublisher ):
__implements__ = AttributePublisher.__implements__
def __init__( self, zptpage ):
self._zptpage = zptpage
def editAction(self, source, REQUEST=None):
zptpage = self.getContext()
zptpage.setSource(source)
if REQUEST is not None:
return self.index(REQUEST, msg='ZPT Page Edited.')
def getContext( self ):
return self._zptpage
index = PageTemplateFile('edit.pt')
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEdit.pyc ===
-í
ÂK<c sI d Z
d k l Z
d k l Z d e f d YZ d S( s1
Define view component for ZPT page editing.
( s AttributePublisher( s PageTemplateFiles ZPTPageEditc sG e i Z d Z e d Z d Z # e d Z RS( Nc s | | _ d S( N( s zptpages selfs _zptpage( s selfs zptpage( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEdit.pys __init__ s c sP | i } | i | | t j o | i | d d Sn d S( Ns msgs ZPT Page Edited.( s selfs
getContexts zptpages setSources sources REQUESTs Nones index( s selfs sources REQUESTs zptpage( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEdit.pys
editAction s c s ! | i Sd S( N( s selfs _zptpage( s self( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEdit.pys
getContext s s edit.pt( s AttributePublishers __implements__s __init__s Nones
editActions
getContexts PageTemplateFiles index( ( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEdit.pys ZPTPageEdit s
N( s __doc__s) Zope.Publisher.Browser.AttributePublishers AttributePublishers" Zope.PageTemplate.PageTemplateFiles PageTemplateFiles ZPTPageEdit( s AttributePublishers ZPTPageEdits PageTemplateFile( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEdit.pys ?
s
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.py ===
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
"""
Define view component for ZPT page eval results.
"""
from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
from Zope.PageTemplate.Expressions import SecureModuleImporter
class ZPTPageEval( AttributePublisher ):
__implements__ = AttributePublisher.__implements__
def __init__( self, zptpage ):
self._zptpage = zptpage
def getContext( self ):
return self._zptpage
def pt_getContext(self, inst=None, REQUEST=None):
#root = self.getPhysicalRoot()
c = {'template': self.getContext(),
'nothing': None,
#XXX 'root': root,
'modules': SecureModuleImporter,
}
if inst is not None:
c['here'] = inst.getContext()
c['container'] = inst
c['views'] = ViewMapper(inst.getContext(), REQUEST)
return c
def index(self, inst=None, REQUEST=None, **kw):
"""Call a Page Template"""
bound_names = {}
bound_names.update(self.pt_getContext(inst, REQUEST))
bound_names['options'] = kw
bound_names['request'] = REQUEST
try:
self.REQUEST.RESPONSE.setHeader('content-type',
self.getContect.content_type)
except AttributeError:
pass
# Execute the template in a new security context.
self.getContext()._cook()
return self.getContext().pt_render(extra_context=bound_names)
def document_src(self, REQUEST=None, RESPONSE=None):
"""Return expanded document source."""
if RESPONSE is not None:
RESPONSE.setHeader('Content-Type', self.content_type)
return self.read()
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.pyc ===
-í
ūģK<c sI d Z
d k l Z
d k l Z d e f d YZ d S( s6
Define view component for ZPT page eval results.
( s AttributePublisher( s SecureModuleImporters ZPTPageEvalc s_ e i Z d Z d Z e e d Z * e e d Z < e e d Z RS( Nc s | | _ d S( N( s zptpages selfs _zptpage( s selfs zptpage( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.pys __init__ s c s | i Sd S( N( s selfs _zptpage( s self( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.pys
getContext s c s h | i d <t d <t d <} # | t j o@ $ | i | d <% | | d <& t | i | | d <n ' | Sd S( Ns templates nothings moduless heres containers views( s selfs
getContexts Nones SecureModuleImporters cs insts
ViewMappers REQUEST( s selfs insts REQUESTs c( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.pys
pt_getContext s *
c sš * + , h } - | i | i | | . | | d </ | | d <1 y& 2 | i i i d 3 | i i
Wn 4 t j
o
5 n X8 | i i
9 | i i d | Sd S( s Call a Page Templates optionss requests content-types
extra_contextN( s bound_namess updates selfs
pt_getContexts insts REQUESTs kws RESPONSEs setHeaders
getContects content_types AttributeErrors
getContexts _cooks pt_render( s selfs insts REQUESTs kws bound_names( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.pys index* s
c sA < = ? | t j o @ | i d | i n A | i Sd S( s Return expanded document source.s Content-TypeN( s RESPONSEs Nones setHeaders selfs content_types read( s selfs REQUESTs RESPONSE( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.pys document_src< s ( s AttributePublishers __implements__s __init__s
getContexts Nones
pt_getContexts indexs document_src( ( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.pys ZPTPageEval s N( s __doc__s) Zope.Publisher.Browser.AttributePublishers AttributePublishers Zope.PageTemplate.Expressionss SecureModuleImporters ZPTPageEval( s SecureModuleImporters AttributePublishers ZPTPageEval( ( s9 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/ZPTPageEval.pys ?
s
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/__init__.py ===
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/__init__.pyc ===
-í
EaK<c s d S( N( ( ( ( s6 /opt/Zope3/lib/python/Zope/App/OFS/ZPTPage/__init__.pys ? s
=== Added File Zope3/lib/python/Zope/App/OFS/ZPTPage/edit.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="headers" type="text/css">
<!--
.ContentIcon {
width: 20px;
}
.ContentTitle {
text-align: left;
}
-->
</style>
</head>
<body>
<div metal:fill-slot="body">
<p tal:content="options/msg | nothing">
Message will go here.
</p>
<form action="editAction" method="post" enctype="multipart/form-data">
<table class="EditTable">
<tbody>
<tr>
<th class="EditAttributeName">Source</th>
<td class="EditAttributeValue">
<textarea name="source" cols="80" rows="10"
tal:content="here/getSource">Source</textarea>
</td>
</tr>
</tbody>
</table>
<input type="submit" name="edit" value="Save Changes">
</form>
</div>
</body>
</html>