-
Notifications
You must be signed in to change notification settings - Fork 51
/
pagetemplate.py
45 lines (39 loc) · 1.61 KB
/
pagetemplate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.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.
#
##############################################################################
"""Page Template Support
"""
import zope
from z3c.rml import rml2pdf
try:
import zope.pagetemplate.pagetemplatefile
except ImportError as err:
raise
# zope.pagetemplate package has not been installed
import types
zope.pagetemplate = types.ModuleType('pagetemplate')
zope.pagetemplate.pagetemplatefile = types.ModuleType('pagetemplatefile')
zope.pagetemplate.pagetemplatefile.PageTemplateFile = object
class RMLPageTemplateFile(zope.pagetemplate.pagetemplatefile.PageTemplateFile):
def pt_getContext(self, args=(), options=None, **ignore):
rval = {'template': self,
'args': args,
'nothing': None,
'context': options
}
rval.update(self.pt_getEngine().getBaseNames())
return rval
def __call__(self, *args, **kwargs):
rml = super(RMLPageTemplateFile, self).__call__(*args, **kwargs)
return rml2pdf.parseString(
rml, filename=self.pt_source_file()).getvalue()