Skip to content

Commit

Permalink
Merge pull request #513 from maykinmedia/feature/1155-link-from-map-t…
Browse files Browse the repository at this point in the history
…o-location-view

[#1155] Link from map to location view
  • Loading branch information
alextreme authored Mar 6, 2023
2 parents 129d4ea + 4a55b65 commit 95cbe9d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/open_inwoner/js/components/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,26 @@ class Map {
* @return {string}
*/
featureToHTML(feature) {
const { name, ...properties } = feature.properties
const { name, location_url, ...properties } = feature.properties
const displayName = name ? escapeHTML(name) : ''
const locationDetailView = location_url ? escapeHTML(location_url) : ''
let title = ''
let finalHTML = ``

if (locationDetailView) {
title = `<a href="${locationDetailView}">${displayName}</a>`
} else {
title = displayName
}

Object.entries(properties).forEach((property) => {
finalHTML += `<p class="p">${escapeHTML(property[1])}</p>`
})

return `
<div class="leaflet-content-name">
<h4 class="h4">
${displayName}
${title}
</h4>
</div>
<div class="leaflet-content-details p--no-margin">
Expand Down
6 changes: 6 additions & 0 deletions src/open_inwoner/pdc/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,16 @@ def __str__(self) -> str:
def get_geojson_feature(self, stringify: bool = True) -> Union[str, dict]:
feature = super().get_geojson_feature(False)

if feature.get("properties"):
feature["properties"]["location_url"] = self.get_absolute_url()

if stringify:
return json.dumps(feature)
return feature

def get_absolute_url(self) -> str:
return reverse("pdc:location_detail", kwargs={"uuid": self.uuid})


class ProductCondition(OrderedModel):
name = models.CharField(
Expand Down
31 changes: 31 additions & 0 deletions src/open_inwoner/pdc/tests/test_product_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_get_geojson_feature(self):
"address_line_2": "1015CJ Amsterdam",
"email": "[email protected]",
"phonenumber": "+31666767676",
"location_url": product_location.get_absolute_url(),
},
}
),
Expand Down Expand Up @@ -170,6 +171,7 @@ def test_queryset_get_geojson_feature_collection(self):
"address_line_2": "7411KT Deventer",
"email": "[email protected]",
"phonenumber": "+31999767676",
"location_url": product_location_1.get_absolute_url(),
},
},
{
Expand All @@ -184,6 +186,7 @@ def test_queryset_get_geojson_feature_collection(self):
"address_line_2": "1015KL Amsterdam",
"email": "[email protected]",
"phonenumber": "+31666767676",
"location_url": product_location_2.get_absolute_url(),
},
},
],
Expand Down Expand Up @@ -269,3 +272,31 @@ def test_shown_products_in_location_detail(self):

# check the draft product is not shown
self.assertEqual(products.get(), published_product)


class TestLocationViewThroughMap(WebTest):
def test_product_location_link_is_rendered_on_home_page(self):
product = ProductFactory()
product_location = ProductLocationFactory()
product.locations.add(product_location)

response = self.app.get(reverse("root"))

self.assertContains(
response,
reverse("pdc:location_detail", kwargs={"uuid": product_location.uuid}),
)

def test_product_location_link_is_rendered_on_product_page(self):
product = ProductFactory()
product_location = ProductLocationFactory()
product.locations.add(product_location)

response = self.app.get(
reverse("pdc:product_detail", kwargs={"slug": product.slug})
)

self.assertContains(
response,
reverse("pdc:location_detail", kwargs={"uuid": product_location.uuid}),
)

0 comments on commit 95cbe9d

Please sign in to comment.