Skip to content
Permalink
Browse files

acquire query from parent if parent is a folderish collection

  • Loading branch information...
pbauer committed Dec 29, 2014
1 parent c4cb5fd commit 366cc1a911c81954645ec6aabce925df4a297c63
@@ -4,6 +4,7 @@
as BaseCollectionFeed
from Products.CMFPlone.interfaces.syndication import IFeed
from Products.CMFPlone.interfaces.syndication import ISyndicatable
from Products.Five import BrowserView
from plone.app.contentlisting.interfaces import IContentListing
from plone.app.contenttypes import _
from plone.autoform.interfaces import IFormFieldProvider
@@ -48,6 +49,14 @@ class ICollection(model.Schema):
missing_value=''
)

acquire_query = schema.Bool(
title=_(u'Inherit search terms'),
description=_(u"If the parent is also a collection inherit it's "
u"search terms and extend/override with current ones. "
u"The preview is not affected by this."),
required=False,
)

sort_on = schema.TextLine(
title=_(u'label_sort_on', default=u'Sort on'),
description=_(u"Sort the collection on this index"),
@@ -136,8 +145,17 @@ def results(self, batch=True, b_start=0, b_size=None,
'v': '/',
})

# Add the current query to the parent's query, so that the
# current overrides the parent (if they query for the same
# parameters).
finalquery = query
if getattr(self, 'acquire_query', False):
parent = self.context.__parent__
if ISyndicatableCollection.providedBy(parent):
finalquery = parent.query + query

return querybuilder(
query=query, batch=batch, b_start=b_start, b_size=b_size,
query=finalquery, batch=batch, b_start=b_start, b_size=b_size,
sort_on=sort_on, sort_order=sort_order,
limit=limit, brains=brains, custom_query=custom_query
)
@@ -236,9 +254,24 @@ def _get_customViewFields(self):

customViewFields = property(_get_customViewFields, _set_customViewFields)

def _set_acquire_query(self, value):
self.context.acquire_query = value

def _get_acquire_query(self):
return getattr(self.context, 'acquire_query', False)

acquire_query = property(_get_acquire_query, _set_acquire_query)


@implementer(IFeed)
class CollectionFeed(BaseCollectionFeed):

def _brains(self):
return ICollection(self.context).results(batch=False)[:self.limit]


class SubCollectionHelper(BrowserView):

def __call__(self):
if ISyndicatableCollection.providedBy(self.context.__parent__):
return True
@@ -59,6 +59,13 @@
template="richtext_gettext.pt"
/>

<browser:page
name="is_subcollection"
for=".collection.ISyndicatableCollection"
class=".collection.SubCollectionHelper"
permission="zope2.View"
/>

<utility
component=".collection.MetaDataFieldsVocabularyFactory"
name="plone.app.contenttypes.metadatafields" />
@@ -0,0 +1,16 @@
$(document).ready(function () {

// Hide field 'acquire_query' when parent is no collection

var jq_acquire_query, ajax_url, response;

jq_acquire_query = $('#formfield-form-widgets-ICollection-acquire_query');
if (jq_acquire_query.length && (document.URL.search('/edit') !== -1)) {
ajax_url = document.URL.split('/edit')[0];
ajax_url = ajax_url + '/@@is_subcollection';
response = $.ajax({'url': ajax_url});
if (response.responseText !== "True") {
jq_acquire_query.hide();
}
}
});
@@ -11,6 +11,10 @@
name="collection.css"
file="stylesheets/collection.css" />

<browser:resource
name="plone.app.contenttypes.collection.js"
file="collection.js" />


<!-- VIEWS FOR COLLECTION ITEM -->

@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<object name="portal_javascripts" meta_type="JavaScripts Registry">

<javascript cacheable="True" compression="safe" cookable="True"
enabled="True" inline="False" expression=""
id="++resource++plone.app.contenttypes.collection.js"
/>

</object>

0 comments on commit 366cc1a

Please sign in to comment.
You can’t perform that action at this time.