Export excel (or csv) from filtered collection (collective.collectionfilter)

Plone 5.2: Is it possible to export csv of a collection filter 'search', for example with collective.exelexport or similar.

In other words, I want to

  1. Filter a collection
  2. Export all fields of every content item 'visible'.

(all will be the same content type)

So what did you try/test before posting this question? Did you install both add'ons and check if they interact? Did you take a peek at their documentation and/or source code?

I could not find anything in the docs, but faceted navigation is mentioned (but I find that a bit of overkill for my use case).

PS: I don't have the opportunity to test to much, since I am stuck with just an old laptop (and an operated foot), but if this is possible I will wait with some part of the migration (of an old site) to later (and do changes in Excel, then reimport instead of what I am doing now, editing one and one content item)

Why don't you just write a view for collectionfilter that writes the resulting list to a dict that contains the attributes you need. Then pass that dict to a .pt view template that writes the csv.

Example template that takes some parameters, used from a BrowserView:

<tal:def tal:define="dummy python:context.REQUEST.response.setHeader('Content-Type', 'text/plain;; charset=' \
                                        + context.plone_utils.getSiteEncoding());
                     dl_name string:${options/filename};
                     dummy python:context.REQUEST.response.setHeader('Content-Disposition', 'attachment;; filename=' \
                                                + dl_name);
                     items options/data | nothing;
                     header_type options/header_type | string:default;
                     fields options/fields | nothing;
                     labels options/labels | nothing;
                     field_separator options/field_separator | string:;;;
                     quote_character options/quote_character | string:&quot;;"
    ><tal:outer tal:repeat="item items"
        ><tal:start tal:condition="repeat/item/start"
            ><tal:labels tal:condition="python: header_type in ('labels', 'extended')"
                ><tal:heading tal:content="python:field_separator.join(labels)" />
</tal:labels><tal:fields tal:condition="python: header_type in ('default', 'extended')"
                ><tal:heading tal:content="python:field_separator.join(fields)" />
</tal:fields></tal:start><tal:inner tal:repeat="col python:fields"><tal:content
                                        tal:content="quote_character" /><tal:content
                                            tal:content="structure python:col in item.keys() and item[col] or ''"/><tal:content
                                                tal:content="quote_character" /><tal:separator
                                                    tal:condition="not:repeat/col/end" tal:content="field_separator"/></tal:inner>
</tal:outer
></tal:def>

2 Likes