Rapport contrats: ajout filtre date début
authorJean-Philippe Caissy <jean-philippe.caissy@auf.org>
Thu, 26 Jan 2012 17:11:25 +0000 (11:11 -0600)
committerJean-Philippe Caissy <jean-philippe.caissy@auf.org>
Thu, 26 Jan 2012 17:11:25 +0000 (11:11 -0600)
project/rh/templates/rh/rapports/contrats.html
project/rh/templatetags/rapports.py

index 4b4f655..177ad7e 100644 (file)
@@ -13,6 +13,7 @@
 {% filter_implantation_contrat %}
 {% filter_type_contrat %}
 {% filter_echeance_contrat %}
+{% filter_debut_contrat %}
 </div>
 
 <table id="result_list">
index 6fc3db8..5ce2ec9 100644 (file)
@@ -51,11 +51,44 @@ def filter_type_contrat(context):
     return {'title': u"type de contrat",
             'choices': prepare_choices(TypeContrat.objects.values_list('id', 'nom'), 'type_contrat', context)}
 
-
 @register.inclusion_tag('admin/filter_select.html', takes_context=True)
 def filter_echeance_contrat(context):
+    today = datetime.date.today()
+    three_months = today + datetime.timedelta(days=3*30)
+    six_months = today + datetime.timedelta(days=6*30)
+    twelve_months = today + datetime.timedelta(days=12*30)
+
+    field_name = 'date_fin'
     return {'title': u"échéance",
-            'choices': prepare_choices_date('date_fin', context)}
+            'choices': prepare_choices_date(field_name, context, links=(
+                ('Tous', {}),
+                ('moins de 3 mois', {'%s__gte' % field_name: today.strftime('%Y-%m-%d'),
+                                    '%s__lte' % field_name: three_months.strftime('%Y-%m-%d')}),
+                ('3 à 6 mois', {'%s__gte' % field_name: three_months.strftime('%Y-%m-%d'),
+                                '%s__lte' % field_name: six_months.strftime('%Y-%m-%d')}),
+                ('6 à 12 mois', {'%s__gte' % field_name: six_months.strftime('%Y-%m-%d'),
+                                '%s__lte' % field_name: twelve_months.strftime('%Y-%m-%d')}),
+            )
+    )}
+
+@register.inclusion_tag('admin/filter_select.html', takes_context=True)
+def filter_debut_contrat(context):
+    year = datetime.date.today().timetuple()[0]
+    this_year = datetime.date(year, 1, 1)
+    next_year = datetime.date(year + 1, 1, 1)
+    last_year = datetime.date(year - 1, 12,31)
+
+    field_name = 'date_debut'
+    return {'title': u"date début",
+            'choices': prepare_choices_date(field_name, context, links=(
+                ('Tous', {}),
+                ('anées à venirs', {'%s__gte' % field_name: next_year.strftime('%Y-%m-%d')}),
+                ('cette anneée', {'%s__gte' % field_name: this_year.strftime('%Y-%m-%d'),
+                                '%s__lt' % field_name: next_year.strftime('%Y-%m-%d')}),
+                ('ans passés', {'%s__lte' % field_name: last_year.strftime('%Y-%m-%d')}),
+            )
+    )}
+
 
 
 @register.inclusion_tag('admin/filter_select.html', takes_context=True)
@@ -100,28 +133,14 @@ def prepare_choices(choices, query_param, context, remove=[]):
     return result
 
 
-def prepare_choices_date(field_name, context, remove=[]):
+def prepare_choices_date(field_name, context, links, remove=[]):
     request = context['request']
     params = request.GET
     field_generic = '%s__' % field_name
     date_params = dict([(k, v) for k, v in params.items() if k.startswith(field_generic)])
 
 
-    today = datetime.date.today()
-    three_months = today + datetime.timedelta(days=3*30)
-    six_months = today + datetime.timedelta(days=6*30)
-    twelve_months = today + datetime.timedelta(days=12*30)
-
-    links = (
-        ('Tous', {}),
-        ('moins de 3 mois', {'%s__gte' % field_name: today.strftime('%Y-%m-%d'),
-                             '%s__lte' % field_name: three_months.strftime('%Y-%m-%d')}),
-        ('3 à 6 mois', {'%s__gte' % field_name: three_months.strftime('%Y-%m-%d'),
-                        '%s__lte' % field_name: six_months.strftime('%Y-%m-%d')}),
-        ('6 à 12 mois', {'%s__gte' % field_name: six_months.strftime('%Y-%m-%d'),
-                         '%s__lte' % field_name: twelve_months.strftime('%Y-%m-%d')}),
-    )
-
+    
     result = []
     for title, param_dict in links:
         result.append({'selected': date_params == param_dict,