64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
import sys
|
|
import os
|
|
|
|
file_path = 'core/views.py'
|
|
with open(file_path, 'r') as f:
|
|
content = f.read()
|
|
|
|
old_code = """ # Prepare data for Google Map
|
|
map_data = [
|
|
{
|
|
'lat': h['latitude'],
|
|
'lng': h['longitude'],
|
|
'address': f"{h['address_street']}, {h['city']}, {h['state']}",
|
|
'voters': ", ".join([f"{v.first_name} {v.last_name}" for v in h['voters_with_sign']]),
|
|
'notes': ", ".join([f"{v.first_name}: {v.notes}" for v in h['voters_with_sign'] if v.notes]),
|
|
'voter_ids': [v.id for v in h['voters_with_sign']]
|
|
}
|
|
for h in households_list if h['latitude'] and h['longitude']
|
|
]"""
|
|
|
|
new_code = """ # Prepare data for Google Map
|
|
# Limit map markers to 3000 for performance
|
|
map_data = [
|
|
{
|
|
'lat': h['latitude'],
|
|
'lng': h['longitude'],
|
|
'address': f"{h['address_street']}, {h['city']}, {h['state']}",
|
|
'voters': ", ".join([f"{v.first_name} {v.last_name}" for v in h['voters_with_sign']]),
|
|
'notes': ", ".join([f"{v.first_name}: {v.notes}" for v in h['voters_with_sign'] if v.notes]),
|
|
'voter_ids': [v.id for v in h['voters_with_sign']]
|
|
}
|
|
for h in households_list[:3000] if h['latitude'] and h['longitude']
|
|
]"""
|
|
|
|
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)
|