Python django.core.checks 模块,Critical() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.core.checks.Critical()

项目:dj-paypal    作者:HearthSim    | 项目源码 | 文件源码
def check_paypal_api_key(app_configs=None, **kwargs):
    """Check that the Paypal API keys are configured correctly"""
    messages = []

    mode = getattr(djpaypal_settings, "PAYPAL_MODE", None)
    if mode not in VALID_MODES:
        msg = "Invalid PAYPAL_MODE specified: {}.".format(repr(mode))
        hint = "PAYPAL_MODE must be one of {}".format(", ".join(repr(k) for k in VALID_MODES))
        messages.append(checks.Critical(msg, hint=hint, id="djpaypal.C001"))

    for setting in "PAYPAL_CLIENT_ID", "PAYPAL_CLIENT_SECRET":
        if not getattr(djpaypal_settings, setting, None):
            msg = "Invalid value specified for {}".format(setting)
            hint = "Add PAYPAL_CLIENT_ID and PAYPAL_CLIENT_SECRET to your settings."
            messages.append(checks.Critical(msg, hint=hint, id="djpaypal.C002"))

    return messages
项目:zing    作者:evernote    | 项目源码 | 文件源码
def check_revision(app_configs=None, **kwargs):
    from pootle.core.models import Revision
    from pootle_store.models import Unit

    errors = []
    revision = Revision.get()
    try:
        max_revision = Unit.max_revision()
    except (OperationalError, ProgrammingError):
        return errors
    if revision is None or revision < max_revision:
        errors.append(checks.Critical(
            _("Revision is missing or has an incorrect value."),
            hint=_("Run `revision --restore` to reset the revision counter."),
            id="pootle.C016",
        ))

    return errors
项目:zing    作者:evernote    | 项目源码 | 文件源码
def check_library_versions(app_configs=None, **kwargs):
    from django import VERSION as DJANGO_VERSION
    from lxml.etree import LXML_VERSION
    from translate.__version__ import ver as ttk_version

    errors = []

    if DJANGO_VERSION < DJANGO_MINIMUM_REQUIRED_VERSION:
        errors.append(checks.Critical(
            _("Your version of Django is too old."),
            hint=_("Try pip install --upgrade 'Django==%s'",
                   _version_to_string(DJANGO_MINIMUM_REQUIRED_VERSION)),
            id="pootle.C002",
        ))

    if LXML_VERSION < LXML_MINIMUM_REQUIRED_VERSION:
        errors.append(checks.Warning(
            _("Your version of lxml is too old."),
            hint=_("Try pip install --upgrade lxml"),
            id="pootle.W003",
        ))

    if ttk_version < TTK_MINIMUM_REQUIRED_VERSION:
        errors.append(checks.Critical(
            _("Your version of Translate Toolkit is too old."),
            hint=_("Try pip install --upgrade translate-toolkit"),
            id="pootle.C003",
        ))

    return errors
项目:zing    作者:evernote    | 项目源码 | 文件源码
def check_redis(app_configs=None, **kwargs):
    from django_rq.queues import get_queue
    from django_rq.workers import Worker

    errors = []

    try:
        queue = get_queue()
        Worker.all(queue.connection)
    except Exception as e:
        conn_settings = queue.connection.connection_pool.connection_kwargs
        errors.append(checks.Critical(
            _("Could not connect to Redis (%s)", e),
            hint=_("Make sure Redis is running on "
                   "%(host)s:%(port)s") % conn_settings,
            id="pootle.C001",
        ))
    else:
        redis_version = tuple(int(x) for x
                              in (queue.connection
                                       .info()["redis_version"].split(".")))
        if redis_version < REDIS_MINIMUM_REQUIRED_VERSION:
            errors.append(checks.Critical(
                _("Your version of Redis is too old."),
                hint=_("Update your system's Redis server package to at least "
                       "version %s", str(REDIS_MINIMUM_REQUIRED_VERSION)),
                id="pootle.C007",
            ))

        if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:
            # We need to check we're not running manage.py rqworker right now..
            import sys
            if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:
                errors.append(checks.Warning(
                    _("No RQ Worker running."),
                    hint=_("Run new workers with manage.py rqworker"),
                    id="pootle.W001",
                ))

    return errors
项目:zing    作者:evernote    | 项目源码 | 文件源码
def check_deprecated_settings(app_configs=None, **kwargs):
    errors = []

    for old, new, dep_ver, remove_ver in DEPRECATIONS:

        # Old setting just disappeared, we just want you to cleanup
        if hasattr(settings, old) and new is None:
            errors.append(checks.Info(
                ("Setting %s was removed in Pootle %s." %
                 (old, dep_ver)),
                hint=("Remove %s from your settings." % old),
                id="pootle.I002",
            ))
            continue

        # Both old and new defined, we'd like you to remove the old setting
        if hasattr(settings, old) and hasattr(settings, new):
            errors.append(checks.Info(
                ("Setting %s was replaced by %s in Pootle %s. Both are set." %
                 (old, new, dep_ver)),
                hint=("Remove %s from your settings." % old),
                id="pootle.I002",
            ))
            continue

        # Old setting is present and new setting is not defined:
        # - Warn and copy
        # - Fail hard if its too old
        if hasattr(settings, old) and not hasattr(settings, new):
            from pootle import VERSION
            if VERSION >= tuple(int(x) for x in remove_ver.split(".")):
                errors.append(checks.Critical(
                    ("Setting %s is deprecated and was removed in Pootle %s." %
                     (old, remove_ver)),
                    hint=("Use %s instead." % new),
                    id="pootle.W002",
                ))
            else:
                errors.append(checks.Warning(
                    ("Setting %s is deprecated and will be removed in "
                     "Pootle %s." % (old, remove_ver)),
                    hint=("Use %s instead." % new),
                    id="pootle.W002",
                ))
                setattr(settings, new, getattr(settings, old))
            continue

    return errors