We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Infrastructures are duplicated in list if they received multiple intervention the same year
- Filter infrastructures by year
- If the infrastructure has received several interventions this same year, it will appear multiple times in the list

Related #293 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `geotrek/common/filters.py`
Content:
```
1 import sys
2 from decimal import Decimal
3 
4 from django.utils.translation import ugettext_lazy as _
5 
6 from django_filters import RangeFilter, Filter
7 from mapentity.filters import MapEntityFilterSet
8 
9 
10 class OptionalRangeFilter(RangeFilter):
11     def __init__(self, *args, **kwargs):
12         super(OptionalRangeFilter, self).__init__(*args, **kwargs)
13         self.field.fields[0].label = _('min %s') % self.field.label
14         self.field.fields[1].label = _('max %s') % self.field.label
15 
16     def filter(self, qs, value):
17         if value:
18             if value.start and not value.stop:
19                 value = slice(value.start, Decimal(sys.maxint), value.step)
20             if not value.start and value.stop:
21                 value = slice(Decimal(-(sys.maxint + 1)), value.stop, value.step)
22         return super(OptionalRangeFilter, self).filter(qs, value)
23 
24 
25 class YearFilter(Filter):
26     def do_filter(self, qs, year):
27         return qs.filter(**{
28             '%s__year' % self.name: year,
29         })
30 
31     def filter(self, qs, value):
32         try:
33             year = int(value)
34         except (ValueError, TypeError):
35             year = -1
36         return qs if year < 0 else self.do_filter(qs, year)
37 
38 
39 class YearBetweenFilter(YearFilter):
40     def __init__(self, *args, **kwargs):
41         assert len(kwargs['name']) == 2
42         super(YearBetweenFilter, self).__init__(*args, **kwargs)
43 
44     def do_filter(self, qs, year):
45         begin, end = self.name
46         qs = qs.filter(**{
47             '%s__lte' % begin: year,
48             '%s__gte' % end: year,
49         })
50         return qs
51 
52 
53 class StructureRelatedFilterSet(MapEntityFilterSet):
54     class Meta(MapEntityFilterSet.Meta):
55         fields = MapEntityFilterSet.Meta.fields + ['structure']
56
```

Path: `geotrek/land/views.py`
Content:
```
1 from mapentity.views import (MapEntityLayer, MapEntityList, MapEntityJsonList, MapEntityFormat,
2                              MapEntityDetail, MapEntityDocument, MapEntityCreate, MapEntityUpdate, MapEntityDelete)
3 
4 from geotrek.core.views import CreateFromTopologyMixin
5 from .models import (PhysicalEdge, LandEdge, CompetenceEdge,
6                      WorkManagementEdge, SignageManagementEdge)
7 from .filters import PhysicalEdgeFilterSet, LandEdgeFilterSet, CompetenceEdgeFilterSet, WorkManagementEdgeFilterSet, SignageManagementEdgeFilterSet
8 from .forms import PhysicalEdgeForm, LandEdgeForm, CompetenceEdgeForm, WorkManagementEdgeForm, SignageManagementEdgeForm
9 
10 
11 class PhysicalEdgeLayer(MapEntityLayer):
12     queryset = PhysicalEdge.objects.existing()
13     properties = ['color_index', 'name']
14 
15 
16 class PhysicalEdgeList(MapEntityList):
17     queryset = PhysicalEdge.objects.existing()
18     filterform = PhysicalEdgeFilterSet
19     columns = ['id', 'physical_type']
20 
21 
22 class PhysicalEdgeJsonList(MapEntityJsonList, PhysicalEdgeList):
23     pass
24 
25 
26 class PhysicalEdgeFormatList(MapEntityFormat, PhysicalEdgeList):
27     pass
28 
29 
30 class PhysicalEdgeDetail(MapEntityDetail):
31     queryset = PhysicalEdge.objects.existing()
32 
33 
34 class PhysicalEdgeDocument(MapEntityDocument):
35     model = PhysicalEdge
36 
37 
38 class PhysicalEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):
39     model = PhysicalEdge
40     form_class = PhysicalEdgeForm
41 
42 
43 class PhysicalEdgeUpdate(MapEntityUpdate):
44     queryset = PhysicalEdge.objects.existing()
45     form_class = PhysicalEdgeForm
46 
47 
48 class PhysicalEdgeDelete(MapEntityDelete):
49     model = PhysicalEdge
50 
51 
52 class LandEdgeLayer(MapEntityLayer):
53     queryset = LandEdge.objects.existing()
54     properties = ['color_index', 'name']
55 
56 
57 class LandEdgeList(MapEntityList):
58     queryset = LandEdge.objects.existing()
59     filterform = LandEdgeFilterSet
60     columns = ['id', 'land_type']
61 
62 
63 class LandEdgeJsonList(MapEntityJsonList, LandEdgeList):
64     pass
65 
66 
67 class LandEdgeFormatList(MapEntityFormat, LandEdgeList):
68     pass
69 
70 
71 class LandEdgeDetail(MapEntityDetail):
72     queryset = LandEdge.objects.existing()
73 
74 
75 class LandEdgeDocument(MapEntityDocument):
76     model = LandEdge
77 
78 
79 class LandEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):
80     model = LandEdge
81     form_class = LandEdgeForm
82 
83 
84 class LandEdgeUpdate(MapEntityUpdate):
85     queryset = LandEdge.objects.existing()
86     form_class = LandEdgeForm
87 
88 
89 class LandEdgeDelete(MapEntityDelete):
90     model = LandEdge
91 
92 
93 class CompetenceEdgeLayer(MapEntityLayer):
94     queryset = CompetenceEdge.objects.existing()
95     properties = ['color_index', 'name']
96 
97 
98 class CompetenceEdgeList(MapEntityList):
99     queryset = CompetenceEdge.objects.existing()
100     filterform = CompetenceEdgeFilterSet
101     columns = ['id', 'organization']
102 
103 
104 class CompetenceEdgeJsonList(MapEntityJsonList, CompetenceEdgeList):
105     pass
106 
107 
108 class CompetenceEdgeFormatList(MapEntityFormat, CompetenceEdgeList):
109     pass
110 
111 
112 class CompetenceEdgeDetail(MapEntityDetail):
113     queryset = CompetenceEdge.objects.existing()
114 
115 
116 class CompetenceEdgeDocument(MapEntityDocument):
117     model = CompetenceEdge
118 
119 
120 class CompetenceEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):
121     model = CompetenceEdge
122     form_class = CompetenceEdgeForm
123 
124 
125 class CompetenceEdgeUpdate(MapEntityUpdate):
126     queryset = CompetenceEdge.objects.existing()
127     form_class = CompetenceEdgeForm
128 
129 
130 class CompetenceEdgeDelete(MapEntityDelete):
131     model = CompetenceEdge
132 
133 
134 class WorkManagementEdgeLayer(MapEntityLayer):
135     queryset = WorkManagementEdge.objects.existing()
136     properties = ['color_index', 'name']
137 
138 
139 class WorkManagementEdgeList(MapEntityList):
140     queryset = WorkManagementEdge.objects.existing()
141     filterform = WorkManagementEdgeFilterSet
142     columns = ['id', 'organization']
143 
144 
145 class WorkManagementEdgeJsonList(MapEntityJsonList, WorkManagementEdgeList):
146     pass
147 
148 
149 class WorkManagementEdgeFormatList(MapEntityFormat, WorkManagementEdgeList):
150     pass
151 
152 
153 class WorkManagementEdgeDetail(MapEntityDetail):
154     queryset = WorkManagementEdge.objects.existing()
155 
156 
157 class WorkManagementEdgeDocument(MapEntityDocument):
158     model = WorkManagementEdge
159 
160 
161 class WorkManagementEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):
162     model = WorkManagementEdge
163     form_class = WorkManagementEdgeForm
164 
165 
166 class WorkManagementEdgeUpdate(MapEntityUpdate):
167     queryset = WorkManagementEdge.objects.existing()
168     form_class = WorkManagementEdgeForm
169 
170 
171 class WorkManagementEdgeDelete(MapEntityDelete):
172     model = WorkManagementEdge
173 
174 
175 class SignageManagementEdgeLayer(MapEntityLayer):
176     queryset = SignageManagementEdge.objects.existing()
177     properties = ['color_index', 'name']
178 
179 
180 class SignageManagementEdgeList(MapEntityList):
181     queryset = SignageManagementEdge.objects.existing()
182     filterform = SignageManagementEdgeFilterSet
183     columns = ['id', 'organization']
184 
185 
186 class SignageManagementEdgeJsonList(MapEntityJsonList, SignageManagementEdgeList):
187     pass
188 
189 
190 class SignageManagementEdgeFormatList(MapEntityFormat, SignageManagementEdgeList):
191     pass
192 
193 
194 class SignageManagementEdgeDetail(MapEntityDetail):
195     queryset = SignageManagementEdge.objects.existing()
196 
197 
198 class SignageManagementEdgeDocument(MapEntityDocument):
199     model = SignageManagementEdge
200 
201 
202 class SignageManagementEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):
203     model = SignageManagementEdge
204     form_class = SignageManagementEdgeForm
205 
206 
207 class SignageManagementEdgeUpdate(MapEntityUpdate):
208     queryset = SignageManagementEdge.objects.existing()
209     form_class = SignageManagementEdgeForm
210 
211 
212 class SignageManagementEdgeDelete(MapEntityDelete):
213     model = SignageManagementEdge
214
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/geotrek/common/filters.py b/geotrek/common/filters.py
--- a/geotrek/common/filters.py
+++ b/geotrek/common/filters.py
@@ -26,7 +26,7 @@
     def do_filter(self, qs, year):
         return qs.filter(**{
             '%s__year' % self.name: year,
-        })
+        }).distinct()
 
     def filter(self, qs, value):
         try:
diff --git a/geotrek/land/views.py b/geotrek/land/views.py
--- a/geotrek/land/views.py
+++ b/geotrek/land/views.py
@@ -16,7 +16,7 @@
 class PhysicalEdgeList(MapEntityList):
     queryset = PhysicalEdge.objects.existing()
     filterform = PhysicalEdgeFilterSet
-    columns = ['id', 'physical_type']
+    columns = ['id', 'physical_type', 'length']
 
 
 class PhysicalEdgeJsonList(MapEntityJsonList, PhysicalEdgeList):
@@ -57,7 +57,7 @@
 class LandEdgeList(MapEntityList):
     queryset = LandEdge.objects.existing()
     filterform = LandEdgeFilterSet
-    columns = ['id', 'land_type']
+    columns = ['id', 'land_type', 'length']
 
 
 class LandEdgeJsonList(MapEntityJsonList, LandEdgeList):
@@ -98,7 +98,7 @@
 class CompetenceEdgeList(MapEntityList):
     queryset = CompetenceEdge.objects.existing()
     filterform = CompetenceEdgeFilterSet
-    columns = ['id', 'organization']
+    columns = ['id', 'organization', 'length']
 
 
 class CompetenceEdgeJsonList(MapEntityJsonList, CompetenceEdgeList):
@@ -139,7 +139,7 @@
 class WorkManagementEdgeList(MapEntityList):
     queryset = WorkManagementEdge.objects.existing()
     filterform = WorkManagementEdgeFilterSet
-    columns = ['id', 'organization']
+    columns = ['id', 'organization', 'length']
 
 
 class WorkManagementEdgeJsonList(MapEntityJsonList, WorkManagementEdgeList):
@@ -180,7 +180,7 @@
 class SignageManagementEdgeList(MapEntityList):
     queryset = SignageManagementEdge.objects.existing()
     filterform = SignageManagementEdgeFilterSet
-    columns = ['id', 'organization']
+    columns = ['id', 'organization', 'length']
 
 
 class SignageManagementEdgeJsonList(MapEntityJsonList, SignageManagementEdgeList):

{"golden_diff": "diff --git a/geotrek/common/filters.py b/geotrek/common/filters.py\n--- a/geotrek/common/filters.py\n+++ b/geotrek/common/filters.py\n@@ -26,7 +26,7 @@\n     def do_filter(self, qs, year):\n         return qs.filter(**{\n             '%s__year' % self.name: year,\n-        })\n+        }).distinct()\n \n     def filter(self, qs, value):\n         try:\ndiff --git a/geotrek/land/views.py b/geotrek/land/views.py\n--- a/geotrek/land/views.py\n+++ b/geotrek/land/views.py\n@@ -16,7 +16,7 @@\n class PhysicalEdgeList(MapEntityList):\n     queryset = PhysicalEdge.objects.existing()\n     filterform = PhysicalEdgeFilterSet\n-    columns = ['id', 'physical_type']\n+    columns = ['id', 'physical_type', 'length']\n \n \n class PhysicalEdgeJsonList(MapEntityJsonList, PhysicalEdgeList):\n@@ -57,7 +57,7 @@\n class LandEdgeList(MapEntityList):\n     queryset = LandEdge.objects.existing()\n     filterform = LandEdgeFilterSet\n-    columns = ['id', 'land_type']\n+    columns = ['id', 'land_type', 'length']\n \n \n class LandEdgeJsonList(MapEntityJsonList, LandEdgeList):\n@@ -98,7 +98,7 @@\n class CompetenceEdgeList(MapEntityList):\n     queryset = CompetenceEdge.objects.existing()\n     filterform = CompetenceEdgeFilterSet\n-    columns = ['id', 'organization']\n+    columns = ['id', 'organization', 'length']\n \n \n class CompetenceEdgeJsonList(MapEntityJsonList, CompetenceEdgeList):\n@@ -139,7 +139,7 @@\n class WorkManagementEdgeList(MapEntityList):\n     queryset = WorkManagementEdge.objects.existing()\n     filterform = WorkManagementEdgeFilterSet\n-    columns = ['id', 'organization']\n+    columns = ['id', 'organization', 'length']\n \n \n class WorkManagementEdgeJsonList(MapEntityJsonList, WorkManagementEdgeList):\n@@ -180,7 +180,7 @@\n class SignageManagementEdgeList(MapEntityList):\n     queryset = SignageManagementEdge.objects.existing()\n     filterform = SignageManagementEdgeFilterSet\n-    columns = ['id', 'organization']\n+    columns = ['id', 'organization', 'length']\n \n \n class SignageManagementEdgeJsonList(MapEntityJsonList, SignageManagementEdgeList):\n", "issue": "Infrastructures are duplicated in list if they received multiple intervention the same year\n- Filter infrastructures by year\n- If the infrastructure has received several interventions this same year, it will appear multiple times in the list\n\nRelated #293 \n\n", "before_files": [{"content": "import sys\nfrom decimal import Decimal\n\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom django_filters import RangeFilter, Filter\nfrom mapentity.filters import MapEntityFilterSet\n\n\nclass OptionalRangeFilter(RangeFilter):\n    def __init__(self, *args, **kwargs):\n        super(OptionalRangeFilter, self).__init__(*args, **kwargs)\n        self.field.fields[0].label = _('min %s') % self.field.label\n        self.field.fields[1].label = _('max %s') % self.field.label\n\n    def filter(self, qs, value):\n        if value:\n            if value.start and not value.stop:\n                value = slice(value.start, Decimal(sys.maxint), value.step)\n            if not value.start and value.stop:\n                value = slice(Decimal(-(sys.maxint + 1)), value.stop, value.step)\n        return super(OptionalRangeFilter, self).filter(qs, value)\n\n\nclass YearFilter(Filter):\n    def do_filter(self, qs, year):\n        return qs.filter(**{\n            '%s__year' % self.name: year,\n        })\n\n    def filter(self, qs, value):\n        try:\n            year = int(value)\n        except (ValueError, TypeError):\n            year = -1\n        return qs if year < 0 else self.do_filter(qs, year)\n\n\nclass YearBetweenFilter(YearFilter):\n    def __init__(self, *args, **kwargs):\n        assert len(kwargs['name']) == 2\n        super(YearBetweenFilter, self).__init__(*args, **kwargs)\n\n    def do_filter(self, qs, year):\n        begin, end = self.name\n        qs = qs.filter(**{\n            '%s__lte' % begin: year,\n            '%s__gte' % end: year,\n        })\n        return qs\n\n\nclass StructureRelatedFilterSet(MapEntityFilterSet):\n    class Meta(MapEntityFilterSet.Meta):\n        fields = MapEntityFilterSet.Meta.fields + ['structure']\n", "path": "geotrek/common/filters.py"}, {"content": "from mapentity.views import (MapEntityLayer, MapEntityList, MapEntityJsonList, MapEntityFormat,\n                             MapEntityDetail, MapEntityDocument, MapEntityCreate, MapEntityUpdate, MapEntityDelete)\n\nfrom geotrek.core.views import CreateFromTopologyMixin\nfrom .models import (PhysicalEdge, LandEdge, CompetenceEdge,\n                     WorkManagementEdge, SignageManagementEdge)\nfrom .filters import PhysicalEdgeFilterSet, LandEdgeFilterSet, CompetenceEdgeFilterSet, WorkManagementEdgeFilterSet, SignageManagementEdgeFilterSet\nfrom .forms import PhysicalEdgeForm, LandEdgeForm, CompetenceEdgeForm, WorkManagementEdgeForm, SignageManagementEdgeForm\n\n\nclass PhysicalEdgeLayer(MapEntityLayer):\n    queryset = PhysicalEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass PhysicalEdgeList(MapEntityList):\n    queryset = PhysicalEdge.objects.existing()\n    filterform = PhysicalEdgeFilterSet\n    columns = ['id', 'physical_type']\n\n\nclass PhysicalEdgeJsonList(MapEntityJsonList, PhysicalEdgeList):\n    pass\n\n\nclass PhysicalEdgeFormatList(MapEntityFormat, PhysicalEdgeList):\n    pass\n\n\nclass PhysicalEdgeDetail(MapEntityDetail):\n    queryset = PhysicalEdge.objects.existing()\n\n\nclass PhysicalEdgeDocument(MapEntityDocument):\n    model = PhysicalEdge\n\n\nclass PhysicalEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = PhysicalEdge\n    form_class = PhysicalEdgeForm\n\n\nclass PhysicalEdgeUpdate(MapEntityUpdate):\n    queryset = PhysicalEdge.objects.existing()\n    form_class = PhysicalEdgeForm\n\n\nclass PhysicalEdgeDelete(MapEntityDelete):\n    model = PhysicalEdge\n\n\nclass LandEdgeLayer(MapEntityLayer):\n    queryset = LandEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass LandEdgeList(MapEntityList):\n    queryset = LandEdge.objects.existing()\n    filterform = LandEdgeFilterSet\n    columns = ['id', 'land_type']\n\n\nclass LandEdgeJsonList(MapEntityJsonList, LandEdgeList):\n    pass\n\n\nclass LandEdgeFormatList(MapEntityFormat, LandEdgeList):\n    pass\n\n\nclass LandEdgeDetail(MapEntityDetail):\n    queryset = LandEdge.objects.existing()\n\n\nclass LandEdgeDocument(MapEntityDocument):\n    model = LandEdge\n\n\nclass LandEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = LandEdge\n    form_class = LandEdgeForm\n\n\nclass LandEdgeUpdate(MapEntityUpdate):\n    queryset = LandEdge.objects.existing()\n    form_class = LandEdgeForm\n\n\nclass LandEdgeDelete(MapEntityDelete):\n    model = LandEdge\n\n\nclass CompetenceEdgeLayer(MapEntityLayer):\n    queryset = CompetenceEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass CompetenceEdgeList(MapEntityList):\n    queryset = CompetenceEdge.objects.existing()\n    filterform = CompetenceEdgeFilterSet\n    columns = ['id', 'organization']\n\n\nclass CompetenceEdgeJsonList(MapEntityJsonList, CompetenceEdgeList):\n    pass\n\n\nclass CompetenceEdgeFormatList(MapEntityFormat, CompetenceEdgeList):\n    pass\n\n\nclass CompetenceEdgeDetail(MapEntityDetail):\n    queryset = CompetenceEdge.objects.existing()\n\n\nclass CompetenceEdgeDocument(MapEntityDocument):\n    model = CompetenceEdge\n\n\nclass CompetenceEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = CompetenceEdge\n    form_class = CompetenceEdgeForm\n\n\nclass CompetenceEdgeUpdate(MapEntityUpdate):\n    queryset = CompetenceEdge.objects.existing()\n    form_class = CompetenceEdgeForm\n\n\nclass CompetenceEdgeDelete(MapEntityDelete):\n    model = CompetenceEdge\n\n\nclass WorkManagementEdgeLayer(MapEntityLayer):\n    queryset = WorkManagementEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass WorkManagementEdgeList(MapEntityList):\n    queryset = WorkManagementEdge.objects.existing()\n    filterform = WorkManagementEdgeFilterSet\n    columns = ['id', 'organization']\n\n\nclass WorkManagementEdgeJsonList(MapEntityJsonList, WorkManagementEdgeList):\n    pass\n\n\nclass WorkManagementEdgeFormatList(MapEntityFormat, WorkManagementEdgeList):\n    pass\n\n\nclass WorkManagementEdgeDetail(MapEntityDetail):\n    queryset = WorkManagementEdge.objects.existing()\n\n\nclass WorkManagementEdgeDocument(MapEntityDocument):\n    model = WorkManagementEdge\n\n\nclass WorkManagementEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = WorkManagementEdge\n    form_class = WorkManagementEdgeForm\n\n\nclass WorkManagementEdgeUpdate(MapEntityUpdate):\n    queryset = WorkManagementEdge.objects.existing()\n    form_class = WorkManagementEdgeForm\n\n\nclass WorkManagementEdgeDelete(MapEntityDelete):\n    model = WorkManagementEdge\n\n\nclass SignageManagementEdgeLayer(MapEntityLayer):\n    queryset = SignageManagementEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass SignageManagementEdgeList(MapEntityList):\n    queryset = SignageManagementEdge.objects.existing()\n    filterform = SignageManagementEdgeFilterSet\n    columns = ['id', 'organization']\n\n\nclass SignageManagementEdgeJsonList(MapEntityJsonList, SignageManagementEdgeList):\n    pass\n\n\nclass SignageManagementEdgeFormatList(MapEntityFormat, SignageManagementEdgeList):\n    pass\n\n\nclass SignageManagementEdgeDetail(MapEntityDetail):\n    queryset = SignageManagementEdge.objects.existing()\n\n\nclass SignageManagementEdgeDocument(MapEntityDocument):\n    model = SignageManagementEdge\n\n\nclass SignageManagementEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = SignageManagementEdge\n    form_class = SignageManagementEdgeForm\n\n\nclass SignageManagementEdgeUpdate(MapEntityUpdate):\n    queryset = SignageManagementEdge.objects.existing()\n    form_class = SignageManagementEdgeForm\n\n\nclass SignageManagementEdgeDelete(MapEntityDelete):\n    model = SignageManagementEdge\n", "path": "geotrek/land/views.py"}], "after_files": [{"content": "import sys\nfrom decimal import Decimal\n\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom django_filters import RangeFilter, Filter\nfrom mapentity.filters import MapEntityFilterSet\n\n\nclass OptionalRangeFilter(RangeFilter):\n    def __init__(self, *args, **kwargs):\n        super(OptionalRangeFilter, self).__init__(*args, **kwargs)\n        self.field.fields[0].label = _('min %s') % self.field.label\n        self.field.fields[1].label = _('max %s') % self.field.label\n\n    def filter(self, qs, value):\n        if value:\n            if value.start and not value.stop:\n                value = slice(value.start, Decimal(sys.maxint), value.step)\n            if not value.start and value.stop:\n                value = slice(Decimal(-(sys.maxint + 1)), value.stop, value.step)\n        return super(OptionalRangeFilter, self).filter(qs, value)\n\n\nclass YearFilter(Filter):\n    def do_filter(self, qs, year):\n        return qs.filter(**{\n            '%s__year' % self.name: year,\n        }).distinct()\n\n    def filter(self, qs, value):\n        try:\n            year = int(value)\n        except (ValueError, TypeError):\n            year = -1\n        return qs if year < 0 else self.do_filter(qs, year)\n\n\nclass YearBetweenFilter(YearFilter):\n    def __init__(self, *args, **kwargs):\n        assert len(kwargs['name']) == 2\n        super(YearBetweenFilter, self).__init__(*args, **kwargs)\n\n    def do_filter(self, qs, year):\n        begin, end = self.name\n        qs = qs.filter(**{\n            '%s__lte' % begin: year,\n            '%s__gte' % end: year,\n        })\n        return qs\n\n\nclass StructureRelatedFilterSet(MapEntityFilterSet):\n    class Meta(MapEntityFilterSet.Meta):\n        fields = MapEntityFilterSet.Meta.fields + ['structure']\n", "path": "geotrek/common/filters.py"}, {"content": "from mapentity.views import (MapEntityLayer, MapEntityList, MapEntityJsonList, MapEntityFormat,\n                             MapEntityDetail, MapEntityDocument, MapEntityCreate, MapEntityUpdate, MapEntityDelete)\n\nfrom geotrek.core.views import CreateFromTopologyMixin\nfrom .models import (PhysicalEdge, LandEdge, CompetenceEdge,\n                     WorkManagementEdge, SignageManagementEdge)\nfrom .filters import PhysicalEdgeFilterSet, LandEdgeFilterSet, CompetenceEdgeFilterSet, WorkManagementEdgeFilterSet, SignageManagementEdgeFilterSet\nfrom .forms import PhysicalEdgeForm, LandEdgeForm, CompetenceEdgeForm, WorkManagementEdgeForm, SignageManagementEdgeForm\n\n\nclass PhysicalEdgeLayer(MapEntityLayer):\n    queryset = PhysicalEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass PhysicalEdgeList(MapEntityList):\n    queryset = PhysicalEdge.objects.existing()\n    filterform = PhysicalEdgeFilterSet\n    columns = ['id', 'physical_type', 'length']\n\n\nclass PhysicalEdgeJsonList(MapEntityJsonList, PhysicalEdgeList):\n    pass\n\n\nclass PhysicalEdgeFormatList(MapEntityFormat, PhysicalEdgeList):\n    pass\n\n\nclass PhysicalEdgeDetail(MapEntityDetail):\n    queryset = PhysicalEdge.objects.existing()\n\n\nclass PhysicalEdgeDocument(MapEntityDocument):\n    model = PhysicalEdge\n\n\nclass PhysicalEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = PhysicalEdge\n    form_class = PhysicalEdgeForm\n\n\nclass PhysicalEdgeUpdate(MapEntityUpdate):\n    queryset = PhysicalEdge.objects.existing()\n    form_class = PhysicalEdgeForm\n\n\nclass PhysicalEdgeDelete(MapEntityDelete):\n    model = PhysicalEdge\n\n\nclass LandEdgeLayer(MapEntityLayer):\n    queryset = LandEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass LandEdgeList(MapEntityList):\n    queryset = LandEdge.objects.existing()\n    filterform = LandEdgeFilterSet\n    columns = ['id', 'land_type', 'length']\n\n\nclass LandEdgeJsonList(MapEntityJsonList, LandEdgeList):\n    pass\n\n\nclass LandEdgeFormatList(MapEntityFormat, LandEdgeList):\n    pass\n\n\nclass LandEdgeDetail(MapEntityDetail):\n    queryset = LandEdge.objects.existing()\n\n\nclass LandEdgeDocument(MapEntityDocument):\n    model = LandEdge\n\n\nclass LandEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = LandEdge\n    form_class = LandEdgeForm\n\n\nclass LandEdgeUpdate(MapEntityUpdate):\n    queryset = LandEdge.objects.existing()\n    form_class = LandEdgeForm\n\n\nclass LandEdgeDelete(MapEntityDelete):\n    model = LandEdge\n\n\nclass CompetenceEdgeLayer(MapEntityLayer):\n    queryset = CompetenceEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass CompetenceEdgeList(MapEntityList):\n    queryset = CompetenceEdge.objects.existing()\n    filterform = CompetenceEdgeFilterSet\n    columns = ['id', 'organization', 'length']\n\n\nclass CompetenceEdgeJsonList(MapEntityJsonList, CompetenceEdgeList):\n    pass\n\n\nclass CompetenceEdgeFormatList(MapEntityFormat, CompetenceEdgeList):\n    pass\n\n\nclass CompetenceEdgeDetail(MapEntityDetail):\n    queryset = CompetenceEdge.objects.existing()\n\n\nclass CompetenceEdgeDocument(MapEntityDocument):\n    model = CompetenceEdge\n\n\nclass CompetenceEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = CompetenceEdge\n    form_class = CompetenceEdgeForm\n\n\nclass CompetenceEdgeUpdate(MapEntityUpdate):\n    queryset = CompetenceEdge.objects.existing()\n    form_class = CompetenceEdgeForm\n\n\nclass CompetenceEdgeDelete(MapEntityDelete):\n    model = CompetenceEdge\n\n\nclass WorkManagementEdgeLayer(MapEntityLayer):\n    queryset = WorkManagementEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass WorkManagementEdgeList(MapEntityList):\n    queryset = WorkManagementEdge.objects.existing()\n    filterform = WorkManagementEdgeFilterSet\n    columns = ['id', 'organization', 'length']\n\n\nclass WorkManagementEdgeJsonList(MapEntityJsonList, WorkManagementEdgeList):\n    pass\n\n\nclass WorkManagementEdgeFormatList(MapEntityFormat, WorkManagementEdgeList):\n    pass\n\n\nclass WorkManagementEdgeDetail(MapEntityDetail):\n    queryset = WorkManagementEdge.objects.existing()\n\n\nclass WorkManagementEdgeDocument(MapEntityDocument):\n    model = WorkManagementEdge\n\n\nclass WorkManagementEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = WorkManagementEdge\n    form_class = WorkManagementEdgeForm\n\n\nclass WorkManagementEdgeUpdate(MapEntityUpdate):\n    queryset = WorkManagementEdge.objects.existing()\n    form_class = WorkManagementEdgeForm\n\n\nclass WorkManagementEdgeDelete(MapEntityDelete):\n    model = WorkManagementEdge\n\n\nclass SignageManagementEdgeLayer(MapEntityLayer):\n    queryset = SignageManagementEdge.objects.existing()\n    properties = ['color_index', 'name']\n\n\nclass SignageManagementEdgeList(MapEntityList):\n    queryset = SignageManagementEdge.objects.existing()\n    filterform = SignageManagementEdgeFilterSet\n    columns = ['id', 'organization', 'length']\n\n\nclass SignageManagementEdgeJsonList(MapEntityJsonList, SignageManagementEdgeList):\n    pass\n\n\nclass SignageManagementEdgeFormatList(MapEntityFormat, SignageManagementEdgeList):\n    pass\n\n\nclass SignageManagementEdgeDetail(MapEntityDetail):\n    queryset = SignageManagementEdge.objects.existing()\n\n\nclass SignageManagementEdgeDocument(MapEntityDocument):\n    model = SignageManagementEdge\n\n\nclass SignageManagementEdgeCreate(CreateFromTopologyMixin, MapEntityCreate):\n    model = SignageManagementEdge\n    form_class = SignageManagementEdgeForm\n\n\nclass SignageManagementEdgeUpdate(MapEntityUpdate):\n    queryset = SignageManagementEdge.objects.existing()\n    form_class = SignageManagementEdgeForm\n\n\nclass SignageManagementEdgeDelete(MapEntityDelete):\n    model = SignageManagementEdge\n", "path": "geotrek/land/views.py"}]}