示例#1
0
	def post(self, request, machine, field, value, format=None):
		request.data['parent'] = machine.serial
		serializedCharacteristics=CharacteristicsSerializer(data=request.data)
		if serializedCharacteristics.is_valid():
			serializedCharacteristics.save()
			return Response(serializedCharacteristics.data, status = status.HTTP_201_CREATED)
		return Response(serializedCharacteristics.errors, status = status.HTTP_400_BAD_REQUEST)
示例#2
0
 def post(self, request, machine, field, value, format=None):
     request.data['parent'] = machine.serial
     serializedCharacteristics = CharacteristicsSerializer(
         data=request.data)
     if serializedCharacteristics.is_valid():
         serializedCharacteristics.save()
         return Response(serializedCharacteristics.data,
                         status=status.HTTP_201_CREATED)
     return Response(serializedCharacteristics.errors,
                     status=status.HTTP_400_BAD_REQUEST)
示例#3
0
	def put(self, request, machine, field, value, format=None):
		characteristics = machine.characteristics.get(characteristicType__iexact=field)
		if not value:		
			serializedCharacteristics = CharacteristicsSerializer(characteristics, data=request.data)
			if serializedCharacteristics.is_valid():
				serializedCharacteristics.save()		
		else:
			characteristics.value = request.data.get(value)
			characteristics.save()
			serializedCharacteristics = CharacteristicsSerializer(characteristics)
		return Response(serializedCharacteristics.data)
		return Response(serializedCharacteristics.errors, status=status.HTTP_400_BAD_REQUEST)
示例#4
0
    def get(self, request, machine, field, value, format=None):

        if field.lower() == 'characteristics':
            characteristics = machine.characteristics.all()
            serializedCharacteristics = CharacteristicsSerializer(
                characteristics, many=True)
            return Response(serializedCharacteristics.data)
        else:
            characteristics = machine.characteristics.get(
                characteristicType__iexact=field)
            serializedCharacteristics = CharacteristicsSerializer(
                characteristics)
            if value:
                return Response(serializedCharacteristics.data.get(value))
            else:
                return Response(serializedCharacteristics.data)
示例#5
0
 def put(self, request, machine, field, value, format=None):
     characteristics = machine.characteristics.get(
         characteristicType__iexact=field)
     if not value:
         serializedCharacteristics = CharacteristicsSerializer(
             characteristics, data=request.data)
         if serializedCharacteristics.is_valid():
             serializedCharacteristics.save()
     else:
         characteristics.value = request.data.get(value)
         characteristics.save()
         serializedCharacteristics = CharacteristicsSerializer(
             characteristics)
     return Response(serializedCharacteristics.data)
     return Response(serializedCharacteristics.errors,
                     status=status.HTTP_400_BAD_REQUEST)