Make index more privacy friendly
This commit is contained in:
parent
e165852a90
commit
eace2143be
12 changed files with 20072 additions and 22 deletions
|
@ -24,4 +24,8 @@ ENABLE_S3_STORAGE = False
|
||||||
|
|
||||||
AWS_ACCESS_KEY_ID = "AWS Key ID"
|
AWS_ACCESS_KEY_ID = "AWS Key ID"
|
||||||
AWS_SECRET_ACCESS_KEY = "AWS Secret Key"
|
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"]
|
0
public/places/__init__.py
Normal file
0
public/places/__init__.py
Normal file
15
public/places/api.py
Normal file
15
public/places/api.py
Normal 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
9
public/places/urls.py
Normal 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
13
public/places/views.py
Normal 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)
|
|
@ -1,4 +1,4 @@
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
from .views import HomeView
|
from .views import HomeView
|
||||||
|
|
||||||
|
@ -6,4 +6,5 @@ app_name = "frontend"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', HomeView.as_view(), name="home"),
|
path('', HomeView.as_view(), name="home"),
|
||||||
|
path('api/places/', include("public.places.urls"), name="places"),
|
||||||
]
|
]
|
|
@ -13,4 +13,5 @@ django-storages
|
||||||
boto3
|
boto3
|
||||||
geopy
|
geopy
|
||||||
django-phonenumber-field
|
django-phonenumber-field
|
||||||
phonenumbers
|
phonenumbers
|
||||||
|
googlemaps
|
|
@ -1,18 +1 @@
|
||||||
var input = document.getElementById('id_destination_name');
|
$("#id_destination_name").autocomplete({ source: "/api/places/autocomplete" });
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
1311
static/vendor/css/jquery-ui.css
vendored
Normal file
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
18706
static/vendor/js/jquery-ui.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,6 +4,9 @@
|
||||||
{% load testimonials %}
|
{% load testimonials %}
|
||||||
{% load dbsetting %}
|
{% load dbsetting %}
|
||||||
{% load offeroptions %}
|
{% load offeroptions %}
|
||||||
|
{% block "styles" %}
|
||||||
|
<link rel="stylesheet" href="{% static "vendor/css/jquery-ui.css" %}">
|
||||||
|
{% endblock %}
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
<!--========================= FLEX SLIDER =====================-->
|
<!--========================= FLEX SLIDER =====================-->
|
||||||
<section class="flexslider-container" id="flexslider-container-1">
|
<section class="flexslider-container" id="flexslider-container-1">
|
||||||
|
@ -291,6 +294,6 @@
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block "scripts" %}
|
{% 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>
|
<script src="{% static "frontend/js/custom-autocomplete.js" %}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,6 +2,8 @@ from django.contrib.admin import AdminSite
|
||||||
from django.utils.translation import ugettext_lazy
|
from django.utils.translation import ugettext_lazy
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
from dbsettings.models import Setting
|
||||||
|
|
||||||
class JokerAdmin(AdminSite):
|
class JokerAdmin(AdminSite):
|
||||||
# Text to put at the end of each page's <title>.
|
# Text to put at the end of each page's <title>.
|
||||||
site_title = ugettext_lazy('JourneyJoker Administration')
|
site_title = ugettext_lazy('JourneyJoker Administration')
|
||||||
|
@ -13,3 +15,5 @@ class JokerAdmin(AdminSite):
|
||||||
index_title = ugettext_lazy('JourneyJoker Administration')
|
index_title = ugettext_lazy('JourneyJoker Administration')
|
||||||
|
|
||||||
joker_admin = JokerAdmin()
|
joker_admin = JokerAdmin()
|
||||||
|
|
||||||
|
joker_admin.register(Setting)
|
Loading…
Reference in a new issue