Przeglądaj źródła

fix mysql compatibility

subDesTagesMitExtraKaese 2 lat temu
rodzic
commit
406af8f8f3

+ 1 - 1
admin.py

@@ -5,7 +5,7 @@ from .models import *
 
 @admin.register(Marker)
 class MarkerAdmin(admin.ModelAdmin):
-  list_display = ["timestamp", "location", "hdop", "speed"]
+  list_display = ["timestamp", "location", "alt", "hdop", "speed"]
 
 @admin.register(Trip)
 class TripAdmin(admin.ModelAdmin):

+ 2 - 2
migrations/0005_auto_20220815_1630.py

@@ -34,13 +34,13 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='censoredlocation',
             name='location',
-            field=django.contrib.gis.db.models.fields.PointField(default=0, srid=4326),
+            field=django.contrib.gis.db.models.fields.PointField(srid=4326),
             preserve_default=False,
         ),
         migrations.AddField(
             model_name='marker',
             name='location',
-            field=django.contrib.gis.db.models.fields.PointField(default=0, dim=3, srid=4326),
+            field=django.contrib.gis.db.models.fields.PointField(dim=3, srid=4326),
             preserve_default=False,
         ),
     ]

+ 25 - 0
migrations/0006_marker_alt_alter_marker_location.py

@@ -0,0 +1,25 @@
+# Generated by Django 4.1.1 on 2022-09-18 18:55
+
+import django.contrib.gis.db.models.fields
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('gps_logger', '0005_auto_20220815_1630'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='marker',
+            name='alt',
+            field=models.FloatField(default=0, verbose_name='Altitude'),
+            preserve_default=False,
+        ),
+        migrations.AlterField(
+            model_name='marker',
+            name='location',
+            field=django.contrib.gis.db.models.fields.PointField(srid=4326),
+        ),
+    ]

+ 2 - 1
models.py

@@ -4,7 +4,8 @@ from django.contrib.gis.db.models.functions import Distance
 
 class Marker(models.Model):
   timestamp = models.DateTimeField(unique=True)
-  location = PointField(dim=3)
+  location = PointField(dim=2)
+  alt = models.FloatField("Altitude")
   hdop = models.IntegerField(null=True, blank=True)
   speed = models.IntegerField(null=True, blank=True)
 

+ 1 - 1
static/gps_logger/js/main.js

@@ -104,7 +104,7 @@ window.onload = function() {
 	var paths = [];
 
 	
-	fetch("gps_ajax.php")
+	fetch("markers")
 	.then(function(response) {
 		return response.json();
 	})

+ 2 - 2
templates/gps_logger/upload.html

@@ -31,7 +31,7 @@
 {% block content %}
 <div class="news">
   <p>
-    <input type="file" id="file-selector" accept=".txt, .nmea" multiple />
+    <input type="file" id="file-selector" multiple />
   </p>
 
   <div class="demo-container">
@@ -54,4 +54,4 @@
 <script language="javascript" type="text/javascript" src="{% static 'gps_logger/flot/jquery.flot.navigate.min.js' %}"></script>
 <script src="{% static 'gps_logger/js/preprocessor.js' %}" type="text/javascript"></script>
 <script src="{% static 'gps_logger/GPS.js/GPS.min.js' %}" type="text/javascript"></script>
-{% endblock %}
+{% endblock %}

+ 3 - 3
views.py

@@ -29,7 +29,8 @@ class MarkerCreateView(PermissionRequiredMixin, View):
         continue
       objects = [Marker(
           timestamp=datetime.strptime(x['timestamp'].replace("Z","-0000"), r"%Y-%m-%dT%H:%M:%S.%f%z"),
-          location = Point(x['lng'], x['lat'], x['alt']),
+          location = Point(x['lng'], x['lat']),
+          alt = x['alt'],
           hdop = x.get('hdop', None),
           speed = x.get('speed', None)
         ) for x in data[file]]
@@ -47,7 +48,7 @@ class MarkerCreateView(PermissionRequiredMixin, View):
       if identical:
         for i, marker in enumerate(oldMarkers):
           objects[i].id = marker.id
-        Marker.objects.bulk_update(objects, ['timestamp', 'location', 'hdop', 'speed'])
+        Marker.objects.bulk_update(objects, ['location', 'alt', 'hdop', 'speed'])
         replace_count += len(oldMarkers)
       else:
         insert_count += len(objects) - len(oldMarkers)
@@ -71,7 +72,6 @@ def marker_view(request):
       if location:
         marker['lng'] = location.x
         marker['lat'] = location.y
-        marker['alt'] = location.z
       del marker['location']
     data = json.dumps(values, cls=DjangoJSONEncoder)
     cache.set('markers', data, 3600*24)