def post(self, request, *args, **kwargs): data = request.data user = data['creator'] code = eval(data['code']) code = Code(title=code['title'], content=code['content'], language=code['language'], creator_id=user) try: code.clean_fields() code.save() except Exception as error: return Response(error, status=status.HTTP_400_BAD_REQUEST) smells = eval(data['smells']) for s in smells: smell = CodeSmell(code_id=code.id, user_id=user, line=s['line'], smell=s['smell']) try: smell.clean_fields() smell.save() except Exception as error: return Response(error, status=status.HTTP_400_BAD_REQUEST) return Response(CodeSerializer(code).data, status=status.HTTP_201_CREATED)
def post(self, request, *args, **kwargs): data = request.data user = data['creator'] code = eval(data['code']) code = Code(title=code['title'], content=code['content'], language=code['language'], creator_id=user) try: code.clean_fields() code.save() except Exception as error: return Response(error, status=status.HTTP_400_BAD_REQUEST) smells = eval(data['smells']) for s in smells: smell = CodeSmell(code_id=code.id, user_id=user, line=s['line'], smell=s['smell']) try: smell.clean_fields() smell.save() except Exception as error: return Response(error, status=status.HTTP_400_BAD_REQUEST) return Response(CodeSerializer(code).data, status=status.HTTP_201_CREATED)
def post(self, request, *args, **kwargs): """ Submit a new code snippet with a list of codesmells together. Example POST body: <code> { "creator" : 18, "code" : "{'title' : 'Third Code Snippet!', 'content' : 'sum = 3+4', 'language' : 'Python'}", "smells" : "[{'line': 1, 'smell': 'Vague string'}, {'line': 2, 'smell': 'Bad variable name'}]" } </code> --- parameters: - name: body paramType: body description: See example POST body above consumes: - application/json """ data = request.data user = data['creator'] code = eval(data['code']) code = Code(title=code['title'], content=code['content'], language=code['language'], creator_id=user) try: code.clean_fields() code.save() except Exception as error: return Response(error, status=status.HTTP_400_BAD_REQUEST) smells = eval(data['smells']) for s in smells: smell = CodeSmell(code_id=code.id, user_id=user, line=s['line'], smell=s['smell']) try: smell.clean_fields() smell.save() except Exception as error: return Response(error, status=status.HTTP_400_BAD_REQUEST) return Response(CodeSerializer(code).data, status=status.HTTP_201_CREATED)