Permalink
Browse files

Add support for context-aware vs. naive field distributions

  • Loading branch information...
1 parent 1632f5a commit 0d157076ba4c961ba13605cbaa56cc713cd1bdc7 @bruth bruth committed May 9, 2013
Showing with 11 additions and 2 deletions.
  1. +11 −2 serrano/resources/field/dist.py
View
13 serrano/resources/field/dist.py
@@ -15,6 +15,7 @@
class FieldDistParametizer(Parametizer):
+ aware = False
nulls = False
sort = None
cluster = True
@@ -24,6 +25,9 @@ class FieldDistParametizer(Parametizer):
aggregates = None
relative = None
+ def clean_aware(self, value):
+ return param_cleaners.clean_bool(value)
+
def clean_nulls(self, value):
return param_cleaners.clean_bool(value)
@@ -52,8 +56,13 @@ def get(self, request, pk):
tree = trees[instance.model]
- # Get the appropriate data context
- context = self.get_context(request)
+ # The `aware` flag toggles the behavior of the distribution by making
+ # 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()
# Explicit fields to group by, ignore ones that dont exist or the

0 comments on commit 0d15707

Please sign in to comment.