Skip to content

Commit

Permalink
revert geolocation customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Nov 18, 2024
1 parent c28a696 commit f49897d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 134 deletions.
45 changes: 1 addition & 44 deletions src/iosanita/contenttypes/indexers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,9 @@ def get_geolocation_data(context):
geolocation = getattr(context.aq_base, "geolocation", None)
if not geolocation:
return {}

title = getattr(context.aq_base, "nome_sede", "") or context.title
street = getattr(context.aq_base, "street", "")
city = getattr(context.aq_base, "city", "")
provincia = getattr(context.aq_base, "provincia", "")

address = ""

if street:
address += f"{street}"
if city:
address += f" {city}"
if provincia:
address += f" ({provincia})"

return {
"latitude": geolocation.latitude,
"longitude": geolocation.longitude,
"title": title,
"address": re.sub(r"\s+", " ", address),
}


Expand Down Expand Up @@ -71,33 +54,7 @@ def provincia(context):

@indexer(IDexterityContent)
def geolocation(context):
data = get_geolocation_data(context)
if data:
return [data]
return []


@indexer(IPersona)
def geolocation_persona(context):
"""
Persona can have multiple locations
"""
res = []
local_data = get_geolocation_data(context)
if local_data:
res.append(local_data)

for field in ["struttura_in_cui_opera", "struttura_ricevimento"]:
value = getattr(context.aq_base, field, [])
if not value:
continue
for ref in value:
ref_obj = ref.to_object
if ref_obj:
data = get_geolocation_data(ref_obj)
if data:
res.append(data)
return res
return get_geolocation_data(context)


@indexer(IDexterityContent)
Expand Down
4 changes: 0 additions & 4 deletions src/iosanita/contenttypes/indexers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
factory=".common.geolocation"
name="geolocation"
/>
<adapter
factory=".common.geolocation_persona"
name="geolocation"
/>
<adapter
factory=".common.has_geolocation"
name="has_geolocation"
Expand Down
89 changes: 3 additions & 86 deletions src/iosanita/contenttypes/tests/test_custom_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_geolocation_metadata_is_empty_if_no_geolocation_set(self):
)

brain = api.content.find(UID=struttura.UID())[0]
self.assertEqual(brain.geolocation, [])
self.assertEqual(brain.geolocation, {})

def test_geolocation_metadata_has_geolocation_data(self):
struttura = api.content.create(
Expand All @@ -219,90 +219,7 @@ def test_geolocation_metadata_has_geolocation_data(self):
)

brain = api.content.find(UID=struttura.UID())[0]
self.assertEqual(len(brain.geolocation), 1)
self.assertEqual(brain.geolocation["latitude"], struttura.geolocation.latitude)
self.assertEqual(
brain.geolocation[0]["latitude"], struttura.geolocation.latitude
brain.geolocation["longitude"], struttura.geolocation.longitude
)
self.assertEqual(
brain.geolocation[0]["longitude"], struttura.geolocation.longitude
)

def test_geolocation_metadata_has_content_address_with_street_city_provincia(self):
struttura = api.content.create(
container=self.portal,
type="Struttura",
title="Struttura",
street="Elm Street, 4",
city="Springwood",
provincia="FE",
geolocation=Geolocation(latitude=10, longitude=20),
)

brain = api.content.find(UID=struttura.UID())[0]
self.assertEqual(len(brain.geolocation), 1)
self.assertEqual(
brain.geolocation[0]["address"], "Elm Street, 4 Springwood (FE)"
)

def test_geolocation_metadata_has_content_nome_sede_or_title(self):
struttura = api.content.create(
container=self.portal,
type="Struttura",
title="Struttura",
geolocation=Geolocation(latitude=10, longitude=20),
)

brain = api.content.find(UID=struttura.UID())[0]
self.assertEqual(len(brain.geolocation), 1)
self.assertEqual(brain.geolocation[0]["title"], struttura.title)

struttura.nome_sede = "Nightmare, inc."
struttura.reindexObject()

brain = api.content.find(UID=struttura.UID())[0]
self.assertEqual(brain.geolocation[0]["title"], struttura.nome_sede)

def test_geolocation_metadata_for_persona_has_a_list_of_values_if_set(self):
struttura1 = api.content.create(
container=self.portal,
type="Struttura",
title="Struttura",
geolocation=Geolocation(latitude=11, longitude=11),
)
struttura2 = api.content.create(
container=self.portal,
type="Struttura",
title="Struttura",
geolocation=Geolocation(latitude=22, longitude=22),
)
struttura3 = api.content.create(
container=self.portal,
type="Struttura",
title="Struttura",
geolocation=Geolocation(latitude=33, longitude=33),
)

persona = api.content.create(
container=self.portal,
type="Persona",
title="persona",
geolocation=Geolocation(latitude=99, longitude=99),
struttura_ricevimento=[
RelationValue(self.intids.getId(struttura1)),
RelationValue(self.intids.getId(struttura2)),
],
struttura_in_cui_opera=[RelationValue(self.intids.getId(struttura3))],
)

brain = api.content.find(UID=persona.UID())[0]

geolocations = brain.geolocation
self.assertEqual(len(geolocations), 4)
self.assertEqual(geolocations[0]["latitude"], persona.geolocation.latitude)
self.assertEqual(geolocations[0]["longitude"], persona.geolocation.longitude)
self.assertEqual(geolocations[1]["latitude"], struttura3.geolocation.latitude)
self.assertEqual(geolocations[1]["longitude"], struttura3.geolocation.longitude)
self.assertEqual(geolocations[2]["latitude"], struttura1.geolocation.latitude)
self.assertEqual(geolocations[2]["longitude"], struttura1.geolocation.longitude)
self.assertEqual(geolocations[3]["latitude"], struttura2.geolocation.latitude)
self.assertEqual(geolocations[3]["longitude"], struttura2.geolocation.longitude)

0 comments on commit f49897d

Please sign in to comment.