Skip to content
This repository
Browse code

Add support for context-aware vs. naive field distributions

  • Loading branch information...
commit 0d157076ba4c961ba13605cbaa56cc713cd1bdc7 1 parent 1632f5a
Byron Ruth authored May 09, 2013

Showing 1 changed file with 11 additions and 2 deletions. Show diff stats Hide diff stats

  1. 13  serrano/resources/field/dist.py
13  serrano/resources/field/dist.py
@@ -15,6 +15,7 @@
15 15
 
16 16
 
17 17
 class FieldDistParametizer(Parametizer):
  18
+    aware = False
18 19
     nulls = False
19 20
     sort = None
20 21
     cluster = True
@@ -24,6 +25,9 @@ class FieldDistParametizer(Parametizer):
24 25
     aggregates = None
25 26
     relative = None
26 27
 
  28
+    def clean_aware(self, value):
  29
+        return param_cleaners.clean_bool(value)
  30
+
27 31
     def clean_nulls(self, value):
28 32
         return param_cleaners.clean_bool(value)
29 33
 
@@ -52,8 +56,13 @@ def get(self, request, pk):
52 56
 
53 57
         tree = trees[instance.model]
54 58
 
55  
-        # Get the appropriate data context
56  
-        context = self.get_context(request)
  59
+        # The `aware` flag toggles the behavior of the distribution by making
  60
+        # relative to the applied context or none
  61
+        if params['aware']:
  62
+            context = self.get_context(request)
  63
+        else:
  64
+            context = self.get_context(request, attrs={})
  65
+
57 66
         queryset = context.apply(tree=tree).distinct()
58 67
 
59 68
         # Explicit fields to group by, ignore ones that dont exist or the

0 notes on commit 0d15707

Please sign in to comment.
Something went wrong with that request. Please try again.