Skip to content

Commit

Permalink
Take sorting from request in querybuilder not context
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Sep 4, 2017
1 parent af7c51d commit f288e76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/collective/sortedlisting/browser/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def html_results(self, query):
results = self(query, sort_on=self.request.get('sort_on', None),
sort_order=self.request.get('sort_order', None),
limit=10)

return getMultiAdapter(
(results, self.request),
name='sortable_query_results'
Expand All @@ -29,9 +28,9 @@ def _makequery(self, query=None, batch=False, b_start=0, b_size=30,
query, batch=False, b_start=b_start, b_size=b_size,
sort_on=sort_on, sort_order=sort_order, limit=limit,
brains=True, custom_query=custom_query)
sorting = getattr(self.context, 'sorting', [])
sorting = self.request.form.get('sorting', '')
# if sorting is None make it an empty list
sorting = sorting and sorting or []
sorting = isinstance(sorting, basestring) and sorting.split(',') or []
# apply the custom sorting to the resultset according to
# our sorting list
positions = {j: i for i, j in enumerate(sorting)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ define([
if (self.$sortOrder.prop('checked')) {
query.push('sort_order=reverse');
}

var sorting = $("textarea[name$='.sorting']" ).val();
if (sorting !== undefined) {
query.push('sorting=' + sorting.split('\n').join(','));
}

self._previewXhr = $.get(self.options.previewURL + '?' + query.join('&'))
.done(function(data, stat) {
$('<div/>')
Expand All @@ -99,7 +105,7 @@ define([
var uidList = $("#search-results li").map(function() {
return $(this).data("uid");
}).get();
$( "textarea[name$='ISortableCollection.sorting']" ).val( uidList.join("\r\n"))
$( "textarea[name$='.sorting']" ).val( uidList.join("\r\n"))


var dd = new Sortable($('#search-results'), {
Expand Down
9 changes: 6 additions & 3 deletions src/collective/sortedlisting/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class ISortableContentListingTile(contentlisting.IContentListingTile):

class SortableContentListingTile(contentlisting.ContentListingTile):

def contents(self):
"""Search results"""
def get_results(self):
builder = getMultiAdapter(
(self.context, self.request),
name='querybuilderresults'
Expand All @@ -41,8 +40,12 @@ def contents(self):
)
sorting = self.data.get('sorting', '')
positions = {j: i for i, j in enumerate(sorting)}
results = sorted(
return sorted(
results, key=lambda item: positions.get(item.uuid(), 999))

def contents(self):
"""Search results"""
results = self.get_results()
view = self.view_template or 'listing_view'
view = view.encode('utf-8')
options = dict(original_context=self.context)
Expand Down

0 comments on commit f288e76

Please sign in to comment.