from django.conf import settings from geopy.geocoders import Nominatim import uuid import string from random import SystemRandom 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): return name_to_coords("%s, %s, %s, %s" % (profile.street, profile.city, profile.zip, profile.country)) def upload_path(instance, filename): try: user_id = instance.user.id except: user_id = "global" return f'userfiles/{user_id}/{uuid.uuid4()}/{filename}' def generate_token(length=6, characters=string.digits): return "".join([SystemRandom().choice(characters) for _ in range(length)])