2021-04-11 14:19:43 +00:00
|
|
|
from django.conf import settings
|
2021-04-08 09:30:19 +00:00
|
|
|
|
2021-04-11 14:19:43 +00:00
|
|
|
from geopy.geocoders import Nominatim
|
2021-04-08 09:30:19 +00:00
|
|
|
|
2021-04-12 12:39:18 +00:00
|
|
|
import uuid
|
2021-05-26 12:07:52 +00:00
|
|
|
import string
|
|
|
|
|
|
|
|
from random import SystemRandom
|
2021-04-12 12:39:18 +00:00
|
|
|
|
2021-04-11 14:19:43 +00:00
|
|
|
def name_to_coords(name):
|
|
|
|
geocoder = Nominatim(user_agent="JourneyJoker.at")
|
2021-04-08 09:30:19 +00:00
|
|
|
|
2021-04-11 14:19:43 +00:00
|
|
|
result = geocoder.geocode(name, exactly_one=True)
|
2021-04-08 09:30:19 +00:00
|
|
|
|
2021-04-11 14:19:43 +00:00
|
|
|
return result.latitude, result.longitude
|
|
|
|
|
|
|
|
def profile_to_coords(profile):
|
2021-04-17 18:35:29 +00:00
|
|
|
return name_to_coords("%s, %s, %s, %s" % (profile.street, profile.city, profile.zip, profile.country))
|
2021-04-12 12:39:18 +00:00
|
|
|
|
|
|
|
def upload_path(instance, filename):
|
2021-06-14 07:50:35 +00:00
|
|
|
try:
|
|
|
|
user_id = instance.user.id
|
|
|
|
except:
|
|
|
|
user_id = "global"
|
|
|
|
|
|
|
|
return f'userfiles/{user_id}/{uuid.uuid4()}/{filename}'
|
2021-05-26 12:07:52 +00:00
|
|
|
|
|
|
|
def generate_token(length=6, characters=string.digits):
|
|
|
|
return "".join([SystemRandom().choice(characters) for _ in range(length)])
|
|
|
|
|