Skip to content

Commit

Permalink
Merge pull request #82 from 4teamwork/lk_zipexport_integration
Browse files Browse the repository at this point in the history
Added ftw.zipexport integration.
  • Loading branch information
jone committed Apr 9, 2015
2 parents 22c8aaa + 6ffe57a commit 99ceb00
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/HISTORY.txt
Expand Up @@ -5,7 +5,8 @@ Changelog
3.1.1 (unreleased)
------------------

- Nothing changed yet.
- Added ftw.zipexport integration.
[lknoepfel]


3.1.0 (2015-03-19)
Expand Down
3 changes: 3 additions & 0 deletions ftw/book/configure.zcml
Expand Up @@ -84,4 +84,7 @@
<implements interface="ftw.book.interfaces.ILaTeXCodeInjectionEnabled" />
</class>

<configure zcml:condition="installed ftw.zipexport">
<adapter factory=".zipexport.BookZipRepresentation" />
</configure>
</configure>
2 changes: 2 additions & 0 deletions ftw/book/testing.py
Expand Up @@ -79,11 +79,13 @@ def setUpZope(self, app, configurationContext):
z2.installProduct(app, 'ftw.book')
z2.installProduct(app, 'simplelayout.base')
z2.installProduct(app, 'ftw.contentpage')
z2.installProduct(app, 'ftw.zipexport')

def setUpPloneSite(self, portal):
# Install into Plone site using portal_setup
applyProfile(portal, 'ftw.book:default')
applyProfile(portal, 'ftw.tabbedview:default')
applyProfile(portal, 'ftw.zipexport:default')

setRoles(portal, TEST_USER_ID, ['Manager'])
login(portal, TEST_USER_NAME)
Expand Down
33 changes: 33 additions & 0 deletions ftw/book/tests/test_zipexport.py
@@ -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())
23 changes: 23 additions & 0 deletions ftw/book/zipexport.py
@@ -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()))
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -14,6 +14,7 @@
'ftw.tabbedview',
'ftw.testbrowser',
'ftw.testing',
'ftw.zipexport',
'mocker',
'plone.app.testing',
'plone.browserlayer',
Expand Down

0 comments on commit 99ceb00

Please sign in to comment.