Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge branch 'postatum-99829616_acl_filtering_aggs' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoiko committed Sep 11, 2015
2 parents 22927ce + 777285f commit ceb136b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions nefertari/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ def set_override_rendered(self):
elif 'text/plain' in self.request.accept:
self.request.override_renderer = 'string'

def _setup_aggregation(self):
def _setup_aggregation(self, aggregator=None):
""" Wrap `self.index` method with ESAggregator.
This makes `self.index` to first try to run aggregation and only
on fail original method is run. Method is wrapped only if it is
defined and `elasticsearch.enable_aggregations` setting is true.
"""
from nefertari.elasticsearch import ES
if aggregator is None:
aggregator = ESAggregator
aggregations_enabled = (
ES.settings and ES.settings.asbool('enable_aggregations'))
if not aggregations_enabled:
Expand All @@ -183,7 +185,7 @@ def _setup_aggregation(self):
index = getattr(self, 'index', None)
index_defined = index and index != self.not_allowed_action
if index_defined:
self.index = ESAggregator(self).wrap(self.index)
self.index = aggregator(self).wrap(self.index)

def get_collection_es(self):
""" Query ES collection and return results.
Expand Down
2 changes: 1 addition & 1 deletion nefertari/view_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def wrap(self, func):
Should be called with view instance methods.
"""
six.wraps(func)
@six.wraps(func)
def wrapper(*args, **kwargs):
try:
return self.aggregate()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_view_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def view_aggregations_keys_used(self):

def test_wrap(self):
view = self.DemoView()
view.index = Mock()
view.index = Mock(__name__='foo')
aggregator = ESAggregator(view)
aggregator.aggregate = Mock(side_effect=KeyError)
func = aggregator.wrap(view.index)
Expand Down

0 comments on commit ceb136b

Please sign in to comment.