views.py 928 B

12345678910111213141516171819202122232425262728
  1. from django.shortcuts import render
  2. from django.contrib.auth.decorators import permission_required
  3. from django.contrib.auth.mixins import PermissionRequiredMixin
  4. from rest_framework import generics
  5. from .models import *
  6. from .serializers import MarkerSerializer
  7. def index(request):
  8. return render(request, 'gps_logger/index.html')
  9. @permission_required("gps-logger.markers.change")
  10. def upload(request):
  11. return render(request, 'gps_logger/upload.html')
  12. class MarkerCreateView(generics.CreateAPIView, PermissionRequiredMixin):
  13. serializer_class = MarkerSerializer
  14. permission_required = ("gps-logger.markers.change")
  15. def get_serializer(self, *args, **kwargs):
  16. if isinstance(kwargs.get("data", {}), list):
  17. kwargs["many"] = True
  18. return super(MarkerCreateView, self).get_serializer(*args, **kwargs)
  19. class MarkerView(generics.ListAPIView):
  20. serializer_class = MarkerSerializer
  21. queryset = Marker.objects