Beispiel #1
0
def track_list(request):
    """
    List all snippets, or create a new snippet.
    """
    if request.method == 'GET':
        tracks = request.user.profile.track_set.all()
        serializer = TrackSerializer(tracks, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = TrackSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save(profile=request.user.profile)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
def new_track_list(request, last_update=0):
    """
    List all snippets, or create a new snippet.
    """
    if request.method == 'GET':
        last_update = datetime.fromtimestamp(float(last_update)/1000)
        # tracks = request.user.profile.track_set.all()
        tracks = Track.objects.filter(profile_id = request.user.profile.id, dateClosed__gt = last_update)
        serializer = TrackSerializer(tracks, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = TrackSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save(profile=request.user.profile)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #3
0
def track_detail(request, uuid):
    """
    Retrieve, update or delete a snippet instance.
    """
    try:
        track = Track.objects.get(uuid=uuid)
    except Track.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = TrackSerializer(track)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = TrackSerializer(track, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        track.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)