0001-maps-add-possibility-to-filter-geojson-data-16977.patch
combo/apps/maps/models.py | ||
---|---|---|
100 | 100 |
features = data['features'] |
101 | 101 |
else: |
102 | 102 |
features = data |
103 | ||
104 |
if request.GET.get('q'): |
|
105 |
query = slugify(request.GET['q']) |
|
106 | ||
107 |
def match(feature): |
|
108 |
for geo_property in feature['properties'].values(): |
|
109 |
if not isinstance(geo_property, basestring): |
|
110 |
continue |
|
111 |
if query in slugify(geo_property): |
|
112 |
return True |
|
113 |
return False |
|
114 | ||
115 |
features = [x for x in features if match(x)] |
|
116 | ||
103 | 117 |
for feature in features: |
104 | 118 |
feature['properties']['layer'] = { |
105 | 119 |
'colour': self.marker_colour, |
tests/test_maps_cells.py | ||
---|---|---|
22 | 22 |
"features": [ |
23 | 23 |
{ |
24 | 24 |
"type": "Feature", |
25 |
"properties": {}, |
|
25 |
"properties": { |
|
26 |
"name": "Foo" |
|
27 |
}, |
|
28 |
"geometry": { |
|
29 |
"type": "Point", |
|
30 |
"coordinates": [ |
|
31 |
2.548828125, |
|
32 |
48.83579746243093 |
|
33 |
] |
|
34 |
} |
|
35 |
}, |
|
36 |
{ |
|
37 |
"type": "Feature", |
|
38 |
"properties": { |
|
39 |
"name": "Bar" |
|
40 |
}, |
|
26 | 41 |
"geometry": { |
27 | 42 |
"type": "Point", |
28 | 43 |
"coordinates": [ |
... | ... | |
147 | 162 |
json=lambda: json.loads(SAMPLE_GEOJSON_CONTENT), |
148 | 163 |
status_code=200) |
149 | 164 |
resp = client.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id})) |
165 |
assert len(json.loads(resp.content)['features']) == 2 |
|
150 | 166 |
assert requests_get.call_count == 1 |
151 | 167 |
resp = client.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id})) |
152 | 168 |
assert requests_get.call_count == 1 # cache was used |
... | ... | |
190 | 206 |
resp = client.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id})) |
191 | 207 |
assert 'orig=combo' in requests_get.call_args[0][1] |
192 | 208 |
assert not 'email=admin%40localhost&' in requests_get.call_args[0][1] |
209 | ||
210 |
# check query on geojson |
|
211 |
layer.geojson_url = 'http://example.org/geojson?t5' |
|
212 |
layer.include_user_identifier = False |
|
213 |
layer.save() |
|
214 |
with mock.patch('combo.utils.RequestsSession.request') as requests_get: |
|
215 |
requests_get.return_value = mock.Mock( |
|
216 |
content=SAMPLE_GEOJSON_CONTENT, |
|
217 |
json=lambda: json.loads(SAMPLE_GEOJSON_CONTENT), |
|
218 |
status_code=200) |
|
219 |
resp = client.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id}) + '?q=bar') |
|
220 |
assert len(json.loads(resp.content)['features']) == 1 |
|
221 |
assert 'orig=combo' in requests_get.call_args[0][1] |
|
222 |
assert not 'email=admin%40localhost&' in requests_get.call_args[0][1] |
tests/test_maps_manager.py | ||
---|---|---|
78 | 78 |
test_add_layer(app, admin_user) |
79 | 79 |
layer = MapLayer.objects.get() |
80 | 80 |
mocked_response = mock.Mock() |
81 |
mock_request.GET = {} |
|
81 | 82 |
mocked_response.json.return_value = [{'type': 'Feature', |
82 | 83 |
'geometry': {'type': 'Point', |
83 | 84 |
'coordinates': [2.3233688436448574, 48.83369263315934]}, |
84 |
- |