Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: FileSystem representation #43

Open
mtrebron opened this issue May 12, 2017 · 0 comments
Open

Enhancement: FileSystem representation #43

mtrebron opened this issue May 12, 2017 · 0 comments

Comments

@mtrebron
Copy link

I have a use case where pdf files on the filesystem need to be zipped:

browser/configure.zcml

    <adapter factory=".filesystem.FileZipRepresentation" />

interfaces.py

    enabled_dotted_names = schema.List(
        title=u"Interface dotted-names on which zipexport is enabled.",
        default=[u"Products.CMFCore.interfaces._content.IContentish"
               , u"Products.CMFCore.interfaces._tools.IDirectoryView"],
        value_type=schema.TextLine())

representations/filesystem.py

from ftw.zipexport.representations.general import NullZipRepresentation
from OFS.interfaces import IItem
from StringIO import StringIO
from Products.CMFPlone.utils import safe_unicode
from zope.component import adapts
from zope.interface import implements
from zope.interface import Interface


class FileZipRepresentation(NullZipRepresentation):
    """
    filesystem zip export implementation
    note, todo: returns img src link for image, not image itself
    """
    implements(IZipRepresentation)
    adapts(IItem, Interface)

    def __init__(self, context, request):
        self.context = context
        self.request = request

    def get_files(self, path_prefix=u"", recursive=True, toplevel=True):
        filename = safe_unicode(self.context.getId() or self.context.id)
        yield self.get_file_tuple(filename, path_prefix)

    def get_file_tuple(self, filename, path_prefix):
        path = u'{0}/{1}'.format(safe_unicode(path_prefix),
                                 safe_unicode(filename))
        stream_data = StringIO(self.context)
        return (path, stream_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant