This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add attribute 'encoding' to rml2pdf directive
- Loading branch information
Dominik Huber
committed
Sep 25, 2007
1 parent
530d11f
commit 963908a
Showing
2 changed files
with
102 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################### | ||
# | ||
# Copyright (c) 2005 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. | ||
# | ||
############################################################################### | ||
"""RML-to-PDF View | ||
$Id$ | ||
""" | ||
__docformat__ = "reStructuredText" | ||
|
||
import cStringIO | ||
from zope.publisher.browser import BrowserPage | ||
from z3c.rml import rml2pdf | ||
|
||
class RML2PDFView(BrowserPage): | ||
|
||
template = None | ||
|
||
def __call__(self): | ||
rml = self.template(self).encode('iso-8859-1') | ||
self.request.response.setHeader('content-type', 'application/pdf') | ||
return rml2pdf.parseString(rml).read() | ||
# -*- coding: utf-8 -*- | ||
############################################################################### | ||
# | ||
# Copyright (c) 2005 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. | ||
# | ||
############################################################################### | ||
"""RML-to-PDF View | ||
$Id$ | ||
""" | ||
__docformat__ = "reStructuredText" | ||
|
||
import cStringIO | ||
from zope.publisher.browser import BrowserPage | ||
from z3c.rml import rml2pdf | ||
|
||
class RML2PDFView(BrowserPage): | ||
|
||
template = None | ||
encoding = u'iso-8859-1' | ||
|
||
def __call__(self): | ||
rml = self.template(self).encode(self.encoding) | ||
self.request.response.setHeader('content-type', 'application/pdf') | ||
return rml2pdf.parseString(rml).read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,69 @@ | ||
############################################################################### | ||
# | ||
# Copyright (c) 2005 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. | ||
# | ||
############################################################################### | ||
"""Directive Handler for several PDF generating presentation components | ||
$Id$ | ||
""" | ||
__docformat__ = "reStructuredText" | ||
|
||
import os.path | ||
|
||
from zope.configuration.exceptions import ConfigurationError | ||
from zope.publisher.interfaces.browser import IDefaultBrowserLayer | ||
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile | ||
from zope.app.publisher.browser.viewmeta import page | ||
from zope.app.publisher.browser.metadirectives import IPageDirective | ||
|
||
from z3c.pdftemplate.rml import RML2PDFView | ||
|
||
|
||
class IRMLToPDFDirective(IPageDirective): | ||
"""A view directive that dynamically evaluates a RML document and converts | ||
it to PDF. | ||
This directive behaves very much like the ``page`` directive, except that | ||
it does not generate HTML, but RML that is rendered to PDF for output. RML | ||
is a simple XML-dialect that creates a storyboard for the reportlab PDF | ||
rendering engine. | ||
""" | ||
|
||
|
||
def rml2pdf(_context, name, permission, for_, template, | ||
layer=IDefaultBrowserLayer, class_=RML2PDFView, | ||
allowed_interface=None, allowed_attributes=None, | ||
menu=None, title=None): | ||
|
||
if class_ is not RML2PDFView and RML2PDFView not in class_.__bases__: | ||
bases = (class_, RML2PDFView) | ||
else: | ||
bases = (class_,) | ||
|
||
factory = type( | ||
'RML2PDFView from template=%s' %(str(template)), | ||
bases, | ||
{'template': ViewPageTemplateFile(template)} | ||
) | ||
|
||
page(_context, name, permission, for_, layer, None, factory, | ||
allowed_interface, allowed_attributes, '__call__', menu, title) | ||
############################################################################### | ||
# | ||
# Copyright (c) 2005 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. | ||
# | ||
############################################################################### | ||
"""Directive Handler for several PDF generating presentation components | ||
$Id$ | ||
""" | ||
__docformat__ = "reStructuredText" | ||
|
||
import os.path | ||
|
||
from zope.configuration.exceptions import ConfigurationError | ||
from zope.publisher.interfaces.browser import IDefaultBrowserLayer | ||
from zope.schema import TextLine | ||
|
||
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile | ||
from zope.app.publisher.browser.metadirectives import IPageDirective | ||
from zope.app.publisher.browser.viewmeta import page | ||
|
||
from z3c.pdftemplate.rml import RML2PDFView | ||
|
||
|
||
class IRMLToPDFDirective(IPageDirective): | ||
"""A view directive that dynamically evaluates a RML document and converts | ||
it to PDF. | ||
This directive behaves very much like the ``page`` directive, except that | ||
it does not generate HTML, but RML that is rendered to PDF for output. RML | ||
is a simple XML-dialect that creates a storyboard for the reportlab PDF | ||
rendering engine. | ||
""" | ||
|
||
encoding = TextLine( | ||
title=u'Encoding', | ||
description=u'Encoding of the template.', | ||
required=False, | ||
default=u'iso-8859-1', | ||
) | ||
|
||
|
||
def rml2pdf(_context, name, permission, for_, template, | ||
layer=IDefaultBrowserLayer, class_=RML2PDFView, | ||
allowed_interface=None, allowed_attributes=None, | ||
menu=None, title=None, encoding=u'iso-8859-1'): | ||
|
||
if class_ is not RML2PDFView and RML2PDFView not in class_.__bases__: | ||
bases = (class_, RML2PDFView) | ||
else: | ||
bases = (class_,) | ||
|
||
factory = type( | ||
'RML2PDFView from template=%s' %(str(template)), | ||
bases, | ||
{'template': ViewPageTemplateFile(template), | ||
'encoding': encoding} | ||
) | ||
|
||
page(_context, name, permission, for_, layer, None, factory, | ||
allowed_interface, allowed_attributes, '__call__', menu, title) |