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


Python checks.Critical方法代码示例

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


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

示例1: check_revision

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Critical [as 别名]
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 
开发者ID:evernote,项目名称:zing,代码行数:22,代码来源:checks.py

示例2: check_schema_names

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Critical [as 别名]
def check_schema_names(app_configs, **kwargs):
    errors = []
    static_names = set(settings.TENANTS.keys())
    clone_reference = get_clone_reference()
    if clone_reference:
        static_names.add(clone_reference)
    try:
        dynamic_names = set(get_tenant_model().objects.values_list("schema_name", flat=True))
    except ProgrammingError:
        # This happens on the first run of migrate, with empty database.
        # It can also happen when the tenant model contains unapplied migrations that break.
        dynamic_names = set()
    intersection = static_names & dynamic_names
    if intersection:
        errors.append(
            checks.Critical(
                "Name clash found between static and dynamic tenants: %s" % intersection, id="pgschemas.W004",
            )
        )
    return errors 
开发者ID:lorinkoz,项目名称:django-pgschemas,代码行数:22,代码来源:checks.py

示例3: check_redis

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Critical [as 别名]
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:
        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 
开发者ID:evernote,项目名称:zing,代码行数:37,代码来源:checks.py

示例4: test_name_clash

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Critical [as 别名]
def test_name_clash(self):
        backup_create = TenantModel.auto_create_schema
        TenantModel.auto_create_schema = False
        # public
        TenantModel.objects.create(schema_name="public")
        errors = check_schema_names(self.app_config)
        expected_errors = [
            checks.Critical("Name clash found between static and dynamic tenants: {'public'}", id="pgschemas.W004"),
        ]
        self.assertEqual(errors, expected_errors)
        TenantModel.objects.all().delete()
        # www
        TenantModel.objects.create(schema_name="www")
        errors = check_schema_names(self.app_config)
        expected_errors = [
            checks.Critical("Name clash found between static and dynamic tenants: {'www'}", id="pgschemas.W004"),
        ]
        self.assertEqual(errors, expected_errors)
        TenantModel.objects.all().delete()
        # sample
        TenantModel.objects.create(schema_name="sample")
        errors = check_schema_names(self.app_config)
        expected_errors = [
            checks.Critical("Name clash found between static and dynamic tenants: {'sample'}", id="pgschemas.W004"),
        ]
        self.assertEqual(errors, expected_errors)
        TenantModel.objects.all().delete()
        TenantModel.auto_create_schema = backup_create 
开发者ID:lorinkoz,项目名称:django-pgschemas,代码行数:30,代码来源:test_checks.py

示例5: test_is_anonymous_authenticated_methods

# 需要导入模块: from django.core import checks [as 别名]
# 或者: from django.core.checks import Critical [as 别名]
def test_is_anonymous_authenticated_methods(self):
        """
        <User Model>.is_anonymous/is_authenticated must not be methods.
        """
        class BadUser(AbstractBaseUser):
            username = models.CharField(max_length=30, unique=True)
            USERNAME_FIELD = 'username'

            def is_anonymous(self):
                return True

            def is_authenticated(self):
                return True

        errors = checks.run_checks(app_configs=self.apps.get_app_configs())
        self.assertEqual(errors, [
            checks.Critical(
                '%s.is_anonymous must be an attribute or property rather than '
                'a method. Ignoring this is a security issue as anonymous '
                'users will be treated as authenticated!' % BadUser,
                obj=BadUser,
                id='auth.C009',
            ),
            checks.Critical(
                '%s.is_authenticated must be an attribute or property rather '
                'than a method. Ignoring this is a security issue as anonymous '
                'users will be treated as authenticated!' % BadUser,
                obj=BadUser,
                id='auth.C010',
            ),
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:33,代码来源:test_checks.py


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