date range filter
[auf_rh_dae.git] / project / rh / filters.py
index d300996..1a129cd 100644 (file)
@@ -3,6 +3,10 @@
 import datetime
 from django.contrib.admin.filterspecs import FilterSpec
 
+year = datetime.date.today().year
+start = year + 5
+end = year - 5
+
 class DateDebutFieldFilterSpec(FilterSpec):
     def __init__(self, f, request, params, model, model_admin,
                  field_path=None): 
@@ -17,17 +21,16 @@ class DateDebutFieldFilterSpec(FilterSpec):
         today = datetime.date.today()
         self.links = [
             (u"Toutes" ,{}),
-            (u"Cette année", {'%s__gte' % self.field_path: "%s-01-01" % str(today.year), }),
-            (u"Sans valeur" ,{'%s__isnull' % self.field_path: str(True)}),
         ]
-        for i in range(1, 10):
-            t = (today.year-i, {
-                '%s__gte' % self.field_path: "%s-01-01" % str(today.year-i),
+        annees = [i for i in range(start, end, -1)]
+        for i in annees:
+            t = (i, {
+                '%s__gte' % self.field_path: "%s-01-01" % str(i),
                 }) 
             self.links.append(t)
 
     def title(self):
-        return self.field.verbose_name
+        return "Date borne gauche"
 
     def choices(self, cl):
         for title, param_dict in self.links:
@@ -50,18 +53,17 @@ class DateFinFieldFilterSpec(FilterSpec):
                                  if k.startswith(self.field_generic)])
         today = datetime.date.today()
         self.links = [
-            (u"Cette année", {'%s__lte' % self.field_path: "%s-12-31" % str(today.year)}),
             (u"Toutes" ,{}),
-            (u"Sans valeur" ,{'%s__isnull' % self.field_path: str(True)}),
         ]
-        for i in range(1, 10):
-            t = (today.year-i, {
-                '%s__lte' % self.field_path: "%s-12-31" % str(today.year-i),
+        annees = [i for i in range(start, end, -1)]
+        for i in annees:
+            t = (i, {
+                '%s__lte' % self.field_path: "%s-12-31" % str(i),
                 }) 
             self.links.append(t)
 
     def title(self):
-        return self.field.verbose_name
+        return "Date borne droite"
 
     def choices(self, cl):
         for title, param_dict in self.links: