def post(self, request, format=None): """ This method is used to create and store a new Event object. All required data is provided in a serialized format. @param request: HttpRequest containing all data for the new Event 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 = EventSerializer(data=request.data) if serializer.is_valid(): serializer.save() logger.debug('Created a new Event object') return Response(serializer.data, status=status.HTTP_201_CREATED) logger.debug('Error on new Event object creation') return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, format=None): """ Method used to update data of a specific Event object, providing fresh field data. @param request: HttpRequest which provide all update data fields. @type request: HttpRequest @param pk: Primary key used to retrieve the Event object to update. @type pk: int @param format: Format used for data serialization. @type format: string @return: HttpResponse containing the Event updated serialized data, error otherwise. @rtype: HttpResponse """ with edit_lock: event = self.get_object(pk) serializer = EventSerializer(event, data=request.data, partial=True) if serializer.is_valid(): serializer.save() logger.debug('Updated data for Event object with id ' + str(pk)) return Response(serializer.data) logger.debug('Error on update of Event object with id ' + str(pk)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)