from django.utils.translation import ugettext_lazy as _
from django_filters import CharFilter

from geotrek.common.filters import StructureRelatedFilterSet, YearFilter, ValueFilter
from geotrek.infrastructure.widgets import InfrastructureYearSelect, InfrastructureImplantationYearSelect
from .models import Infrastructure


class InfrastructureFilterSet(StructureRelatedFilterSet):
    name = CharFilter(label=_('Name'), lookup_expr='icontains')
    description = CharFilter(label=_('Description'), lookup_expr='icontains')
    implantation_year = ValueFilter(name='implantation_year',
                                    widget=InfrastructureImplantationYearSelect)
    intervention_year = YearFilter(name='interventions_set__date',
                                   widget=InfrastructureYearSelect)

    def __init__(self, *args, **kwargs):
        super(InfrastructureFilterSet, self).__init__(*args, **kwargs)

        field = self.form.fields['type__type']
        all_choices = [field.widget.choices]
        all_choices = field.widget.choices
        all_choices = [c for c in all_choices]

    class Meta(StructureRelatedFilterSet.Meta):
        model = Infrastructure
        fields = StructureRelatedFilterSet.Meta.fields + ['type__type', 'type', 'condition', 'implantation_year',
                                                          'intervention_year', 'published']

@@ -978,17 +978,21 @@
 oices = 
-%5B
+list(
 field.wi
@@ -1003,25 +1003,25 @@
 .choices
-%5D
+)
 %0A       
  all_cho
@@ -1012,30 +1012,16 @@
 %0A       
- all_choices =
  field.w
@@ -1037,42 +1037,35 @@
 ices
-%0A        all_choices = %5Bc for c in
+ = %5B('', _(u%22Category%22))%5D +
  all
@@ -1072,16 +1072,19 @@
 _choices
+%5B1:
 %5D%0A%0A    c

Fix filter label