JourneyJoker/localauth/helpers.py

18 lines
519 B
Python
Raw Normal View History

from django.conf import settings
from geopy.geocoders import Nominatim
2021-04-12 12:39:18 +00:00
import uuid
def name_to_coords(name):
geocoder = Nominatim(user_agent="JourneyJoker.at")
result = geocoder.geocode(name, exactly_one=True)
return result.latitude, result.longitude
def profile_to_coords(profile):
2021-04-12 12:39:18 +00:00
return name_to_coords("%s, %s, %s, %s" % (profile.address, profile.city, profile.zip, profile.country))
def upload_path(instance, filename):
return f'userfiles/{instance.user.id}/{uuid.uuid4()}/{filename}'