4teamwork / ftw.zipexport

Zip Export for Plone
2 stars 6 forks source link

How to correctly support both Archetypes and Dexterity based setups? #47

Open hvelarde opened 6 years ago

hvelarde commented 6 years ago

I'm working on adding support for Dextrity-based content types to one package that uses yours as a dependency.

I'm almost there but I found an issue with the ZipGenerator class as it seems to select the Archetypes implementation by mistake:

$ bin/test --layer=\!Robot
Running sc.photogallery.testing.sc.photogallery:Integration tests:
  Set up plone.testing.zca.LayerCleanup in 0.000 seconds.
  Set up plone.testing.z2.Startup in 0.157 seconds.
  Set up plone.app.testing.layers.PloneFixture in 6.334 seconds.
  Set up plone.app.event.testing.PAEventLayer in 1.392 seconds.
  Set up plone.app.contenttypes.testing.PloneAppContenttypes in 1.599 seconds.
  Set up sc.photogallery.testing.Fixture in 3.147 seconds.
  Set up sc.photogallery.testing.sc.photogallery:Integration in 0.000 seconds.
  Running:
    48/53 (90.6%)> /home/hvelarde/collective/sc.photogallery/src/sc/photogallery/browser/view.py(103)_zip_size()
-> size = os.stat(zip_file.name).st_size
(Pdb) zip_file.name
'/tmp/plone_zipexport_MVc4Gj'
(Pdb) repre
<ftw.zipexport.representations.archetypes.FolderZipRepresentation object at 0x7fb4df119cd0>
(Pdb) 

our source code is here:

https://github.com/collective/sc.photogallery/blob/1.0b1/src/sc/photogallery/browser/view.py#L87-L100

can you give me a hint on how to solve this?

maethu commented 6 years ago

@hvelarde It looks like a adapter register problem:

For folderish Archetypes content we register it for Products.CMFCore.interfaces.IFolderish --> https://github.com/4teamwork/ftw.zipexport/blob/master/ftw/zipexport/representations/archetypes.py#L18

And if DX is available we register it also for plone.dexterity.interfaces.IDexterityItem --> https://github.com/4teamwork/ftw.zipexport/blob/master/ftw/zipexport/representations/dexterity.py#L22

Your type is folderish an a dexterityitem, looks like IFolderish wins.

I guess the easiest way for now is to register a more specific adapter using the IPhotoGallery interface

hvelarde commented 6 years ago

mmm, seems we have a different problem: the views for this content type are not registered correctly; we are using the class instead of the interface:

<browser:page zcml:condition="installed ftw.zipexport"
    for="sc.photogallery.content.PhotoGallery"
    name="zip"
    class=".ZipView"
    permission="zope2.View"
    layer="sc.photogallery.interfaces.IBrowserLayer"
    />

I'll test and let you know.

CC @rodfersou

hvelarde commented 6 years ago

@maethu it didn't work, so we probably need to register the multi-adapter indeed; I'll close this once we fix the issue to leave it as documentation, thanks!