Skip to content
Snippets Groups Projects
Commit a22d17af authored by Jesper Zedlitz's avatar Jesper Zedlitz
Browse files

Merge branch '12-doppelte-gemeinden-in-der-auswahlliste-raumbezug' into 'dev'

Refactor get_spatial_for_selection() to ensure unique values and prioritize municipality keys

See merge request !42
parents 233514d5 694cd1c8
No related branches found
No related tags found
2 merge requests!48Merge dev into master,!42Refactor get_spatial_for_selection() to ensure unique values and prioritize municipality keys
...@@ -134,13 +134,34 @@ def get_spatial_for_selection(): ...@@ -134,13 +134,34 @@ def get_spatial_for_selection():
file_path = config.get('ckanext.odsh.spatial.mapping', extension_path + '/resources/schleswig-holstein_geojson.csv') file_path = config.get('ckanext.odsh.spatial.mapping', extension_path + '/resources/schleswig-holstein_geojson.csv')
with open(file_path, newline='') as mapping_file: with open(file_path, newline='') as mapping_file:
cr = csv.reader(mapping_file, delimiter="\t") cr = csv.reader(mapping_file, delimiter="\t")
spatial_mapping = list() spatial_mapping = list(cr)
for row in cr:
key = row[0] unique_mapping = []
value = row[1] seen_values = set()
spatial_mapping.append({'key':key, 'value':value}) for key, value, _ in spatial_mapping:
spatial_mapping.append({'key':'', 'value':''}) if value in seen_values:
return spatial_mapping continue # Skip if the value has already been seen
if "municipalityKey" in key:
unique_mapping.append({'key': key, 'value': value})
else:
# Check if there is a municipality key entry for the value
municipality_entry = next(
(entry for entry in spatial_mapping if entry[1] == value and "municipalityKey" in entry[0]),
None
)
if municipality_entry:
# If a municipality key entry exists, use it instead of the current key
unique_mapping.append({'key': municipality_entry[0], 'value': value})
else:
# Otherwise, use the current key
unique_mapping.append({'key': key, 'value': value})
seen_values.add(value)
unique_mapping.append({'key': '', 'value': ''})
return unique_mapping
def get_subject_for_selection(): def get_subject_for_selection():
SUBJECT_MAPPING = load_subject_mapping() SUBJECT_MAPPING = load_subject_mapping()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment