Exemplo n.º 1
0
    def post(self, request):
        """POST handler."""
        # person = Person.get(self.database_manager, id=1)
        # processor = PersonSerializer(person)
        # output_json = processor.to_json()
        print("POST")
        input_processor = PersonSerializer(self.database_manager, request.body_json)
        errors = input_processor.check_json()
        print("JSON Errors:")
        print(errors)
        if len(errors) == 0:
            # new_person = input_processor.to_object()
            new_person = input_processor.save_object()
            print(new_person)
        else:
            output = dict([(error, "This field is required") for error in errors])
            return Response(output, status=Response.STATUS_400_BAD_REQUEST, headers=self.headers)
        # print("PERSON as JSON:")
        # print(json.dumps(output_json, indent=4))
        print("POST")
        print(request)
        print(self.headers)
        body = request.body
        print("BODY:")
        print(body)
        print(json.dumps(request.body_json, indent=4))
        # input_processor = PersonSerializer(request.body_json)

        response = Response(input_processor.to_json(), headers=self.headers)
        return response