Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Commit

Permalink
Add support for context-aware vs. naive field distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
bruth committed May 9, 2013
1 parent 1632f5a commit 0d15707
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions serrano/resources/field/dist.py
Expand Up @@ -15,6 +15,7 @@




class FieldDistParametizer(Parametizer): class FieldDistParametizer(Parametizer):
aware = False
nulls = False nulls = False
sort = None sort = None
cluster = True cluster = True
Expand All @@ -24,6 +25,9 @@ class FieldDistParametizer(Parametizer):
aggregates = None aggregates = None
relative = None relative = None


def clean_aware(self, value):
return param_cleaners.clean_bool(value)

def clean_nulls(self, value): def clean_nulls(self, value):
return param_cleaners.clean_bool(value) return param_cleaners.clean_bool(value)


Expand Down Expand Up @@ -52,8 +56,13 @@ def get(self, request, pk):


tree = trees[instance.model] tree = trees[instance.model]


# Get the appropriate data context # The `aware` flag toggles the behavior of the distribution by making
context = self.get_context(request) # relative to the applied context or none
if params['aware']:
context = self.get_context(request)
else:
context = self.get_context(request, attrs={})

queryset = context.apply(tree=tree).distinct() queryset = context.apply(tree=tree).distinct()


# Explicit fields to group by, ignore ones that dont exist or the # Explicit fields to group by, ignore ones that dont exist or the
Expand Down

0 comments on commit 0d15707

Please sign in to comment.