python类AppConfig()的实例源码

apps.py 文件源码 项目:morango 作者: learningequality 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def ready(self):
        from django.core.management import call_command
        from morango.models import InstanceIDModel
        from morango.certificates import ScopeDefinition
        from .signals import add_to_deleted_models  # noqa: F401

        # NOTE: Warning: https://docs.djangoproject.com/en/1.10/ref/applications/#django.apps.AppConfig.ready
        # its recommended not to execute queries in this method, but we are producing the same result after the first call, so its OK

        # call this on app load up to get most recent system config settings
        try:
            InstanceIDModel.get_or_create_current_instance()
            if not ScopeDefinition.objects.filter():
                call_command("loaddata", "scopedefinitions")
        # we catch this error in case the database has not been migrated, b/c we can't query it until its been created
        except (OperationalError, ProgrammingError):
            pass

        # add models to be synced by profile
        add_syncable_models()
test_management_permissions.py 文件源码 项目:django-north 作者: peopledoc 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_get_all_contenttypes_for_app_config(mocker):
    model1 = mocker.Mock(_meta=mocker.Mock(model_name='mymodel1'))
    model2 = mocker.Mock(_meta=mocker.Mock(model_name='mymodel2'))
    ct1 = ContentType(app_label='myapp', model='mymodel1')
    ct2 = ContentType(app_label='myapp', model='mymodel2')
    app_config = CustomAppConfig('myapp', mocker.Mock())

    mocker.patch(
        'django.apps.AppConfig.get_models', return_value=[model1, model2])
    mock_get_for_model = mocker.patch(
        'django.contrib.contenttypes.models.ContentTypeManager.get')

    mock_get_for_model.side_effect = [ct1, ct2]
    result = permissions.get_all_contenttypes_for_app_config(app_config)

    assert result == [(ct1, model1), (ct2, model2)]

    mock_get_for_model.side_effect = [ct1, ContentType.DoesNotExist]
    result = permissions.get_all_contenttypes_for_app_config(app_config)

    assert result == [(ct1, model1)]
migrations.py 文件源码 项目:django-postgres-extra 作者: SectorLabs 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def __init__(self):
        """Creates a new migration simulator with an empty
        project state and no migrations."""

        import psqlextra.apps

        self.app_label = self._generate_random_name()
        self.app_config = type(self.app_label, (AppConfig,), dict(
            name=self.app_label,
            verbose_name=self.app_label
        ))(self.app_label, psqlextra.apps)

        self.app_config.models = {}

        self.apps = Apps()
        self.apps.ready = False
        self.apps.populate(installed_apps=[self.app_config])

        self.project_state = ProjectState()
        self.migrations = []
test_apps.py 文件源码 项目:fakester 作者: pawelad 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_redirects_app_config():
    """Test 'redirects' module `AppConfig` instance"""
    redirects_app_config = fakester_apps.get_app_config('redirects')

    assert isinstance(redirects_app_config, AppConfig)
    assert redirects_app_config.name == 'redirects'
    assert redirects_app_config.verbose_name == 'redirects'
apps.py 文件源码 项目:ecs 作者: ecs-org 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def ready(self):
        # XXX: should be imported in the AppConfig of the respective app itself
        import ecs.core.triggers
        import ecs.votes.triggers
        import ecs.meetings.triggers

        # Patch the user __str__ method, so the hash in the username field
        # does not show up.
        # XXX: We should be using a custom user model instead.
        from django.contrib.auth.models import User
        from ecs.users.utils import get_full_name
        User.__str__ = get_full_name
apps.py 文件源码 项目:cyphon 作者: dunbarcyber 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def ready(self):
        """Override the default :meth:`~django.apps.AppConfig.ready` method.

        Registers :mod:`~tags.signals` used in the app.
        """
        import tags.signals  # noqa: F401
apps.py 文件源码 项目:cyphon 作者: dunbarcyber 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def ready(self):
        """Override the default :meth:`~django.apps.AppConfig.ready` method.

        Registers :mod:`~distilleries.signals` used in the app.
        """
        import distilleries.signals  # noqa: F401
apps.py 文件源码 项目:cyphon 作者: dunbarcyber 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def ready(self):
        """Override the default :meth:`~django.apps.AppConfig.ready` method.

        Registers :mod:`~warehouses.signals` used in the app.
        """
        import warehouses.signals  # noqa: F401
test_management_contenttypes.py 文件源码 项目:django-north 作者: peopledoc 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_get_known_models_for_app_config(mocker):
    model1 = mocker.Mock(_meta=mocker.Mock(model_name='mymodel1'))
    model2 = mocker.Mock(_meta=mocker.Mock(model_name='mymodel2'))
    app_config = CustomAppConfig('myapp', mocker.Mock())

    mocker.patch(
        'django.apps.AppConfig.get_models', return_value=[model1, model2])

    result = contenttypes.get_known_models_for_app_config(app_config)

    assert result == {
        'mymodel1': model1,
        'mymodel2': model2,
    }
test_app.py 文件源码 项目:djangolg 作者: wolcomm 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_app_import(self):
        """Test importing djangolg app."""
        from djangolg import apps
        assert issubclass(apps.DjangolgConfig, AppConfig)
        assert apps.DjangolgConfig.name == "djangolg"


问题


面经


文章

微信
公众号

扫码关注公众号