def put(self, request, *args, **kwargs): course = self.get_object() serializer = self.get_serializer(course, data=request.data) if serializer.is_valid(raise_exception=True): serializer.save() return Response(data=serializer.data, status=status.HTTP_200_OK) raise exception.APIException()
def post(self, request, *args, **kwargs): queryset = self.get_queryset() serializer = self.get_serializer(data=request.data) if serializer.is_valid(raise_exception=True): serializer.save() return Response(data=serializer.data, status=status.HTTP_201_CREATED) raise exception.APIException()
def validate(self, attrs): if self.initial_data.get('old_password', None) is None: raise exception.RequireValue(detail=f"old_password is require!!!") is_correct_password = self.instance.check_password( self.initial_data.get('old_password')) if is_correct_password is False: raise exception.APIException(detail="password is wrong!!!") if self.initial_data.get('old_password', None) is not None: attrs['new_password'] = self.initial_data.get('new_password') return attrs
def validate(self, attrs): data = {} username = attrs.get('username', None) user = UserModel.objects.filter(username=username).exclude( account_type=0).first() if user is None: raise exception.APIException(detail="authen failed!") refresh = self.get_token(user) data['refresh'] = str(refresh) data['access'] = str(refresh.access_token) # # Add extra responses here print(user, user.photo, 'user') data['id'] = user.id data['username'] = user.username data['email'] = user.email data['name'] = user.name data["phone"] = user.phone data['position'] = user.position data['slogan'] = user.slogan data['owner_course'] = user.owner_course data['temporary_user'] = user.temporary_user data['description'] = user.description if hasattr(user.photo, 'id') is True: data['photo'] = { 'id': user.photo.id, 'name': "image.png", 'status': "done", 'path': user.photo.photo.name, } else: data['photo'] = { 'id': "", 'name': "image.png", 'status': "done", 'path': "", } return data