当前位置: 首页>>代码示例>>Python>>正文


Python options.IncorrectLookupParameters方法代码示例

本文整理汇总了Python中django.contrib.admin.options.IncorrectLookupParameters方法的典型用法代码示例。如果您正苦于以下问题:Python options.IncorrectLookupParameters方法的具体用法?Python options.IncorrectLookupParameters怎么用?Python options.IncorrectLookupParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.admin.options的用法示例。


在下文中一共展示了options.IncorrectLookupParameters方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_result_list_editable

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def test_result_list_editable(self):
        """
        Regression test for #14312: list_editable with pagination
        """
        new_parent = Parent.objects.create(name='parent')
        for i in range(200):
            Child.objects.create(name='name %s' % i, parent=new_parent)
        request = self.factory.get('/child/', data={'p': -1})  # Anything outside range
        request.user = self.superuser
        m = ChildAdmin(Child, custom_site)

        # Test with list_editable fields
        m.list_display = ['id', 'name', 'parent']
        m.list_display_links = ['id']
        m.list_editable = ['name']
        with self.assertRaises(IncorrectLookupParameters):
            m.get_changelist_instance(request) 
开发者ID:nesdis,项目名称:djongo,代码行数:19,代码来源:tests.py

示例2: queryset

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def queryset(self, request, queryset):
        try:
            return queryset.filter(**self.used_parameters)
        except ValidationError as e:
            raise IncorrectLookupParameters(e) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:7,代码来源:filters.py

示例3: queryset

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def queryset(self, request, queryset):
        try:
            return queryset.filter(**self.used_parameters)
        except (ValueError, ValidationError) as e:
            # Fields may raise a ValueError or ValidationError when converting
            # the parameters to the correct type.
            raise IncorrectLookupParameters(e) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:9,代码来源:filters.py

示例4: get_admin_cl

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def get_admin_cl(self, request):
        ChangeList = self.get_changelist(request)
        try:
            cl = ChangeList(request, self.model, self.list_display,
                            self.list_display_links, self.list_filter, self.date_hierarchy,
                            self.search_fields, self.list_select_related, self.list_per_page,
                            self.list_max_show_all, self.list_editable, self)
            return cl

        except IncorrectLookupParameters:
            raise Exception("IncorrectLookupParameters") 
开发者ID:erdem,项目名称:django-admino,代码行数:13,代码来源:sites.py

示例5: test_fieldlistfilter_invalid_lookup_parameters

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def test_fieldlistfilter_invalid_lookup_parameters(self):
        """Filtering by an invalid value."""
        modeladmin = BookAdmin(Book, site)
        request = self.request_factory.get('/', {'author__id__exact': 'StringNotInteger!'})
        request.user = self.alfred
        with self.assertRaises(IncorrectLookupParameters):
            modeladmin.get_changelist_instance(request) 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:tests.py

示例6: test_invalid_params

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def test_invalid_params(self):
        tests = (
            {'year': 'x'},
            {'year': 2017, 'month': 'x'},
            {'year': 2017, 'month': 12, 'day': 'x'},
            {'year': 2017, 'month': 13},
            {'year': 2017, 'month': 12, 'day': 32},
            {'year': 2017, 'month': 0},
            {'year': 2017, 'month': 12, 'day': 0},
        )
        for invalid_query in tests:
            with self.subTest(query=invalid_query), self.assertRaises(IncorrectLookupParameters):
                self.assertDateParams(invalid_query, None, None) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:test_date_hierarchy.py

示例7: get_filters

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def get_filters(self, request):
        lookup_params = self.get_filters_params()
        use_distinct = False

        filter_specs = []
        if self.list_filter:
            for list_filter in self.list_filter:
                if callable(list_filter):
                    # This is simply a custom list filter class.
                    spec = list_filter(
                        request,
                        lookup_params,
                        self.model,
                        self.model_admin)
                else:
                    field_path = None
                    if isinstance(list_filter, (tuple, list)):
                        # This is a custom FieldListFilter class for a given
                        # field.
                        field, field_list_filter_class = list_filter
                    else:
                        # This is simply a field name, so use the default
                        # FieldListFilter class that has been registered for
                        # the type of the given field.
                        field = list_filter
                        field_list_filter_class = FieldListFilter.create
                    if not isinstance(field, models.Field):
                        field_path = field
                        field = get_fields_from_path(self.model,
                                                     field_path)[-1]
                    spec = field_list_filter_class(
                        field,
                        request,
                        lookup_params,
                        self.model,
                        self.model_admin,
                        field_path=field_path)

                    # Check if we need to use distinct()
                    use_distinct = (
                        use_distinct or lookup_needs_distinct(self.opts,
                                                              field_path))
                if spec and spec.has_output():
                    filter_specs.append(spec)

        # At this point, all the parameters used by the various ListFilters
        # have been removed from lookup_params, which now only contains other
        # parameters passed via the query string. We now loop through the
        # remaining parameters both to ensure that all the parameters are valid
        # fields and to determine if at least one of them needs distinct(). If
        # the lookup parameters aren't real fields, then bail out.
        try:
            for key, value in lookup_params.items():
                lookup_params[key] = prepare_lookup_value(key, value)
                use_distinct = (
                    use_distinct or lookup_needs_distinct(self.opts, key))
            return (
                filter_specs, bool(filter_specs), lookup_params, use_distinct
            )
        except FieldDoesNotExist as e:
            raise IncorrectLookupParameters from e 
开发者ID:wagtail,项目名称:wagtail,代码行数:63,代码来源:views.py

示例8: get_queryset

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def get_queryset(self, request=None):
        request = request or self.request

        # First, we collect all the declared list filters.
        (self.filter_specs, self.has_filters, remaining_lookup_params,
         filters_use_distinct) = self.get_filters(request)

        # Then, we let every list filter modify the queryset to its liking.
        qs = self.get_base_queryset(request)
        for filter_spec in self.filter_specs:
            new_qs = filter_spec.queryset(request, qs)
            if new_qs is not None:
                qs = new_qs

        try:
            # Finally, we apply the remaining lookup parameters from the query
            # string (i.e. those that haven't already been processed by the
            # filters).
            qs = qs.filter(**remaining_lookup_params)
        except (SuspiciousOperation, ImproperlyConfigured):
            # Allow certain types of errors to be re-raised as-is so that the
            # caller can treat them in a special way.
            raise
        except Exception as e:
            # Every other error is caught with a naked except, because we don't
            # have any other way of validating lookup parameters. They might be
            # invalid if the keyword arguments are incorrect, or if the values
            # are not in the correct type, so we might get FieldError,
            # ValueError, ValidationError, or ?.
            raise IncorrectLookupParameters(e)

        if not qs.query.select_related:
            qs = self.apply_select_related(qs)

        # Set ordering.
        ordering = self.get_ordering(request, qs)
        qs = qs.order_by(*ordering)

        # Remove duplicates from results, if necessary
        if filters_use_distinct:
            qs = qs.distinct()

        # Apply search results
        return self.get_search_results(request, qs, self.query) 
开发者ID:wagtail,项目名称:wagtail,代码行数:46,代码来源:views.py

示例9: get_queryset

# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import IncorrectLookupParameters [as 别名]
def get_queryset(self, request):
        # First, we collect all the declared list filters.
        (self.filter_specs, self.has_filters, remaining_lookup_params,
         filters_use_distinct) = self.get_filters(request)

        # Then, we let every list filter modify the queryset to its liking.
        qs = self.get_base_queryset(request)
        for filter_spec in self.filter_specs:
            new_qs = filter_spec.queryset(request, qs)
            if new_qs is not None:
                qs = new_qs

        try:
            # Finally, we apply the remaining lookup parameters from the query
            # string (i.e. those that haven't already been processed by the
            # filters).
            qs = qs.filter(**remaining_lookup_params)
        except (SuspiciousOperation, ImproperlyConfigured):
            # Allow certain types of errors to be re-raised as-is so that the
            # caller can treat them in a special way.
            raise
        except Exception as e:
            # Every other error is caught with a naked except, because we don't
            # have any other way of validating lookup parameters. They might be
            # invalid if the keyword arguments are incorrect, or if the values
            # are not in the correct type, so we might get FieldError,
            # ValueError, ValidationError, or ?.
            raise IncorrectLookupParameters(e)

        if not qs.query.select_related:
            qs = self.apply_select_related(qs)

        # Set ordering.
        ordering = self.get_ordering(request, qs)
        qs = qs.order_by(*ordering)

        # Apply search results
        qs, search_use_distinct = self.get_search_results(
            request, qs, self.query)

        # Remove duplicates from results, if necessary
        if filters_use_distinct | search_use_distinct:
            return qs.distinct()
        else:
            return qs 
开发者ID:rkhleics,项目名称:wagtailmodeladmin,代码行数:47,代码来源:views.py


注:本文中的django.contrib.admin.options.IncorrectLookupParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。