Skip to content

Instantly share code, notes, and snippets.

@simahawk
Created July 12, 2013 07:34
Show Gist options
  • Save simahawk/5982599 to your computer and use it in GitHub Desktop.
Save simahawk/5982599 to your computer and use it in GitHub Desktop.
Plone: extracting catalog query from topic and collection seamlessly
from Products.ATContentTypes.interfaces import IATTopic
from plone.app.collection.interfaces import ICollection
from plone.app.querystring import queryparser
def is_collection(obj):
return IATTopic.providedBy(obj) or ICollection.providedBy(obj)
def parse_new_collection_query(context):
""" given a new collection item returns its catalgo query
"""
parse = queryparser.parseFormquery
return parse(context, context.getRawQuery())
def get_collection_query(obj):
""" return collection's query params
"""
if IATTopic.providedBy(obj):
# old style collection
return obj.buildQuery()
if ICollection.providedBy(obj):
# new style collection
return parse_new_collection_query(obj)
@simahawk
Copy link
Author

Usually I use this to update catalog queries based on context, like: if folderish go with base query, if collection update base query with params from collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment