Start development of gpslog module

This commit is contained in:
Kumi 2022-09-09 16:59:13 +00:00
parent 67c602ddcf
commit ac18f31d9a
6 changed files with 90 additions and 9 deletions

View file

@ -1,3 +1,39 @@
from django.db import models from django.contrib.gis.db import models
from django.contrib.auth import get_user_model
# Create your models here. from uuid import uuid4
class GPSTrack(models.Model):
id = models.UUIDField(default=uuid4, primary_key=True)
user = models.ForeignKey(get_user_model(), models.CASCADE)
class GPSToken(models.Model):
name = models.CharField(max_length=128, null=True, blank=True)
track = models.ForeignKey(GPSTrack, models.CASCADE)
token = models.UUIDField(default=uuid4)
# Permissions
read = models.BooleanField(default=False)
write = models.BooleanField(default=False)
history = models.BooleanField(default=False)
class GPSPoint(models.Model):
track = models.ForeignKey(GPSTrack, models.CASCADE)
point = models.PointField()
timestamp = models.DateTimeField()
token = models.ForeignKey(GPSToken, models.SET_NULL, null=True)
# Optional additional information
battery = models.DecimalField(
max_digits=5, decimal_places=2, null=True, blank=True)
accuracy = models.DecimalField(
max_digits=64, decimal_places=32, null=True, blank=True)
speed = models.DecimalField(
max_digits=64, decimal_places=32, null=True, blank=True)
bearing = models.DecimalField(
max_digits=64, decimal_places=61, null=True, blank=True)
satellites = models.IntegerField(null=True, blank=True)
user_agent = models.TextField(null=True, blank=True)

9
gpslog/urls.py Normal file
View file

@ -0,0 +1,9 @@
from .views import GPSLogView
from django.urls import path
app_name = "gpslog"
urlpatterns = [
path('<uuid:track>/<uuid:token>/', GPSLogView.as_view(), name="gpslog"),
]

View file

@ -1,3 +1,37 @@
from django.shortcuts import render from django.views import View
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.contrib.gis.geos import Point
# Create your views here. from .models import GPSTrack, GPSToken, GPSPoint
class GPSLogView(LoginRequiredMixin, View):
def dispatch(self, request, *args, **kwargs):
self.gps_track = get_object_or_404(GPSTrack, id=self.kwargs["track"])
self.gps_token = get_object_or_404(
GPSToken, track=self.gps_track, token=self.kwargs["token"])
if request.method == "POST" and not self.gps_token.write:
return self.http_method_not_allowed(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
# ?lat=47.07047834&lon=15.45140181&alt=427.04833984375&tst=1043419092&batt=23.0&acc=14.692631721496582&spd=0.0&dir=&sat=6
def get(self, request, *args, **kwargs):
if self.gps_token.write and all(field in request.GET for field in ("lat", "lon")):
lat = request.GET["lat"]
lon = request.GET["lon"]
alt = request.GET.get("alt", None)
point = Point(lat, lon, alt)
tst = request.GET.get("tst", timezone.now().timestamp())
def post(self, request, *args, **kwargs):
pass

View file

@ -22,6 +22,7 @@ except NameError:
'friends', 'friends',
'habits', 'habits',
'mood', 'mood',
'gpslog',
] ]
CORE_MODULES = [ CORE_MODULES = [
@ -79,10 +80,10 @@ WSGI_APPLICATION = 'kumify.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.contrib.gis.db.backends.spatialite',
'NAME': BASE_DIR / 'db.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3',
} if not DB_HOST else { } if not DB_HOST else {
'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'django.contrib.gis.db.backends.mysql',
'NAME': DB_NAME, 'NAME': DB_NAME,
'USER': DB_USER, 'USER': DB_USER,
'PASSWORD': DB_PASS, 'PASSWORD': DB_PASS,
@ -132,6 +133,7 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/ # https://docs.djangoproject.com/en/3.1/howto/static-files/

View file

@ -26,4 +26,5 @@ urlpatterns = [
path('cron/', include("cronhandler.urls", "cron")), path('cron/', include("cronhandler.urls", "cron")),
path('webhooks/telegram/', TelegramWebhookView.as_view()), path('webhooks/telegram/', TelegramWebhookView.as_view()),
path('dreams/', include("dreams.urls", "dreams")), path('dreams/', include("dreams.urls", "dreams")),
path('gpslog/', include("gpslog.urls"))
] ]

View file

@ -1,12 +1,10 @@
django
django[argon2] django[argon2]
django[mysql]
django-colorfield django-colorfield
django-multiupload django-multiupload
django-storages django-storages
django-polymorphic django-polymorphic
git+https://kumig.it/kumitterer/django-multiselectfield.git git+https://kumig.it/kumitterer/django-multiselectfield.git
git+https://github.com/Chive/django-multiupload.git#egg=django-multiupload git+https://github.com/Chive/django-multiupload.git
dbsettings dbsettings
django-filtersignals django-filtersignals
mysqlclient mysqlclient
@ -20,3 +18,4 @@ bokeh
panel panel
scipy scipy
channels channels
django-autosecretkey