Make index more privacy friendly

This commit is contained in:
Kumi 2021-04-17 08:30:26 +02:00
parent e165852a90
commit eace2143be
12 changed files with 20072 additions and 22 deletions

View file

@ -24,4 +24,8 @@ ENABLE_S3_STORAGE = False
AWS_ACCESS_KEY_ID = "AWS Key ID"
AWS_SECRET_ACCESS_KEY = "AWS Secret Key"
AWS_STORAGE_BUCKET_NAME = "AWS Bucket"
AWS_STORAGE_BUCKET_NAME = "AWS Bucket"
# Countries the app can be used in (currently no more than 5 due to Google Maps restrictions)
JOKER_COUNTRIES = ["AT"]

View file

15
public/places/api.py Normal file
View file

@ -0,0 +1,15 @@
from django.utils.translation import get_language
from django.conf import settings
import googlemaps
from dbsettings.functions import getValue
class GoogleAPI:
def __init__(self, api_key=None):
api_key = api_key or getValue("google.api.key")
self.api = googlemaps.Client(key=api_key)
def autocomplete(self, term, types="(cities)", language=get_language(), countries=settings.JOKER_COUNTRIES):
response = self.api.places_autocomplete(term, types=types, language=language, components={"country": countries})
return [result["description"] for result in response]

9
public/places/urls.py Normal file
View file

@ -0,0 +1,9 @@
from django.urls import path
from .views import PlacesAutocompleteView
app_name = "places"
urlpatterns = [
path('autocomplete', PlacesAutocompleteView.as_view(), name="autocomplete"),
]

13
public/places/views.py Normal file
View file

@ -0,0 +1,13 @@
from django.views.generic import View
from django.http import JsonResponse
from .api import GoogleAPI
class PlacesAutocompleteView(View):
def get(self, request, *args, **kwargs):
if term := request.GET.get("term"):
api = GoogleAPI()
results = api.autocomplete(term)
else:
results = []
return JsonResponse(results, safe=False)

View file

@ -1,4 +1,4 @@
from django.urls import path
from django.urls import path, include
from .views import HomeView
@ -6,4 +6,5 @@ app_name = "frontend"
urlpatterns = [
path('', HomeView.as_view(), name="home"),
path('api/places/', include("public.places.urls"), name="places"),
]

View file

@ -13,4 +13,5 @@ django-storages
boto3
geopy
django-phonenumber-field
phonenumbers
phonenumbers
googlemaps

View file

@ -1,18 +1 @@
var input = document.getElementById('id_destination_name');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'at'},
language: language
};
autocomplete = new google.maps.places.Autocomplete(input, options);
autocomplete.setFields(['geometry']);
autocomplete.addListener('place_changed', fillInAddress);
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
$("#id_destination_lat").val(place.geometry.location.lat);
$("#id_destination_lon").val(place.geometry.location.lon);
}
$("#id_destination_name").autocomplete({ source: "/api/places/autocomplete" });

1311
static/vendor/css/jquery-ui.css vendored Normal file

File diff suppressed because it is too large Load diff

18706
static/vendor/js/jquery-ui.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,9 @@
{% load testimonials %}
{% load dbsetting %}
{% load offeroptions %}
{% block "styles" %}
<link rel="stylesheet" href="{% static "vendor/css/jquery-ui.css" %}">
{% endblock %}
{% block "content" %}
<!--========================= FLEX SLIDER =====================-->
<section class="flexslider-container" id="flexslider-container-1">
@ -291,6 +294,6 @@
{% endblock %}
{% block "scripts" %}
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key={% dbsetting "google.api.key" %}&libraries=places"></script>
<script src="{% static "vendor/js/jquery-ui.js" %}"></script>
<script src="{% static "frontend/js/custom-autocomplete.js" %}"></script>
{% endblock %}

View file

@ -2,6 +2,8 @@ from django.contrib.admin import AdminSite
from django.utils.translation import ugettext_lazy
from django.contrib.auth import get_user_model
from dbsettings.models import Setting
class JokerAdmin(AdminSite):
# Text to put at the end of each page's <title>.
site_title = ugettext_lazy('JourneyJoker Administration')
@ -13,3 +15,5 @@ class JokerAdmin(AdminSite):
index_title = ugettext_lazy('JourneyJoker Administration')
joker_admin = JokerAdmin()
joker_admin.register(Setting)