def delete(self, request, employee_id, model_id): try: model = self.model.objects.get(id=model_id, employee_id=employee_id) if self._owner_or_admin(request, employee_id): model.delete() return Response({'id': model_id}, status.HTTP_200_OK) else: return Utils.error_response("Permission denied", status.HTTP_403_FORBIDDEN) except ObjectDoesNotExist as e: return Utils.error_response(e.args, status.HTTP_404_NOT_FOUND)
def post(self, request, employee_id): if self._owner_or_admin(request, employee_id): data = request.data data['employeeId'] = employee_id serializer = self.serializer(data=data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Utils.error_response(serializer.errors, status.HTTP_400_BAD_REQUEST) else: return Utils.error_response("Permission denied", status.HTTP_403_FORBIDDEN)
def patch(self, request, model_id): try: model = self.model.objects.get(id=model_id) if self.serializer_for_user is not None and not request.user.is_staff: serializer = self.serializer_for_user(model, data=request.data, partial=True) else: serializer = self.serializer(model, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data, status.HTTP_200_OK) else: return Utils.error_response(serializer.errors, status.HTTP_400_BAD_REQUEST) except ObjectDoesNotExist as e: return Utils.error_response(e.args, status.HTTP_404_NOT_FOUND)
def patch(self, request): try: model = request.user serializer = self.serializer(model, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data, status.HTTP_200_OK) else: return Utils.error_response(serializer.errors, status.HTTP_400_BAD_REQUEST) except ObjectDoesNotExist as e: return Utils.error_response(e.args, status.HTTP_404_NOT_FOUND)
def patch(self, request, employee_id, model_id): try: model = self.model.objects.get(id=model_id, employee_id=employee_id) if self._owner_or_admin(request, employee_id): serializer = self.serializer(model, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data, status.HTTP_200_OK) else: return Utils.error_response(serializer.errors, status.HTTP_400_BAD_REQUEST) else: return Utils.error_response("Permission denied", status.HTTP_403_FORBIDDEN) except ObjectDoesNotExist as e: return Utils.error_response(e.args, status.HTTP_404_NOT_FOUND)
def delete(self, request, model_id): try: model = self.model.objects.get(id=model_id) model.delete() return Response({'id': model_id}, status.HTTP_200_OK) except ObjectDoesNotExist as e: return Utils.error_response(e.args, status.HTTP_404_NOT_FOUND)
def put(self, request): user = request.user serializer = ChangePasswordSerializer(data=request.data) if serializer.is_valid(): old_password = serializer.data.get("old_password") if not user.check_password(old_password): return Utils.error_response( {"old_password": ["Wrong password."]}, status.HTTP_400_BAD_REQUEST) user.set_password(serializer.data.get("new_password")) user.save() return Response(status=status.HTTP_204_NO_CONTENT) return Utils.error_response(serializer.errors, status.HTTP_400_BAD_REQUEST)
def post(self, request, model_id): data = request.data data['employee'] = model_id serializer = self.serializer(data=data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Utils.error_response(serializer.errors, status.HTTP_400_BAD_REQUEST)
def get(self, request, model_id): try: model = self.model.objects.get(id=model_id) if self.serializer_for_user is not None and not request.user.is_staff: serializer = self.serializer_for_user(model) else: serializer = self.serializer(model) return Response(serializer.data) except ObjectDoesNotExist as e: return Utils.error_response(e.args, status.HTTP_404_NOT_FOUND)
def post(self, request, employee_id): if self._owner_or_admin(request, employee_id): data = request.data data['employeeId'] = employee_id try: EmployeeSkill.objects.get(skill_id=data['skillId'], employee_id=data['employeeId']) return Utils.error_response( {'non_field_errors': ['You already have such skill']}, status.HTTP_400_BAD_REQUEST) except ObjectDoesNotExist: serializer = self.serializer(data=data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Utils.error_response(serializer.errors, status.HTTP_400_BAD_REQUEST) else: return Utils.error_response("Permission denied", status.HTTP_403_FORBIDDEN)
def get(self, request, model_id): from docx import Document try: self.employee = Employee.objects.get(id=model_id) self.candidate_presentation = Document() self.candidate_presentation.add_heading('Candidate Presentation', 0) self._generate_employee_summary() if self.employee.position is not None and self.employee.career_start_date is not None: self._generate_employee_summary_of_qualification() self._generate_technical_summary() self._generate_professional_experience() return self._generate_file_response() except ObjectDoesNotExist as e: return Utils.error_response(e.args, status.HTTP_404_NOT_FOUND)
def get(self, request, employee_id, model_id): try: model = self.model.objects.get(id=model_id, employee_id=employee_id) return Response(self.serializer(model).data) except ObjectDoesNotExist as e: return Utils.error_response(e.args, status.HTTP_404_NOT_FOUND)