Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from 4teamwork/lk_zipexport_integration
Added ftw.zipexport integration.
- Loading branch information
Showing
6 changed files
with
64 additions
and
1 deletion.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from ftw.book.testing import FTW_BOOK_FUNCTIONAL_TESTING | ||
from ftw.builder import Builder | ||
from ftw.builder import create | ||
from ftw.testbrowser import browsing | ||
from unittest2 import TestCase | ||
from zipfile import ZipFile | ||
from StringIO import StringIO | ||
|
||
|
||
class TestBookZipexport(TestCase): | ||
|
||
layer = FTW_BOOK_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
self.book = create(Builder('book').titled('The Book')) | ||
chapter = create(Builder('chapter').titled('First Chapter') | ||
.within(self.book)) | ||
subchapter = create(Builder('chapter').titled('The SubChapter') | ||
.within(chapter)) | ||
create(Builder('book textblock').titled('Hidden Title Block') | ||
.having(showTitle=False).within(subchapter)) | ||
create(Builder('book textblock').titled('Visible Title Block') | ||
.having(showTitle=True).within(subchapter)) | ||
create(Builder('chapter').titled('Second Chapter').within(self.book)) | ||
|
||
@browsing | ||
def test_zipexport_integration(self, browser): | ||
browser.login().visit(self.book, view='zip_export') | ||
|
||
self.assertEquals('application/zip', browser.headers['Content-Type']) | ||
|
||
zipfile = ZipFile(StringIO(browser.contents)) | ||
self.assertEquals(['the-book.pdf'], zipfile.namelist()) |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from ftw.book.interfaces import IBook | ||
from ftw.pdfgenerator.interfaces import IPDFAssembler | ||
from ftw.zipexport.interfaces import IZipRepresentation | ||
from ftw.zipexport.representations.general import NullZipRepresentation | ||
from StringIO import StringIO | ||
from zope.component import adapts | ||
from zope.component import getMultiAdapter | ||
from zope.interface import implements | ||
from zope.interface import Interface | ||
|
||
|
||
class BookZipRepresentation(NullZipRepresentation): | ||
implements(IZipRepresentation) | ||
adapts(IBook, Interface) | ||
|
||
def get_files(self, path_prefix=u"", recursive=True, toplevel=True): | ||
filename = u'{0}.pdf'.format(self.context.getId()) | ||
|
||
assembler = getMultiAdapter((self.context, self.request), | ||
IPDFAssembler) | ||
|
||
yield (u'{0}/{1}'.format(path_prefix, filename), | ||
StringIO(assembler.build_pdf())) |
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