Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial location collection #2

Merged
merged 5 commits into from
Oct 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ShopAssistant/ShopAssistant/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import posixpath

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


Expand All @@ -25,7 +27,9 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['a06eef97.ngrok.io',
'localhost',
'127.0.0.1']


# Application definition
Expand All @@ -37,6 +41,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'frontend',
'database',
]

Expand Down Expand Up @@ -123,3 +128,5 @@
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ['static']))
4 changes: 3 additions & 1 deletion ShopAssistant/ShopAssistant/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include


urlpatterns = [
path('admin/', admin.site.urls),
path('', include('frontend.urls')),
]
2 changes: 1 addition & 1 deletion ShopAssistant/frontend/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
47 changes: 47 additions & 0 deletions ShopAssistant/frontend/static/js/location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*

button.onclick = function () {
let startPos;

let geoSuccess = function (position) {
// Do magic with location
startPos = position;
document.getElementById('startLat').innerHTML = startPos.coords.latitude;
document.getElementById('startLon').innerHTML = startPos.coords.longitude;
};
let geoError = function (error) {
switch (error.code) {
case error.TIMEOUT:
// The user didn't accept the callout
console.log('DENIED!');
break;
}
};

navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
};
*/
button = document.getElementById("mainButton");

let startPos;
let geoOptions = {
enableHighAccuracy: true,
maximumAge: 60 * 1000, // get new position data every minute
};

let geoSuccess = function (position) {
startPos = position;
console.log('updated pos');
document.getElementById('startLat').innerHTML = startPos.coords.latitude;
document.getElementById('startLon').innerHTML = startPos.coords.longitude;
};
let geoError = function (error) {
console.log('Error occurred. Error code: ' + error.code);
// error.code can be:
// 0: unknown error
// 1: permission denied
// 2: position unavailable (error response from location provider)
// 3: timed out
};

let watchId = navigator.geolocation.watchPosition(geoSuccess, geoError, geoOptions);
19 changes: 19 additions & 0 deletions ShopAssistant/frontend/templates/collector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Location</title>
{% load static %}
<link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet">
</head>
<body>
<button id="mainButton" type="button" class="btn btn-primary">Primary</button>

<p id="startLat">0</p><br>
<p id="startLon">0</p>
<!-- script at the end to load the page faster -->
{% load static %}
<script src="{% static "js/location.js" %}"></script>

</body>
</html>
7 changes: 7 additions & 0 deletions ShopAssistant/frontend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path

from . import views

urlpatterns = [
path('', views.index),
]
5 changes: 5 additions & 0 deletions ShopAssistant/frontend/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.shortcuts import render_to_response


def index(request):
return render_to_response('collector.html')
3 changes: 1 addition & 2 deletions ShopAssistant/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Django==2.2.6
psycopg2-binary==2.8.4
pytz==2019.3
sqlparse==0.3.0

sqlparse==0.3.0