예제 #1
0
 def get_queryset(self):
     """Get the queryset filtered to appropriate user."""
     user = self.request.user
     queryset = self.queryset
     if not user.is_superuser:
         queryset = queryset.filter(instance__account__user__id=user.id)
     user_id = self.request.query_params.get('user_id', None)
     if user_id is not None:
         user_id = convert_param_to_int('user_id', user_id)
         queryset = queryset.filter(instance__account__user__id=user_id)
     instance_id = self.request.query_params.get('instance_id', None)
     if instance_id is not None:
         instance_id = convert_param_to_int('instance_id', instance_id)
         queryset = queryset.filter(instance__id=instance_id)
     return queryset
예제 #2
0
 def get_queryset(self):
     """Get the queryset filtered to appropriate user."""
     user = self.request.user
     if not user.is_superuser:
         return self.queryset.filter(account__user__id=user.id)
     user_id = self.request.query_params.get('user_id', None)
     if user_id is not None:
         user_id = convert_param_to_int('user_id', user_id)
         return self.queryset.filter(account__user__id=user_id)
     return self.queryset
예제 #3
0
 def test_convert_param_to_int_with_str(self):
     """Test that convert_param_to_int returns int with str."""
     with self.assertRaises(ValidationError):
         convert_param_to_int('test_field', 'not_int')
예제 #4
0
 def test_convert_param_to_int_with_str_int(self):
     """Test that convert_param_to_int returns int with str int."""
     result = convert_param_to_int('test_field', '42')
     self.assertEqual(result, 42)