37769-vm/patch_door_visits_view.py
2026-05-30 08:01:02 +00:00

71 lines
2.6 KiB
Python

import sys
import os
file_path = 'core/views.py'
with open(file_path, 'r') as f:
content = f.read()
old_code = """ # Optimization: Map data should only be for visible results or limited
# We still keep the limit of 3000 for map
map_data = []
if len(households_list) < 3000:
for h in households_list:
if h['latitude'] and h['longitude']:
map_data.append({
'lat': h['latitude'],
'lng': h['longitude'],
'address_street': h['address_street'],
'city': h['city'],
'state': h['state'],
'zip_code': h['zip_code'],
'address': f"{h['address_street']}, {h['city']}",
'voters': ", ".join([f"{v['first_name']} {v['last_name']}" for v in h['target_voters']])
})"""
new_code = """ # Optimization: Map data should only be for visible results or limited
# We still keep the limit of 3000 for map
map_data = []
# Always try to show up to 3000 markers instead of showing 0 if count > 3000
for h in households_list[:3000]:
if h['latitude'] and h['longitude']:
map_data.append({
'lat': h['latitude'],
'lng': h['longitude'],
'address_street': h['address_street'],
'city': h['city'],
'state': h['state'],
'zip_code': h['zip_code'],
'address': f"{h['address_street']}, {h['city']}",
'voters': ", ".join([f"{v['first_name']} {v['last_name']}" for v in h['target_voters']])
})"""
content = content.replace(old_code, new_code)
old_context = """ context = {
'selected_tenant': tenant,
'households': households_page,
'district_filter': district_filter,
'neighborhood_filter': neighborhood_filter,
'address_filter': address_filter,
'city_filter': city_filter,
'map_data_json': json.dumps(map_data),
'GOOGLE_MAPS_API_KEY': getattr(settings, 'GOOGLE_MAPS_API_KEY', ''),
}"""
new_context = """ context = {
'selected_tenant': tenant,
'households': households_page,
'district_filter': district_filter,
'neighborhood_filter': neighborhood_filter,
'address_filter': address_filter,
'city_filter': city_filter,
'map_data_json': json.dumps(map_data),
'map_limit_reached': len(households_list) > 3000,
'GOOGLE_MAPS_API_KEY': getattr(settings, 'GOOGLE_MAPS_API_KEY', ''),
}"""
content = content.replace(old_context, new_context)
with open(file_path, 'w') as f:
f.write(content)