def put(self, request, format='json'): """ Request-type: PUT Method for Updating an Iteration Details """ data = request.data request_serializer = IterationSerializer(data=data) if request_serializer.is_valid(): result = update_iteration(data) if result: return Response({"message": "Updated Successfully."}, status=status.HTTP_200_OK) return Response({"message": "No Data Found."}, status=status.HTTP_200_OK) return Response({"message": "Invalid Data."}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): """ Request-type: POST Method for Creating an Iteration """ data = request.data request_serializer = IterationSerializer(data=data) if request_serializer.is_valid(): result = create_iteration(data) if result: response_serializer = IterationSerializer(result) return Response(response_serializer.data, status=status.HTTP_201_CREATED) return Response({"message": "Operation failed."}, status=status.HTTP_417_EXPECTATION_FAILED) return Response({"message": "Invalid Data"}, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, format=None): """ Request-type: GET Method to fetch All Iterations Details """ result = get_all_iterations() if result: response_serializer = IterationSerializer(result, many=True) return Response(response_serializer.data, status=status.HTTP_200_OK) return Response({"message": "No Data Found."}, status=status.HTTP_200_OK)
def get(self, request, iteration_uid, format=None): """ Request-type: GET Method for fetching iteration details using 'iteration_name' """ result = get_iteration_by_iteration_uid(iteration_uid) if result: response_serializer = IterationSerializer(result, many=True) return Response(response_serializer.data, status=status.HTTP_200_OK) return Response({"message": "No Data Found"}, status=status.HTTP_200_OK)
def get(self, request, iteration_uid, format=None): """ Request-type: GET Method to fetch an Iteration detail using 'iteration_id' """ result = get_iteration_by_iteration_uid(iteration_uid) if result: response_serializer = IterationSerializer(result) return Response(response_serializer.data, status=status.HTTP_200_OK) return Response({"message": "Not Found"}, status=status.HTTP_404_NOT_FOUND)
def update_iteration(input_dict): """ Editing and updating required fields of iteration. """ date_modified = datetime.now().isoformat() try: if (input_dict.get('status') == "Completed"): completed_at = datetime.now().isoformat() iteration_obj = Iteration.objects( iteration_uid=input_dict.get('iteration_uid')).update( iteration_name=input_dict.get('iteration_name'), iteration_description=input_dict.get( 'iteration_description'), date_modified=date_modified, completed_at=completed_at, status=input_dict.get('status')) elif (input_dict.get('status') == "Hold"): completed_at = datetime.now().isoformat() iteration_obj = Iteration.objects( iteration_uid=input_dict.get('iteration_uid')).update( iteration_name=input_dict.get('iteration_name'), iteration_description=input_dict.get( 'iteration_description'), date_modified=date_modified, completed_at=completed_at, status=input_dict.get('status')) else: iteration_obj = Iteration.objects( iteration_uid=input_dict.get('iteration_uid')).update( iteration_name=input_dict.get('iteration_name'), iteration_description=input_dict.get( 'iteration_description'), date_modified=date_modified, status="In Progress") iteration_data = IterationSerializer( get_iteration_by_iteration_uid( input_dict.get('iteration_uid'))).data project_data = ProjectResponseSerializer( get_project(iteration_data['project_uid'])).data add_activity( iteration_data['project_uid'], " modified iteration '" + input_dict.get("iteration_name") + "'.", project_data['owned_by']) except (Exception): print(Exception.message) else: return iteration_obj return None
def get(self, request, project_uid, format=None): """ Request-type: POST Method to fetch an Iteration detail using 'project_id' """ if project_uid == None: return Response({"message": "Invalid Data"}, status=status.HTTP_200_OK) result = get_iteration_by_project_uid(project_uid) if result: response_serializer = IterationSerializer(result, many=True) return Response(response_serializer.data, status=status.HTTP_200_OK) return Response({"message": "Not Found"}, status=status.HTTP_200_OK)
def post(self, request, format=None): """ Request-type: POST Method to fetch an Iteration detail using 'iteration_name' and 'project_uid' """ print(request.data) if request.data.get('iteration_name') == None or request.data.get( 'project_uid') == None: return Response({"message": "Invalid Data"}, status=status.HTTP_200_OK) result = get_iteration_by_name_and_projectuid(request, request.data) if result: response_serializer = IterationSerializer(result, many=True) return Response(response_serializer.data, status=status.HTTP_200_OK) return Response({"message": "Not Found"}, status=status.HTTP_200_OK)
def delete_iteration(iteration_uid): """ Deleting a Iteration from database here. """ try: iteration_obj = Iteration.objects(iteration_uid=iteration_uid) iteration_data = IterationSerializer( get_iteration_by_iteration_uid(iteration_uid)).data iteration_obj = iteration_obj.delete() project_data = ProjectResponseSerializer( get_project(iteration_data['project_uid'])).data add_activity( iteration_data['project_uid'], " deleted iteration '" + iteration_data['iteration_name'] + "'.", project_data['owned_by']) except (Exception): print(Exception.message) else: return iteration_obj return None