The PEAK Developers' Center   attachment:zpttest.py of ZopePageTemplates UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View

Attachment 'zpttest.py'

from peak.api import *
from peak.web.api import *

from zope.pagetemplate.pagetemplate import PageTemplate
from zope.pagetemplate.pagetemplatefile import PageTemplateFile

# This adapter does care about security at all yet
class PageTemplateAsWebMethod(protocols.Adapter):

    """Make PageTemplates play nicely with peak.web"""

    protocols.advise(
        instancesProvide = [IWebPage],
        asAdapterForTypes = [PageTemplate, PageTemplateFile]
        )

    def render(self, context):
        request = context.interaction.request
        try:
            obj = self.subject
            ctx = obj.pt_getContext(request.getPositionalArguments())
            ctx['request'] = request
            ctx['template'] = obj
            ctx['app'] = context.interaction.app
            # XXX more context elements ??

            data = obj.pt_render(ctx)
            ret = data.encode('utf-8')
        except Exception, e:
            ret = str(e)
        return ret



class ZPTTestApp(binding.Component):

    security.allow(
        index_html = [security.Anybody]
        )


    index_html = PageTemplateFile('index.zpt')

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to upload files.


PythonPowered
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck