feat: Add instance health check, allow clean locations for rescue orgs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from django.core.management import BaseCommand
|
||||
from fellchensammlung.models import AdoptionNotice, Location
|
||||
from fellchensammlung.tools.geo import clean_locations
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -14,19 +15,4 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
adoption_notices_without_location = AdoptionNotice.objects.filter(location__isnull=True)
|
||||
num_of_all = AdoptionNotice.objects.count()
|
||||
num_without_location = adoption_notices_without_location.count()
|
||||
print(f"From {num_of_all} there are {num_without_location} adoption notices without location "
|
||||
f"({num_without_location/num_of_all*100:.2f}%)")
|
||||
for adoption_notice in adoption_notices_without_location:
|
||||
print(f"Searching {adoption_notice.location_string} in Nominatim")
|
||||
location = Location.get_location_from_string(adoption_notice.location_string)
|
||||
if location:
|
||||
adoption_notice.location = location
|
||||
adoption_notice.save()
|
||||
|
||||
adoption_notices_without_location_new = AdoptionNotice.objects.filter(location__isnull=True)
|
||||
num_without_location_new = adoption_notices_without_location_new.count()
|
||||
num_new = num_without_location - num_without_location_new
|
||||
print(f"Added {num_new} new locations")
|
||||
clean_locations(quiet=False)
|
Reference in New Issue
Block a user