prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Bug affichage intervention selon niveau de zoom
  Bonjour, sur la 2.49.0 selon le niveau de zoom sélectionné, certaines interventions apparaissent et disparaissent. Faire glisser la carte provoque aussi ce comportement :
  
  
  https://user-images.githubusercontent.com/45095227/108825316-2719b200-75c3-11eb-8406-11d57bcd2531.mov
  
  J'en profite pour dire que je n'ai pas pu changer l'opacité des linéaires pour qu'ils soient plus visibles ( voir : https://github.com/GeotrekCE/Geotrek-admin/issues/2554)
  
  </issue>
  <code>
  [start of geotrek/maintenance/filters.py]
  1 from django.db.models import Q
  2 from django.conf import settings
  3 from django.contrib.contenttypes.models import ContentType
  4 from django.utils.translation import gettext_lazy as _
  5 from django_filters import ChoiceFilter, MultipleChoiceFilter
  6 
  7 from mapentity.filters import PolygonFilter, PythonPolygonFilter
  8 
  9 from geotrek.core.models import Topology
  10 from geotrek.authent.filters import StructureRelatedFilterSet
  11 from geotrek.common.filters import RightFilter
  12 from geotrek.zoning.filters import ZoningFilterSet
  13 from geotrek.zoning.models import City, District
  14 
  15 from .models import Intervention, Project
  16 
  17 if 'geotrek.signage' in settings.INSTALLED_APPS:
  18     from geotrek.signage.models import Blade
  19 
  20 
  21 class PolygonInterventionFilterMixin(object):
  22     def get_geom(self, value):
  23         return value
  24 
  25     def filter(self, qs, values):
  26         if not values:
  27             return qs
  28         lookup = self.lookup_expr
  29 
  30         blade_content_type = ContentType.objects.get_for_model(Blade)
  31         topologies = []
  32         for value in values:
  33             topologies += Topology.objects.filter(**{'geom__%s' % lookup: self.get_geom(value)}).values_list('id', flat=True)
  34         topologies_intervention = Intervention.objects.existing().filter(target_id__in=topologies).exclude(
  35             target_type=blade_content_type).distinct('pk').values_list('id', flat=True)
  36 
  37         interventions = list(topologies_intervention)
  38         if 'geotrek.signage' in settings.INSTALLED_APPS:
  39             blades = list(Blade.objects.filter(signage__in=topologies).values_list('id', flat=True))
  40             blades_intervention = Intervention.objects.existing().filter(target_id__in=blades,
  41                                                                          target_type=blade_content_type).values_list('id',
  42                                                                                                                      flat=True)
  43             interventions.extend(blades_intervention)
  44         if hasattr(self, 'lookup_queryset_in'):
  45             lookup_queryset = self.lookup_queryset_in
  46         else:
  47             lookup_queryset = 'pk__in'
  48         qs = qs.filter(**{'%s' % lookup_queryset: interventions})
  49         return qs
  50 
  51 
  52 class PolygonTopologyFilter(PolygonInterventionFilterMixin, PolygonFilter):
  53     pass
  54 
  55 
  56 class ProjectIntersectionFilterCity(PolygonInterventionFilterMixin, RightFilter):
  57     model = City
  58 
  59     def __init__(self, *args, **kwargs):
  60         super(ProjectIntersectionFilterCity, self).__init__(*args, **kwargs)
  61         self.lookup_expr = 'intersects'
  62         self.lookup_queryset_in = 'interventions__in'
  63 
  64     def get_geom(self, value):
  65         return value.geom
  66 
  67 
  68 class ProjectIntersectionFilterDistrict(PolygonInterventionFilterMixin, RightFilter):
  69     model = District
  70 
  71     def __init__(self, *args, **kwargs):
  72         super(ProjectIntersectionFilterDistrict, self).__init__(*args, **kwargs)
  73         self.lookup_expr = 'intersects'
  74         self.lookup_queryset_in = 'interventions__in'
  75 
  76     def get_geom(self, value):
  77         return value.geom
  78 
  79 
  80 class InterventionFilterSet(ZoningFilterSet, StructureRelatedFilterSet):
  81     ON_CHOICES = (('infrastructure', _("Infrastructure")), ('signage', _("Signage")), ('blade', _("Blade")),
  82                   ('topology', _("Path")), ('trek', _("Trek")), ('poi', _("POI")), ('service', _("Service")),
  83                   ('trail', _("Trail")))
  84     bbox = PolygonTopologyFilter(lookup_expr='intersects')
  85     year = MultipleChoiceFilter(choices=Intervention.objects.year_choices(),
  86                                 field_name='date', lookup_expr='year', label=_("Year"))
  87     on = ChoiceFilter(field_name='target_type__model', choices=ON_CHOICES, label=_("On"), empty_label=_("On"))
  88 
  89     class Meta(StructureRelatedFilterSet.Meta):
  90         model = Intervention
  91         fields = StructureRelatedFilterSet.Meta.fields + [
  92             'status', 'type', 'stake', 'subcontracting', 'project', 'on',
  93         ]
  94 
  95 
  96 class ProjectFilterSet(StructureRelatedFilterSet):
  97     bbox = PythonPolygonFilter(field_name='geom')
  98     year = MultipleChoiceFilter(
  99         label=_("Year of activity"), method='filter_year',
  100         choices=lambda: Project.objects.year_choices()  # Could change over time
  101     )
  102     city = ProjectIntersectionFilterCity(label=_('City'), required=False)
  103     district = ProjectIntersectionFilterDistrict(label=_('District'), required=False)
  104 
  105     class Meta(StructureRelatedFilterSet.Meta):
  106         model = Project
  107         fields = StructureRelatedFilterSet.Meta.fields + [
  108             'year', 'type', 'domain', 'contractors', 'project_owner',
  109             'project_manager', 'founders'
  110         ]
  111 
  112     def filter_year(self, qs, name, values):
  113         q = Q()
  114         for value in values:
  115             q |= Q(begin_year__lte=value, end_year__gte=value)
  116         return qs.filter(q)
  117
  [end of geotrek/maintenance/filters.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/geotrek/maintenance/filters.py b/geotrek/maintenance/filters.py
  --- a/geotrek/maintenance/filters.py
  +++ b/geotrek/maintenance/filters.py
  @@ -25,6 +25,9 @@
       def filter(self, qs, values):
           if not values:
               return qs
  +        if not isinstance(values, list):
  +            values = [values]
  +
           lookup = self.lookup_expr
   
           blade_content_type = ContentType.objects.get_for_model(Blade)
  
verification_info: {"golden_diff": "diff --git a/geotrek/maintenance/filters.py b/geotrek/maintenance/filters.py\n--- a/geotrek/maintenance/filters.py\n+++ b/geotrek/maintenance/filters.py\n@@ -25,6 +25,9 @@\n     def filter(self, qs, values):\n         if not values:\n             return qs\n+        if not isinstance(values, list):\n+            values = [values]\n+\n         lookup = self.lookup_expr\n \n         blade_content_type = ContentType.objects.get_for_model(Blade)\n", "issue": "Bug affichage intervention selon niveau de zoom\nBonjour, sur la 2.49.0 selon le niveau de zoom s\u00e9lectionn\u00e9, certaines interventions apparaissent et disparaissent. Faire glisser la carte provoque aussi ce comportement :\r\n\r\n\r\nhttps://user-images.githubusercontent.com/45095227/108825316-2719b200-75c3-11eb-8406-11d57bcd2531.mov\r\n\r\nJ'en profite pour dire que je n'ai pas pu changer l'opacit\u00e9 des lin\u00e9aires pour qu'ils soient plus visibles ( voir : https://github.com/GeotrekCE/Geotrek-admin/issues/2554)\n", "before_files": [{"content": "from django.db.models import Q\nfrom django.conf import settings\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.utils.translation import gettext_lazy as _\nfrom django_filters import ChoiceFilter, MultipleChoiceFilter\n\nfrom mapentity.filters import PolygonFilter, PythonPolygonFilter\n\nfrom geotrek.core.models import Topology\nfrom geotrek.authent.filters import StructureRelatedFilterSet\nfrom geotrek.common.filters import RightFilter\nfrom geotrek.zoning.filters import ZoningFilterSet\nfrom geotrek.zoning.models import City, District\n\nfrom .models import Intervention, Project\n\nif 'geotrek.signage' in settings.INSTALLED_APPS:\n    from geotrek.signage.models import Blade\n\n\nclass PolygonInterventionFilterMixin(object):\n    def get_geom(self, value):\n        return value\n\n    def filter(self, qs, values):\n        if not values:\n            return qs\n        lookup = self.lookup_expr\n\n        blade_content_type = ContentType.objects.get_for_model(Blade)\n        topologies = []\n        for value in values:\n            topologies += Topology.objects.filter(**{'geom__%s' % lookup: self.get_geom(value)}).values_list('id', flat=True)\n        topologies_intervention = Intervention.objects.existing().filter(target_id__in=topologies).exclude(\n            target_type=blade_content_type).distinct('pk').values_list('id', flat=True)\n\n        interventions = list(topologies_intervention)\n        if 'geotrek.signage' in settings.INSTALLED_APPS:\n            blades = list(Blade.objects.filter(signage__in=topologies).values_list('id', flat=True))\n            blades_intervention = Intervention.objects.existing().filter(target_id__in=blades,\n                                                                         target_type=blade_content_type).values_list('id',\n                                                                                                                     flat=True)\n            interventions.extend(blades_intervention)\n        if hasattr(self, 'lookup_queryset_in'):\n            lookup_queryset = self.lookup_queryset_in\n        else:\n            lookup_queryset = 'pk__in'\n        qs = qs.filter(**{'%s' % lookup_queryset: interventions})\n        return qs\n\n\nclass PolygonTopologyFilter(PolygonInterventionFilterMixin, PolygonFilter):\n    pass\n\n\nclass ProjectIntersectionFilterCity(PolygonInterventionFilterMixin, RightFilter):\n    model = City\n\n    def __init__(self, *args, **kwargs):\n        super(ProjectIntersectionFilterCity, self).__init__(*args, **kwargs)\n        self.lookup_expr = 'intersects'\n        self.lookup_queryset_in = 'interventions__in'\n\n    def get_geom(self, value):\n        return value.geom\n\n\nclass ProjectIntersectionFilterDistrict(PolygonInterventionFilterMixin, RightFilter):\n    model = District\n\n    def __init__(self, *args, **kwargs):\n        super(ProjectIntersectionFilterDistrict, self).__init__(*args, **kwargs)\n        self.lookup_expr = 'intersects'\n        self.lookup_queryset_in = 'interventions__in'\n\n    def get_geom(self, value):\n        return value.geom\n\n\nclass InterventionFilterSet(ZoningFilterSet, StructureRelatedFilterSet):\n    ON_CHOICES = (('infrastructure', _(\"Infrastructure\")), ('signage', _(\"Signage\")), ('blade', _(\"Blade\")),\n                  ('topology', _(\"Path\")), ('trek', _(\"Trek\")), ('poi', _(\"POI\")), ('service', _(\"Service\")),\n                  ('trail', _(\"Trail\")))\n    bbox = PolygonTopologyFilter(lookup_expr='intersects')\n    year = MultipleChoiceFilter(choices=Intervention.objects.year_choices(),\n                                field_name='date', lookup_expr='year', label=_(\"Year\"))\n    on = ChoiceFilter(field_name='target_type__model', choices=ON_CHOICES, label=_(\"On\"), empty_label=_(\"On\"))\n\n    class Meta(StructureRelatedFilterSet.Meta):\n        model = Intervention\n        fields = StructureRelatedFilterSet.Meta.fields + [\n            'status', 'type', 'stake', 'subcontracting', 'project', 'on',\n        ]\n\n\nclass ProjectFilterSet(StructureRelatedFilterSet):\n    bbox = PythonPolygonFilter(field_name='geom')\n    year = MultipleChoiceFilter(\n        label=_(\"Year of activity\"), method='filter_year',\n        choices=lambda: Project.objects.year_choices()  # Could change over time\n    )\n    city = ProjectIntersectionFilterCity(label=_('City'), required=False)\n    district = ProjectIntersectionFilterDistrict(label=_('District'), required=False)\n\n    class Meta(StructureRelatedFilterSet.Meta):\n        model = Project\n        fields = StructureRelatedFilterSet.Meta.fields + [\n            'year', 'type', 'domain', 'contractors', 'project_owner',\n            'project_manager', 'founders'\n        ]\n\n    def filter_year(self, qs, name, values):\n        q = Q()\n        for value in values:\n            q |= Q(begin_year__lte=value, end_year__gte=value)\n        return qs.filter(q)\n", "path": "geotrek/maintenance/filters.py"}]}