Esempio n. 1
0
 def get_user_by_username(self, user_name):
     key = self.get_user_name_key(user_name)
     user_instance = self.handle.get(key)
     if not user_instance:
         user_instance = BusinessUser.get_object(**{'phone': user_name})
         if isinstance(user_instance, Exception):
             return user_instance
         self.set_data_to_cache(key, user_instance)
     return user_instance
Esempio n. 2
0
 def get_user_by_id(self, user_id):
     key = self.get_user_id_key(user_id)
     user_instance = self.handle.get(key)
     if not user_instance:
         user_instance = BusinessUser.get_object(**{'pk': user_id})
         if isinstance(user_instance, Exception):
             return user_instance
         self.set_user_to_cache(key, user_instance)
     return user_instance
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        user = BusinessUser.get_user_detail(request)
        if isinstance(user, Exception):
            return Response({'Error': user.args},
                            status=status.HTTP_400_BAD_REQUEST)

        serializer = UserDetailSerializer(data=user)
        if serializer.is_valid():
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 4
0
 def get_user_by_id(self, request, user_id=None):
     if not request.user.is_admin:
         user_id = request.user.id
     key = self.get_user_id_key(user_id)
     user_instance = self.handle.get(key)
     if not user_instance:
         user_instance = BusinessUser.get_object(**{'pk': user_id})
         if isinstance(user_instance, Exception):
             return user_instance
         self.set_data_to_cache(key, user_instance)
     return user_instance
Esempio n. 5
0
    def put(self, request, *args, **kwargs):
        """
        修改密码
        """
        form = ChangePasswordForm(request.data)
        if not form.is_valid():
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)

        obj = BusinessUser.get_object(**{'pk': request.user.id})
        serializer = UserSerializer(obj)
        try:
            serializer.update_password(obj, form.cleaned_data)
        except Exception as e:
            return Response({'Error': e.args},
                            status=status.HTTP_400_BAD_REQUEST)

        serializer_response = UserInstanceSerializer(obj)
        return Response(serializer_response.data,
                        status=status.HTTP_206_PARTIAL_CONTENT)
Esempio n. 6
0
    def filter_perfect_details(cls, request, **kwargs):
        instances = cls.filter_objects(**kwargs)
        if isinstance(instances, Exception):
            return instances

        users_dict = {}
        details = []
        for ins in instances:
            if not request.user.is_admin:
                ins.bank_card_number = ins.security_card_number

            detail = model_to_dict(ins)
            user = users_dict.get(ins.user_id)
            if not user:
                user = BusinessUser.get_object(pk=ins.user_id)
                users_dict[ins.user_id] = user
            detail['chinese_people_id'] = user.chinese_people_id
            details.append(detail)
        return details
Esempio n. 7
0
 def get_user_object(self, username):
     return BusinessUser.get_object(phone=username)
Esempio n. 8
0
 def get_objects_list(self, request, **kwargs):
     return BusinessUser.get_objects_list(request, **kwargs)
Esempio n. 9
0
def get_user_info(user_id):
    return BusinessUser.get_object(pk=user_id)