def post(self, request, format=None): """ This method will be converted in a HTTP POST API and it will allow to save new Event objects in the database. @param request: HttpRequest containing all data for the new Action object. @type request: HttpRequest @param format: The format used to serialize objects data. @type format: string @return: HttpResponse containing the id of the new object, error otherwise. @rtype: HttpResponse """ serializer = ActionSerializer(data=request.data) if serializer.is_valid(): serializer.save() logger.debug('Created new Action object') return Response(serializer.data, status=status.HTTP_201_CREATED) logger.debug('Error on Action object creation') return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, format=None): """ Method used to update action information providing serialized data. @param request: HttpRequest which provide all update data fields. @type request: HttpRequest @param pk: Primary key used to retrieve the Action object to update. @type pk: int @param format: Format used for data serialization. @type format: string @return: HttpResponse containing the Action updated serialized data, error otherwise. @rtype: HttpResponse """ action = self.get_object(pk) serializer = ActionSerializer(action, data=request.data) if serializer.is_valid(): serializer.save() logger.debug('Updated data for Action object with id ' + str(pk)) return Response(serializer.data) logger.debug('Error on update of Action object with id ' + str(pk)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)