Commits

Luke Plant committed c067e99

Pulled out auto_ranges function

  • Participants
  • Parent commits a70e4a2

Comments (0)

Files changed (2)

File django_easyfilters/filters.py

 from django.utils.dates import MONTHS
 from django.utils.text import capfirst
 from django_easyfilters.queries import date_aggregation, value_counts, numeric_range_counts
+from django_easyfilters.ranges import auto_ranges
 
 try:
     from collections import namedtuple
             if self.ranges is None:
                 val_range = qs.aggregate(lower=models.Min(self.field),
                                          upper=models.Max(self.field))
-                lower = val_range['lower']
-                upper = val_range['upper']
-
-                # TODO - round to produce nice looking ranges.
-                step = (upper - lower)/self.max_links
-                ranges = [(lower + step * i, lower + step * (i+1)) for i in xrange(self.max_links)]
+                ranges = auto_ranges(val_range['lower'], val_range['upper'], self.max_links)
             else:
                 ranges = self.ranges
 

File django_easyfilters/ranges.py

+
+
+def auto_ranges(lower, upper, max_items):
+    # TODO - round to produce nice looking ranges.
+    step = (upper - lower)/max_items
+    ranges = [(lower + step * i, lower + step * (i+1)) for i in xrange(max_items)]
+    return ranges