[SOLVED] Collection and contentFilter with querystring

Hi all,
as mentioned in source code of plone.app.contettypes (1.4.9)

I want to manipulate the results of a Collection with querystring.
Reading the sourcecode wrote before I'm trying to instruct the url in this way to obtain the results filtered by portal_type


but nothing happens.
What's wrong?

The code tells you that the contentFilter in the request is supposed to be some kind of mapping. To turn the querystring part contentFilter.portal_type=Folder into a mapping, you must use the ZPublisher conversion specifier :record. This would give you the querystring contentFilter.portal_type:record=Folder.

In general, :record is applied to names of the form var.key and tells ZPublisher that it should construct a record object (a kind of mapping) bound in the request to var and to give key the value in this request parameter definition. There are a lot of other ZPublisher conversion specifiers.

you have to use the custom_query parameter; this is what I'm using on a custom view for a collection:

def results(self, b_size=5, b_start=0):
    """Apply a custom query over the collection results."""
    custom_query = {}
    b_start = int(b_start)

    text = self.request.form.get('SearchableText', '')
    if text:
        custom_query['SearchableText'] = quote_chars(text)

    created = self.request.form.get('created', {})
    if self.valid_period(created):
        custom_query['created'] = created

    sort_on = self.request.form.get('sort_on', '')
    if sort_on not in ('', 'Date', 'sortable_title'):
        sort_on = ''
    sort_order = 'reverse' if sort_on == 'Date' else 'ascending'
    custom_query['sort_order'] = sort_order

    results = self.context.results(
    return results

my custom view let you apply some filters to the collection results.

1 Like

Thanks to all.

You can edit the post and add [SOLVED] to it's title.