Created
July 12, 2013 07:34
-
-
Save simahawk/5982599 to your computer and use it in GitHub Desktop.
Plone: extracting catalog query from topic and collection seamlessly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.