Projet

Général

Profil

0001-maps-keep-the-marker-s-colour-property-58072.patch

Benjamin Dauvergne, 16 novembre 2021 13:09

Télécharger (4,54 ko)

Voir les différences:

Subject: [PATCH] maps: keep the marker's colour property (#58072)

 combo/apps/maps/models.py |  7 ++++++-
 tests/test_maps_cells.py  | 39 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 42 insertions(+), 4 deletions(-)
combo/apps/maps/models.py
252 252
        else:
253 253
            features = data
254 254

  
255
        properties = []
256 255
        if self.properties:
257 256
            properties = [x.strip() for x in self.properties.split(',')]
258 257
            for feature in features:
258
                property_values = feature['properties']
259 259
                if 'display_fields' in feature['properties']:
260 260
                    # w.c.s. content, filter fields on varnames
261 261
                    feature['properties']['display_fields'] = [
......
266 266
                    feature['properties'] = dict(
267 267
                        [x for x in feature['properties'].items() if x[0] in properties]
268 268
                    )
269
                    # keep the property for marker's colour
270
                    if self.marker_colour and not self.marker_colour.startswith('#'):
271
                        first_dotted_name = self.marker_colour.split('.')[0]
272
                        if first_dotted_name in property_values:
273
                            feature['properties'][first_dotted_name] = property_values[first_dotted_name]
269 274

  
270 275
        if request and not self.geojson_accepts_circle_param and distance_params:
271 276
            geod = pyproj.Geod(ellps='WGS84')
tests/test_maps_cells.py
22 22
      "type": "Feature",
23 23
      "properties": {
24 24
         "name": "Foo",
25
         "extra": "Baz"
25
         "extra": "Baz",
26
         "color": "#0a0a0a",
27
         "subcolor": {
28
           "color": "#0a0a0a"
29
         }
26 30
      },
27 31
      "geometry": {
28 32
        "type": "Point",
......
105 109
        layer = MapLayer()
106 110
        layer.label = 'bicycles'
107 111
        layer.geojson_url = 'http://example.org/geojson'
108
        layer.marker_colour = 'FF0000'
112
        layer.marker_colour = '#FF0000'
109 113
        layer.icon = 'fa-bicycle'
110
        layer.icon_colour = '0000FF'
114
        layer.icon_colour = '#0000FF'
111 115
        layer.save()
112 116
    return layer
113 117

  
......
606 610
        assert 'name' in features[0]['properties']
607 611
        assert 'extra' not in features[0]['properties']
608 612

  
613
    with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get:
614
        layer.geojson_url = 'http://example.org/geojson?t2'
615
        layer.properties = 'name, hop'
616
        layer.marker_colour = 'color'
617
        layer.save()
618
        requests_get.return_value = mock.Mock(
619
            content=SAMPLE_GEOJSON_CONTENT, json=lambda: json.loads(SAMPLE_GEOJSON_CONTENT), status_code=200
620
        )
621
        resp = app.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id, 'layer_slug': layer.slug}))
622
        features = json.loads(resp.text)['features']
623
        assert 'name' in features[0]['properties']
624
        assert 'extra' not in features[0]['properties']
625
        assert 'color' in features[0]['properties']
626

  
627
    with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get:
628
        layer.geojson_url = 'http://example.org/geojson?t2'
629
        layer.properties = 'name, hop'
630
        layer.marker_colour = 'subcolor.color'
631
        layer.save()
632
        requests_get.return_value = mock.Mock(
633
            content=SAMPLE_GEOJSON_CONTENT, json=lambda: json.loads(SAMPLE_GEOJSON_CONTENT), status_code=200
634
        )
635
        resp = app.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id, 'layer_slug': layer.slug}))
636
        features = json.loads(resp.text)['features']
637
        assert 'name' in features[0]['properties']
638
        assert 'extra' not in features[0]['properties']
639
        assert 'subcolor' in features[0]['properties']
640
        assert 'color' in features[0]['properties']['subcolor']
641

  
609 642
    with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get:
610 643
        layer.geojson_url = 'http://example.org/geojson?t3'
611 644
        layer.properties = ''
612
-