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


Python checks.Error方法代码示例

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


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

示例1: actions_have_consistent_hashes

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def actions_have_consistent_hashes(app_configs, **kwargs):
    errors = []
    try:
        Action = apps.get_model("recipes", "Action")
        actions = list(Action.objects.filter(implementation__isnull=False))
    except (ProgrammingError, OperationalError, ImproperlyConfigured) as e:
        errors.append(Info(f"Could not retrieve actions: {e}", id=INFO_COULD_NOT_RETRIEVE_ACTIONS))
    else:
        for action in actions:
            if action.compute_implementation_hash() != action.implementation_hash:
                msg = "Action '{action}' (id={action.id}) has a mismatched hash".format(
                    action=action
                )
                errors.append(Error(msg, id=ERROR_MISMATCHED_ACTION_HASH))

    return errors 
开发者ID:mozilla,项目名称:normandy,代码行数:18,代码来源:checks.py

示例2: geoip_db_is_available

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def geoip_db_is_available(app_configs, **kwargs):
    errors = []
    if geolocation.geoip_reader is None:
        # try loading it
        geolocation.load_geoip_database()
        if geolocation.geoip_reader is None:
            errors.append(Error("GeoIP DB not available", id=ERROR_GEOIP_DB_NOT_AVAILABLE))

    if not errors:
        # DB seems to be available, try and do a lookup that should resolve to
        # some country. The specific country isn't important.
        ip = "1.2.3.4"
        country = geolocation.get_country_code(ip)
        if country is None:
            errors.append(
                Error(
                    f"GeoIP DB returned no country for {ip!r}", id=ERROR_GEOIP_DB_UNEXPECTED_RESULT
                )
            )

    return errors 
开发者ID:mozilla,项目名称:normandy,代码行数:23,代码来源:checks.py

示例3: check

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def check(cls, **kwargs):
        """
        We use .session_key and CSRF_COOKIE above: check that they will be there, and fail fast if not.
        """
        errors = super().check(**kwargs)

        # Ensure we are using the database session store. (Other SessionStores may also have .session_key?)
        engine = import_module(settings.SESSION_ENGINE)
        store = engine.SessionStore
        if not issubclass(store, DatabaseSessionStore):
            errors.append(Error(
                "Quiz logging uses request.session.session_key, which likely implies "
                "SESSION_ENGINE = 'django.contrib.sessions.backends.db' in settings."
            ))

        if 'django.middleware.csrf.CsrfViewMiddleware' not in settings.MIDDLEWARE:
            errors.append(Error(
                "CsrfViewMiddleware is not enabled in settings: quiz logging uses CSRF_COOKIE and will fail without "
                "CSRF checking enabled. Also it should be enabled in general."
            ))

        return errors 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:models.py

示例4: _check_column_name_clashes

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_column_name_clashes(cls):
        # Store a list of column names which have already been used by other fields.
        used_column_names = []
        errors = []

        for f in cls._meta.local_fields:
            _, column_name = f.get_attname_column()

            # Ensure the column name is not already in use.
            if column_name and column_name in used_column_names:
                errors.append(
                    checks.Error(
                        "Field '%s' has column name '%s' that is used by "
                        "another field." % (f.name, column_name),
                        hint="Specify a 'db_column' for the field.",
                        obj=cls,
                        id='models.E007'
                    )
                )
            else:
                used_column_names.append(column_name)

        return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:25,代码来源:base.py

示例5: _check_referencing_to_swapped_model

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_referencing_to_swapped_model(self):
        if (self.rel.to not in apps.get_models() and
                not isinstance(self.rel.to, six.string_types) and
                self.rel.to._meta.swapped):
            model = "%s.%s" % (
                self.rel.to._meta.app_label,
                self.rel.to._meta.object_name
            )
            return [
                checks.Error(
                    ("Field defines a relation with the model '%s', "
                     "which has been swapped out.") % model,
                    hint="Update the relation to point at 'settings.%s'." % self.rel.to._meta.swappable,
                    obj=self,
                    id='fields.E301',
                )
            ]
        return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:related.py

示例6: _check_on_delete

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_on_delete(self):
        on_delete = getattr(self.rel, 'on_delete', None)
        if on_delete == SET_NULL and not self.null:
            return [
                checks.Error(
                    'Field specifies on_delete=SET_NULL, but cannot be null.',
                    hint='Set null=True argument on the field, or change the on_delete rule.',
                    obj=self,
                    id='fields.E320',
                )
            ]
        elif on_delete == SET_DEFAULT and not self.has_default():
            return [
                checks.Error(
                    'Field specifies on_delete=SET_DEFAULT, but has no default value.',
                    hint='Set a default value, or change the on_delete rule.',
                    obj=self,
                    id='fields.E321',
                )
            ]
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:24,代码来源:related.py

示例7: _check_null_allowed_for_primary_keys

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_null_allowed_for_primary_keys(self):
        if (self.primary_key and self.null and
                not connection.features.interprets_empty_strings_as_nulls):
            # We cannot reliably check this for backends like Oracle which
            # consider NULL and '' to be equal (and thus set up
            # character-based fields a little differently).
            return [
                checks.Error(
                    'Primary keys must not have null=True.',
                    hint=('Set null=False on the field, or '
                          'remove primary_key=True argument.'),
                    obj=self,
                    id='fields.E007',
                )
            ]
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:__init__.py

示例8: _check_max_length_attribute

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_max_length_attribute(self, **kwargs):
        try:
            max_length = int(self.max_length)
            if max_length <= 0:
                raise ValueError()
        except TypeError:
            return [
                checks.Error(
                    "CharFields must define a 'max_length' attribute.",
                    hint=None,
                    obj=self,
                    id='fields.E120',
                )
            ]
        except ValueError:
            return [
                checks.Error(
                    "'max_length' must be a positive integer.",
                    hint=None,
                    obj=self,
                    id='fields.E121',
                )
            ]
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:__init__.py

示例9: _check_mutually_exclusive_options

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_mutually_exclusive_options(self):
        # auto_now, auto_now_add, and default are mutually exclusive
        # options. The use of more than one of these options together
        # will trigger an Error
        mutually_exclusive_options = [self.auto_now_add, self.auto_now,
                                      self.has_default()]
        enabled_options = [option not in (None, False)
                          for option in mutually_exclusive_options].count(True)
        if enabled_options > 1:
            return [
                checks.Error(
                    "The options auto_now, auto_now_add, and default "
                    "are mutually exclusive. Only one of these options "
                    "may be present.",
                    hint=None,
                    obj=self,
                    id='fields.E160',
                )
            ]
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:23,代码来源:__init__.py

示例10: _check_decimal_places

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_decimal_places(self):
        try:
            decimal_places = int(self.decimal_places)
            if decimal_places < 0:
                raise ValueError()
        except TypeError:
            return [
                checks.Error(
                    "DecimalFields must define a 'decimal_places' attribute.",
                    hint=None,
                    obj=self,
                    id='fields.E130',
                )
            ]
        except ValueError:
            return [
                checks.Error(
                    "'decimal_places' must be a non-negative integer.",
                    hint=None,
                    obj=self,
                    id='fields.E131',
                )
            ]
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:__init__.py

示例11: _check_max_digits

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_max_digits(self):
        try:
            max_digits = int(self.max_digits)
            if max_digits <= 0:
                raise ValueError()
        except TypeError:
            return [
                checks.Error(
                    "DecimalFields must define a 'max_digits' attribute.",
                    hint=None,
                    obj=self,
                    id='fields.E132',
                )
            ]
        except ValueError:
            return [
                checks.Error(
                    "'max_digits' must be a positive integer.",
                    hint=None,
                    obj=self,
                    id='fields.E133',
                )
            ]
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:__init__.py

示例12: _check_exclude

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_exclude(self, cls, model):
        """ Check that exclude is a sequence without duplicates. """

        if cls.exclude is None:  # default value is None
            return []
        elif not isinstance(cls.exclude, (list, tuple)):
            return must_be('a list or tuple', option='exclude', obj=cls, id='admin.E014')
        elif len(cls.exclude) > len(set(cls.exclude)):
            return [
                checks.Error(
                    "The value of 'exclude' contains duplicate field(s).",
                    hint=None,
                    obj=cls,
                    id='admin.E015',
                )
            ]
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:checks.py

示例13: _check_radio_fields_key

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_radio_fields_key(self, cls, model, field_name, label):
        """ Check that a key of `radio_fields` dictionary is name of existing
        field and that the field is a ForeignKey or has `choices` defined. """

        try:
            field = model._meta.get_field(field_name)
        except FieldDoesNotExist:
            return refer_to_missing_field(field=field_name, option=label,
                                          model=model, obj=cls, id='admin.E022')
        else:
            if not (isinstance(field, models.ForeignKey) or field.choices):
                return [
                    checks.Error(
                        "The value of '%s' refers to '%s', which is not an "
                        "instance of ForeignKey, and does not have a 'choices' definition." % (
                            label, field_name
                        ),
                        hint=None,
                        obj=cls,
                        id='admin.E023',
                    )
                ]
            else:
                return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:26,代码来源:checks.py

示例14: _check_radio_fields_value

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_radio_fields_value(self, cls, model, val, label):
        """ Check type of a value of `radio_fields` dictionary. """

        from django.contrib.admin.options import HORIZONTAL, VERTICAL

        if val not in (HORIZONTAL, VERTICAL):
            return [
                checks.Error(
                    "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
                    hint=None,
                    obj=cls,
                    id='admin.E024',
                )
            ]
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:18,代码来源:checks.py

示例15: _check_readonly_fields_item

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Error [as 别名]
def _check_readonly_fields_item(self, cls, model, field_name, label):
        if callable(field_name):
            return []
        elif hasattr(cls, field_name):
            return []
        elif hasattr(model, field_name):
            return []
        else:
            try:
                model._meta.get_field(field_name)
            except FieldDoesNotExist:
                return [
                    checks.Error(
                        "The value of '%s' is not a callable, an attribute of '%s', or an attribute of '%s.%s'." % (
                            label, cls.__name__, model._meta.app_label, model._meta.object_name
                        ),
                        hint=None,
                        obj=cls,
                        id='admin.E035',
                    )
                ]
            else:
                return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:25,代码来源:checks.py


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