+
+
+def prepare_choices_date(field_name, context, 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,
+ 'query_string': get_query_string(request, param_dict, [field_generic]),
+ 'display': title})
+ return result