106 lines
3.2 KiB
Python
106 lines
3.2 KiB
Python
|
|
from rest_framework import viewsets
|
|
from django.http import JsonResponse
|
|
from rest_framework.decorators import action
|
|
from .. import models, serializers
|
|
import json
|
|
|
|
class DispositivoViewSet(viewsets.ModelViewSet):
|
|
queryset = models.Dispositivo.objects.all()
|
|
serializer_class = serializers.DispositivoSerializer
|
|
|
|
@action(detail=False, methods=['post'])
|
|
def whoami(self, request, pk=None):
|
|
input = json.loads(request.body)
|
|
whoami = input['whoami']
|
|
|
|
if (whoami['idDispositivo'] == 'existe'):
|
|
return JsonResponse({
|
|
"WhoamiResponse": {
|
|
"NroParadero": "AAA330",
|
|
"NombreParadero":"paradero 1 esq colon",
|
|
"Status": "OK"
|
|
}
|
|
})
|
|
|
|
# retorna json de no existente
|
|
return JsonResponse({
|
|
"WhoamiResponse": {
|
|
"Status": "NOK",
|
|
"errorString": "Dispositivo no identificado"
|
|
}
|
|
})
|
|
|
|
|
|
@action(detail=False, methods=['post'])
|
|
def getInfoDevice(self, request, pk=None):
|
|
input = json.loads(request.body)
|
|
|
|
linea1 = {
|
|
"Linea": "803010",
|
|
"Descripcion": "Tucapel",
|
|
"TipoLocomocion": 1,
|
|
"colorFondo": "Hexadecimal",
|
|
"colorLetra": "Hexadecimal",
|
|
"Llegadas": [
|
|
{
|
|
"Patente": "RPDA-98",
|
|
"Planificada": "",
|
|
"EstimadaGPS": "15:08",
|
|
"DistanciaGPS": "1.0 KM"
|
|
},
|
|
{
|
|
"Patente": "WYXYZ-22",
|
|
"Planificada": "",
|
|
"EstimadaGPS": "15:42",
|
|
"DistanciaGPS": "5.0 KM"
|
|
},
|
|
{
|
|
"Patente": "ABCA-65",
|
|
"Planificada": "",
|
|
"EstimadaGPS": "16:18",
|
|
"DistanciaGPS": "13.4 KM"
|
|
}
|
|
],
|
|
"Mensajelinea": ""
|
|
}
|
|
|
|
linea2 = {
|
|
"Linea": "5487",
|
|
"Descripcion": "Centauro",
|
|
"TipoLocomocion": 1,
|
|
"colorFondo": "Hexadecimal",
|
|
"colorLetra": "Hexadecimal",
|
|
"Llegadas": [
|
|
{
|
|
"Patente": "PLKJ-32",
|
|
"Planificada": "15:13",
|
|
"EstimadaGPS": "",
|
|
"DistanciaGPS": "",
|
|
},
|
|
{
|
|
"Patente": "GHLK-11",
|
|
"Planificada": "15:39",
|
|
"EstimadaGPS": "",
|
|
"DistanciaGPS": "",
|
|
},
|
|
{
|
|
"Patente": "DFQW-55",
|
|
"Planificada": "16:22",
|
|
"EstimadaGPS": "",
|
|
"DistanciaGPS": "",
|
|
}
|
|
],
|
|
"Mensajelinea": "Sin info. GPS, la informacion es estimada"
|
|
}
|
|
|
|
detalle_lineas = []
|
|
detalle_lineas.append(linea1)
|
|
detalle_lineas.append(linea2)
|
|
|
|
return JsonResponse({
|
|
"GetInfoDeviceResponse": {
|
|
"DetalleLineas": detalle_lineas,
|
|
"MensajeParadero": "No considerar, uso futuro"
|
|
}
|
|
}) |