~sidnei/zope3/ztk-1.0a1

« back to all changes in this revision

Viewing changes to src/zope/app/dtmlpage/dtmlpage.py

  • Committer: Sidnei da Silva
  • Date: 2010-03-03 03:29:50 UTC
  • mfrom: (12.1.16 trunk)
  • Revision ID: sidnei.da.silva@canonical.com-20100303032950-duivfaoqsxaf9dgg
Merged newer-from-ztk [r=jkakar,bigkevmcd,free][qa=andreas][f=522474].

Update our monolithic Zope 3 tree to a kgs-based, generated,
monolithic Zope 3 tree built from eggs using the
collective.buildout.omelette recipe.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
4
 
# All Rights Reserved.
5
 
#
6
 
# This software is subject to the provisions of the Zope Public License,
7
 
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
 
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
 
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
 
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
 
# FOR A PARTICULAR PURPOSE.
12
 
#
13
 
##############################################################################
14
 
"""DTML Page content component
15
 
 
16
 
$Id: dtmlpage.py 67630 2006-04-27 00:54:03Z jim $
17
 
"""
18
 
__docformat__ = 'restructuredtext'
19
 
 
20
 
from persistent import Persistent
21
 
 
22
 
from zope.documenttemplate.untrusted import UntrustedHTML
23
 
from zope.interface import implements
24
 
from zope.annotation.interfaces import IAnnotatable
25
 
from zope.filerepresentation.interfaces import IFileFactory
26
 
 
27
 
from zope.app.container.contained import Contained
28
 
from zope.app.publication.interfaces import IFileContent
29
 
 
30
 
from interfaces import IDTMLPage, IRenderDTMLPage
31
 
 
32
 
class DTMLPage(Persistent, Contained):
33
 
    implements(IDTMLPage, IRenderDTMLPage, IFileContent, IAnnotatable)
34
 
 
35
 
    def __init__(self, source=''):
36
 
        self.setSource(source)
37
 
 
38
 
    def getSource(self):
39
 
        '''See interface `IDTMLPage`'''
40
 
        return self.template.read()
41
 
 
42
 
    def setSource(self, text, content_type='text/html'):
43
 
        '''See interface `IDTMLPage`'''
44
 
        self.template = UntrustedHTML(text)
45
 
        self.content_type = content_type
46
 
 
47
 
    def render(self, request, *args, **kw):
48
 
        """See interface `IDTMLRenderPage`"""
49
 
        return self.template(self.__parent__, request, REQUEST=request, **kw)
50
 
 
51
 
 
52
 
    __call__ = render
53
 
 
54
 
    source = property(getSource, setSource, None,
55
 
                      """Source of the DTML Page.""")
56
 
 
57
 
class DTMLFactory(object):
58
 
    implements(IFileFactory)
59
 
 
60
 
    def __init__(self, context):
61
 
        self.context = context
62
 
 
63
 
    def __call__(self, name, content_type, data):
64
 
        r = DTMLPage()
65
 
        r.setSource(data, content_type or 'text/html')
66
 
        return r