Private
Public Access
1
0

exporting courses.kml

This commit is contained in:
2024-02-28 15:36:12 +01:00
parent af1adf132e
commit 25bfcb17fd
6 changed files with 165 additions and 71 deletions

View File

@@ -1,7 +1,7 @@
from rowers.views.statements import *
from rowers.tasks import handle_calctrimp
from rowers.opaque import encoder
from rowers.courses import coursetokml
from rowers.courses import coursetokml, coursestokml
from xml.etree import ElementTree as ET
import arrow
@@ -252,6 +252,7 @@ Optional, not for CN
- Update one or more new courses from KML
"""
@api_view(["GET"])
@permission_classes([AllowAny])
def course_list(request):
if request.method != 'GET':
dologging('apilog.log','{m} request to KML endpoint'.format(m=request.method))
@@ -304,6 +305,7 @@ def course_list(request):
return JsonResponse(response_dict, content_type='application/json; charset=utf8')
@api_view(["GET"])
@permission_classes([AllowAny])
def get_crewnerd_kml(request,id=0):
if request.method != 'GET':
dologging('apilog.log','{m} request to CrewNerd KML endpoint'.format(m=request.method))
@@ -318,6 +320,26 @@ def get_crewnerd_kml(request,id=0):
return HttpResponse(kml)
#@csrf_exempt
@api_view(["GET"])
@permission_classes([AllowAny])
def get_crewnerd_multiple(request):
if request.method != 'GET':
dologging('apilog.log','{m} request to CrewNerd KML endpoint'.format(m=request.method))
return HttpResponseNotAllowed("Method not supported")
ids = request.GET.get('id')
if ids is not None:
tdict = dict(request.GET.lists())
ids = [int(id) for id in tdict['id']]
else:
gcs = GeoCourse.objects.all()
ids = [c.id for c in gcs]
kml = coursestokml(ids, cn=True)
return HttpResponse(kml)
# Stroke data views
@csrf_exempt

View File

@@ -7,7 +7,7 @@ from django.contrib.gis.geoip2 import GeoIP2
from django import forms
from rowers.plannedsessions import timefield_to_seconds_duration
from rowers.courses import getnearestraces, getnearestcourses
from rowers.courses import getnearestraces, getnearestcourses,coursetokml, coursestokml
# List Courses
@@ -16,6 +16,25 @@ def courses_view(request):
r = getrower(request.user)
g = GeoIP2()
if request.method == 'POST':
try:
tdict = dict(request.POST.lists())
ids = tdict['courseid']
courseids = [int(id) for id in ids]
kmlstring = coursestokml(courseids)
kmlfilename = 'courses.kml'
response = HttpResponse(kmlstring)
response['Content-Disposition'] = 'attachment; filename="{filename}"'.format(
filename=kmlfilename)
response['Content-Type'] = 'application/octet-stream'
return response
except KeyError:
pass
ip = request.META.get('HTTP_X_REAL_IP', '1.1.1.1')
try:
lat_lon = g.lat_lon(ip)

View File

@@ -22,7 +22,7 @@ from scipy.special import lambertw
from io import BytesIO
import rowers.plots as plots
from rowers.permissions import IsOwnerOrNot, IsCompetitorOrNot
from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.decorators import api_view, renderer_classes, permission_classes
from rest_framework.response import Response
from rq.job import Job