0001-maps-move-properties-from-layer-to-cell-57760.patch
combo/apps/maps/forms.py | ||
---|---|---|
66 | 66 |
'icon_colour', |
67 | 67 |
'cache_duration', |
68 | 68 |
'include_user_identifier', |
69 |
'properties', |
|
70 | 69 |
'geojson_query_parameter', |
71 | 70 |
'geojson_accepts_circle_param', |
72 | 71 |
] |
combo/apps/maps/migrations/0017_auto_20211104_1559.py | ||
---|---|---|
1 |
# Generated by Django 2.2.19 on 2021-11-04 14:59 |
|
2 | ||
3 |
from django.db import migrations, models |
|
4 | ||
5 | ||
6 |
class Migration(migrations.Migration): |
|
7 | ||
8 |
dependencies = [ |
|
9 |
('maps', '0016_auto_20210927_1945'), |
|
10 |
] |
|
11 | ||
12 |
operations = [ |
|
13 |
migrations.AddField( |
|
14 |
model_name='map', |
|
15 |
name='properties', |
|
16 |
field=models.CharField( |
|
17 |
blank=True, |
|
18 |
help_text='List of properties to include, separated by commas', |
|
19 |
max_length=500, |
|
20 |
verbose_name='Properties', |
|
21 |
), |
|
22 |
), |
|
23 |
] |
combo/apps/maps/migrations/0018_auto_20211104_1559.py | ||
---|---|---|
1 |
# Generated by Django 2.2.19 on 2021-11-04 14:59 |
|
2 | ||
3 |
from django.db import migrations |
|
4 | ||
5 | ||
6 |
def populate_cell_properties(apps, schema_editor): |
|
7 |
MapLayer = apps.get_model('maps', 'MapLayer') |
|
8 |
Map = apps.get_model('maps', 'Map') |
|
9 | ||
10 |
for cell in Map.objects.all(): |
|
11 |
properties = [layer.properties for layer in cell.layers.all() if layer.properties.strip()] |
|
12 |
cell.properties = ','.join(properties) |
|
13 |
cell.save() |
|
14 | ||
15 | ||
16 |
def populate_layer_properties(apps, schema_editor): |
|
17 |
MapLayer = apps.get_model('maps', 'MapLayer') |
|
18 |
Map = apps.get_model('maps', 'Map') |
|
19 | ||
20 |
for cell in Map.objects.all(): |
|
21 |
for layer in cell.layers.all(): |
|
22 |
layer.properties = cell.properties |
|
23 |
layer.save() |
|
24 | ||
25 | ||
26 |
class Migration(migrations.Migration): |
|
27 | ||
28 |
dependencies = [ |
|
29 |
('maps', '0017_auto_20211104_1559'), |
|
30 |
] |
|
31 | ||
32 |
operations = [ |
|
33 |
migrations.RunPython(populate_cell_properties, populate_layer_properties), |
|
34 |
] |
combo/apps/maps/migrations/0019_auto_20211104_1603.py | ||
---|---|---|
1 |
# Generated by Django 2.2.19 on 2021-11-04 15:03 |
|
2 | ||
3 |
from django.db import migrations, models |
|
4 | ||
5 | ||
6 |
class Migration(migrations.Migration): |
|
7 | ||
8 |
dependencies = [ |
|
9 |
('maps', '0018_auto_20211104_1559'), |
|
10 |
] |
|
11 | ||
12 |
operations = [ |
|
13 |
migrations.RemoveField( |
|
14 |
model_name='maplayer', |
|
15 |
name='properties', |
|
16 |
), |
|
17 |
] |
combo/apps/maps/models.py | ||
---|---|---|
129 | 129 |
icon_colour = models.CharField(_('Icon colour'), max_length=7, default='#000000') |
130 | 130 |
cache_duration = models.PositiveIntegerField(_('Cache duration'), default=60, help_text=_('In seconds.')) |
131 | 131 |
include_user_identifier = models.BooleanField(_('Include user identifier in request'), default=True) |
132 |
properties = models.CharField( |
|
133 |
_('Properties'), |
|
134 |
max_length=500, |
|
135 |
blank=True, |
|
136 |
help_text=_('List of properties to include, separated by commas'), |
|
137 |
) |
|
138 | 132 |
geojson_query_parameter = models.CharField( |
139 | 133 |
_("Query parameter for fulltext requests"), |
140 | 134 |
max_length=100, |
... | ... | |
195 | 189 |
layer = next(serializers.deserialize('json', json.dumps([json_layer]), ignorenonexistent=True)) |
196 | 190 |
layer.save() |
197 | 191 | |
198 |
def get_geojson(self, request): |
|
192 |
def get_geojson(self, request, properties=''):
|
|
199 | 193 |
geojson_url = get_templated_url(self.geojson_url) |
200 | 194 | |
201 | 195 |
query_parameter = self.geojson_query_parameter |
... | ... | |
252 | 246 |
else: |
253 | 247 |
features = data |
254 | 248 | |
255 |
properties = [] |
|
256 |
if self.properties: |
|
257 |
properties = [x.strip() for x in self.properties.split(',')] |
|
249 |
properties = [x.strip() for x in properties.split(',') if x.strip()] |
|
250 |
if properties: |
|
258 | 251 |
for feature in features: |
259 | 252 |
if 'display_fields' in feature['properties']: |
260 | 253 |
# w.c.s. content, filter fields on varnames |
... | ... | |
375 | 368 |
_('Marker behaviour on click'), max_length=32, default='none', choices=MARKER_BEHAVIOUR_ONCLICK |
376 | 369 |
) |
377 | 370 |
layers = models.ManyToManyField(MapLayer, through='MapLayerOptions', verbose_name=_('Layers'), blank=True) |
371 |
properties = models.CharField( |
|
372 |
_('Properties'), |
|
373 |
max_length=500, |
|
374 |
blank=True, |
|
375 |
help_text=_('List of properties to include, separated by commas'), |
|
376 |
) |
|
378 | 377 | |
379 | 378 |
default_template_name = 'maps/map_cell.html' |
380 | 379 |
manager_form_template = 'maps/map_cell_form.html' |
... | ... | |
407 | 406 |
'max_zoom', |
408 | 407 |
'group_markers', |
409 | 408 |
'marker_behaviour_onclick', |
409 |
'properties', |
|
410 | 410 |
) |
411 | 411 |
return forms.models.modelform_factory(self.__class__, fields=fields) |
412 | 412 | |
... | ... | |
464 | 464 |
'icon': l.icon, |
465 | 465 |
'icon_colour': l.icon_colour, |
466 | 466 |
'marker_colour': l.marker_colour, |
467 |
'properties': [x.strip() for x in l.properties.split(',')],
|
|
467 |
'properties': [x.strip() for x in self.properties.split(',')],
|
|
468 | 468 |
} |
469 | 469 |
for l in self.layers.filter(kind='geojson') |
470 | 470 |
] |
combo/apps/maps/views.py | ||
---|---|---|
29 | 29 |
layer = get_object_or_404(cell.layers.all(), kind='geojson', slug=kwargs['layer_slug']) |
30 | 30 |
if not cell.page.is_visible(request.user) or not cell.is_visible(user=request.user): |
31 | 31 |
return HttpResponseForbidden() |
32 |
geojson = layer.get_geojson(request) |
|
32 |
geojson = layer.get_geojson(request, cell.properties)
|
|
33 | 33 |
content_type = 'application/json' |
34 | 34 |
return HttpResponse(json.dumps(geojson), content_type=content_type) |
tests/test_maps_cells.py | ||
---|---|---|
596 | 596 | |
597 | 597 |
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get: |
598 | 598 |
layer.geojson_url = 'http://example.org/geojson?t2' |
599 |
layer.properties = 'name, hop' |
|
600 | 599 |
layer.save() |
600 |
cell.properties = 'name, hop' |
|
601 |
cell.save() |
|
601 | 602 |
requests_get.return_value = mock.Mock( |
602 | 603 |
content=SAMPLE_GEOJSON_CONTENT, json=lambda: json.loads(SAMPLE_GEOJSON_CONTENT), status_code=200 |
603 | 604 |
) |
... | ... | |
608 | 609 | |
609 | 610 |
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get: |
610 | 611 |
layer.geojson_url = 'http://example.org/geojson?t3' |
611 |
layer.properties = '' |
|
612 | 612 |
layer.save() |
613 |
cell.properties = '' |
|
614 |
cell.save() |
|
613 | 615 |
requests_get.return_value = mock.Mock( |
614 | 616 |
content=SAMPLE_WCS_GEOJSON_CONTENT, |
615 | 617 |
json=lambda: json.loads(SAMPLE_WCS_GEOJSON_CONTENT), |
... | ... | |
621 | 623 | |
622 | 624 |
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get: |
623 | 625 |
layer.geojson_url = 'http://example.org/geojson?t4' |
624 |
layer.properties = 'id' |
|
625 | 626 |
layer.save() |
627 |
cell.properties = 'id' |
|
628 |
cell.save() |
|
626 | 629 |
requests_get.return_value = mock.Mock( |
627 | 630 |
content=SAMPLE_WCS_GEOJSON_CONTENT, |
628 | 631 |
json=lambda: json.loads(SAMPLE_WCS_GEOJSON_CONTENT), |
tests/test_maps_manager.py | ||
---|---|---|
88 | 88 |
assert 'marker_colour' not in resp.context['form'].fields |
89 | 89 |
assert 'icon' not in resp.context['form'].fields |
90 | 90 |
assert 'icon_colour' not in resp.context['form'].fields |
91 |
assert 'properties' not in resp.context['form'].fields |
|
92 | 91 |
assert 'geojson_query_parameter' not in resp.context['form'].fields |
93 | 92 |
assert 'geojson_accepts_circle_param' not in resp.context['form'].fields |
94 | 93 |
resp.forms[0]['label'] = 'Test' |
... | ... | |
150 | 149 |
assert 'marker_colour' not in resp.context['form'] |
151 | 150 |
assert 'icon' not in resp.context['form'] |
152 | 151 |
assert 'icon_colour' not in resp.context['form'] |
153 |
assert 'properties' not in resp.context['form'] |
|
154 | 152 |
resp.forms[0]['tiles_default'] = False |
155 | 153 |
resp = resp.forms[0].submit() |
156 | 154 |
assert resp.location.endswith('/manage/maps/') |
157 |
- |