+ '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', {}),
+ ('années à venir', {
+ '%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')
+ }),
+ ('années passées', {
+ '%s__lte' % field_name: last_year.strftime('%Y-%m-%d')
+ }),
+ )
+ )}
+
+
+@register.inclusion_tag('admin/filter_select.html', takes_context=True)
+def filter_a_venir(context):
+ today = datetime.date.today()
+ year, month, day = datetime.date.today().timetuple()[:3]
+ mois_prochain = datetime.date(
+ year + (month + 1) / 13, (month + 1) % 12, 1
+ )
+ this_month = datetime.date(year, month, 1)
+
+ field_name = 'date_debut'
+ return {'title': u"à venir",
+ 'choices': prepare_choices_date(field_name, context, links=(
+ ('Tous', {}),
+ ('à venir', {
+ '%s__gt' % field_name: today.strftime('%Y-%m-%d')
+ }),
+ ('à venir mois prochain', {
+ '%s__gte' % field_name: mois_prochain.strftime('%Y-%m-%d')
+ }),
+ ('à venir ce mois', {
+ '%s__gte' % field_name: this_month.strftime('%Y-%m-%d'),
+ '%s__lt' % field_name: mois_prochain.strftime('%Y-%m-%d')
+ }),
+ )
+ )}