def list_of_rough_solution_dtos(): rough_solution_dtos = [ RoughSolutionDto(code_type="C", code="str", filename="str", roughsolution_id=1, question_id=1), RoughSolutionDto(code_type="PYTHON", code="str", filename="str", roughsolution_id=2, question_id=1), ] return rough_solution_dtos
def roughsolutiondto(): roughsolutiondto = RoughSolutionDto(code_type=CodeLanguage.python.value, code="string", filename="string", roughsolution_id=None, question_id=1) return roughsolutiondto
def rough_solution_id_dto(): rough_solution_id_dto = RoughSolutionDto(code_type="PYTHON", code="str", filename="str", roughsolution_id=1, question_id=1) return rough_solution_id_dto
def _convert_roughsolution_list_obj_to_dtos(self, roughsolution_objs): list_of_rough_solution_dtos = [ RoughSolutionDto(code_type=obj.code_type, code=obj.code, filename=obj.filename, question_id=obj.question_id, roughsolution_id=obj.id) for obj in roughsolution_objs ] return list_of_rough_solution_dtos
def _convert_roughsolution_queryset_to_dtos_list(roughsolution_queryset): list_of_rough_solution_dtos = [ RoughSolutionDto(code_type=obj.code_type, code=obj.code, filename=obj.filename, question_id=obj.question_id, roughsolution_id=obj.id) for obj in roughsolution_queryset ] return list_of_rough_solution_dtos
def rough_solution_create_or_update(self, \ question_id: int,question_rough_solutions_list:List[Dict]): try: self.storage.validate_question_id(question_id=question_id) except InvalidQuestionId: self.presenter.raise_invalid_question_exception() updated_rough_solutions = [] created_rough_solutions = [] list_of_rough_solutions_ids = [] for roughsolution in question_rough_solutions_list: roughsolution_id = roughsolution.get('roughsolution_id') if roughsolution_id: updated_rough_solutions.append(roughsolution) list_of_rough_solutions_ids.append(roughsolution_id) else: created_rough_solutions.append(roughsolution) #print(created_rough_solutions,updated_rough_solutions) try: self.storage.validate_rough_solution_ids( \ list_of_rough_solutions_ids=list_of_rough_solutions_ids) except InvalidRoughSolutionId: self.presenter.raise_invalid_rough_solution_exception() try: self.storage.validate_question_roughsolutions_match( \ question_id=question_id, \ list_of_rough_solutions_ids=list_of_rough_solutions_ids) except InvalidRoughSolutionForQuestion: self.presenter.raise_invalid_rough_solution_for_question_exception( ) created_rough_solutions_dtos = [ RoughSolutionDto(roughsolution_id=None, code_type=roughsolution["code_type"], code=roughsolution["code"], filename=roughsolution["filename"], question_id=question_id) for roughsolution in created_rough_solutions ] updated_rough_solutions_dtos = [ RoughSolutionDto( code_type=roughsolution["code_type"], code=roughsolution["code"], filename=roughsolution["filename"], roughsolution_id=roughsolution["roughsolution_id"], question_id=question_id) for roughsolution in updated_rough_solutions ] list_of_rough_solutions_dtos = \ self.storage.updation_and_creation_of_rough_solutions( \ question_id=question_id, updated_rough_solutions_dtos=updated_rough_solutions_dtos, created_rough_solutions_dtos=created_rough_solutions_dtos ) return self.presenter.get_response_for_list_of_rough_solutions_dtos( list_of_rough_solution_dtos=list_of_rough_solutions_dtos)