def post(self, request, project_id=None, format=None): data = request_to_dict(request) project = Project.objects.create(name=data['name'], description=data['description']) return Response(ProjectSerializer(project).data, status=201)
def put(self, request, project_id=None, format=None): project = get_object_or_404(Project, pk=project_id) data = request_to_dict(request) for attr in data: setattr(project, attr, data[attr]) project.save() return Response(ProjectSerializer(project).data)
def put(self, request, project_id=None, intent_id=None, format=None): intent = get_object_or_404(Intent, pk=intent_id) project = get_object_or_404(Project, pk=project_id) data = request_to_dict(request) is_valid, error_messages = validate_intent(data, project_id) if not is_valid: return Response({'errors': error_messages}, status=400) for attr in data: setattr(intent, attr, data[attr]) intent.project = project intent.save() return Response(IntentSerializer(intent).data)
def put(self, request, project_id=None, utter_id=None, format=None): utter = get_object_or_404(Utter, pk=utter_id) project = Project.objects.get(pk=project_id) data = request_to_dict(request) is_valid, error_messages = validate_utter(data, project_id) if not is_valid: return Response({'errors': error_messages}, status=400) for attr in data: setattr(utter, attr, data[attr]) utter.project = project utter.save() return Response(UtterSerializer(utter).data)
def post(self, request, project_id=None, intent_id=None, format=None): if not project_id: return Response(status=404) data = request_to_dict(request) is_valid, error_messages = validate_intent(data, project_id) if not is_valid: return Response({'errors': error_messages}, status=400) project = get_object_or_404(Project, pk=project_id) intent = Intent.objects.create( name=data['name'], samples=data['samples'], project=project ) return Response(IntentSerializer(intent).data, status=201)
def put(self, request, project_id=None, story_id=None, format=None): story = get_object_or_404(Story, pk=story_id) project = get_object_or_404(Project, pk=project_id) data = request_to_dict(request) if not validate_story(data): return Response({'errors': ['Invalid data']}, status=400) if validate_content(data['content']): for attr in data: if attr == 'content': setattr(story, attr, story_content_formatter(data[attr])) else: setattr(story, attr, data[attr]) story.project = project story.save() return Response(StorySerializer(story).data) else: return Response({'errors': ['Invalid content array']}, status=400)
def post(self, request, project_id=None, story_id=None, format=None): if not project_id: return Response(status=404) data = request_to_dict(request) if not validate_story(data): return Response({'errors': ['Invalid data']}, status=400) project = get_object_or_404(Project, pk=project_id) if validate_content(data['content']): story = Story.objects.create(name="Default Name", content=story_content_formatter( data['content']), project=project) story.name = "Diálogo_{0}_{1}".format(story.project.name, story.id) story.save() return Response(StorySerializer(story).data, status=201) else: return Response({'errors': ['Invalid content array']}, status=400)
def post(self, request, project_id=None, utter_id=None, format=None): if not project_id: return Response(status=404) data = request_to_dict(request) is_valid, error_messages = validate_utter(data, project_id) if not is_valid: return Response({'errors': error_messages}, status=400) project = get_object_or_404(Project, pk=project_id) utter = Utter.objects.create( name=data['name'], alternatives=data['alternatives'], multiple_alternatives=data['multiple_alternatives'], project=project ) return Response(UtterSerializer(utter).data, status=201)