2023-07-21 19:26:10 -04:00
|
|
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
from rest_framework.decorators import action, api_view, schema
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
2023-07-24 22:26:56 -04:00
|
|
|
from ..models import Paradero, ParaderoImagen
|
2023-08-15 22:22:38 -04:00
|
|
|
from ..models import Linea, GtfsShape
|
2023-08-07 20:31:09 -04:00
|
|
|
from .paradero import url_image_paradero
|
2023-07-24 22:26:56 -04:00
|
|
|
from logging import error
|
2023-07-21 19:26:10 -04:00
|
|
|
|
2023-08-15 22:22:38 -04:00
|
|
|
google_api_key = 'AIzaSyDnFO9w_SsodjBuY5tOK8-kQJns_l5klQ4'
|
|
|
|
center = {'lat': -36.8077884, 'lng': -73.0775401}
|
2023-07-21 19:26:10 -04:00
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
@api_view(['GET'])
|
|
|
|
def paraderos(request):
|
2023-07-24 22:26:56 -04:00
|
|
|
zoom = 17
|
2023-07-21 19:26:10 -04:00
|
|
|
marks = []
|
2023-07-24 22:26:56 -04:00
|
|
|
|
|
|
|
paraderos = Paradero.objects.all()
|
|
|
|
for p in paraderos:
|
2023-08-07 20:31:09 -04:00
|
|
|
url_image = url_image_paradero(request, p.id_paradero)
|
|
|
|
|
2023-07-24 22:26:56 -04:00
|
|
|
marks.append({
|
2023-08-07 20:31:09 -04:00
|
|
|
'position': { 'lat': p.stop_lat, 'lng': p.stop_lon },
|
|
|
|
'id_paradero': p.id_paradero,
|
2023-07-24 22:26:56 -04:00
|
|
|
'title': 'Paradero #' + str(p.id_paradero),
|
2023-08-07 20:31:09 -04:00
|
|
|
'location': p.stop_name,
|
|
|
|
'id_comuna': p.id_comuna,
|
|
|
|
'id_tipo_paradero': p.id_tipo_paradero,
|
|
|
|
'url_image': url_image
|
2023-07-24 22:26:56 -04:00
|
|
|
})
|
|
|
|
|
2023-07-21 19:26:10 -04:00
|
|
|
return JsonResponse({
|
2023-07-24 22:26:56 -04:00
|
|
|
'google_api_key': google_api_key,
|
2023-07-21 19:26:10 -04:00
|
|
|
'zoom': zoom,
|
|
|
|
'center': center,
|
|
|
|
'marks': marks
|
|
|
|
})
|
2023-08-15 22:22:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
@api_view(['GET'])
|
|
|
|
def rutas(request):
|
|
|
|
id_linea = request.GET.get('id_linea')
|
|
|
|
service_id = request.GET.get('service_id')
|
|
|
|
|
|
|
|
linea = Linea.objects \
|
|
|
|
.filter(id_linea = id_linea, service_id = service_id, direction_id = '0') \
|
|
|
|
.values('shape_id') \
|
|
|
|
.first()
|
|
|
|
rutas = GtfsShape.objects \
|
|
|
|
.filter(id_shape = linea['shape_id']) \
|
|
|
|
.order_by('shape_pt_sequence') \
|
|
|
|
.values('shape_pt_lat','shape_pt_lon','shape_pt_sequence')
|
|
|
|
return JsonResponse(list(rutas), safe=False)
|