當前位置: 首頁>>代碼示例>>Python>>正文


Python django.apps方法代碼示例

本文整理匯總了Python中django.apps方法的典型用法代碼示例。如果您正苦於以下問題:Python django.apps方法的具體用法?Python django.apps怎麽用?Python django.apps使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django的用法示例。


在下文中一共展示了django.apps方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_installed_apps

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def get_installed_apps():
    """
    Return list of all installed apps
    """
    if django.VERSION >= (1, 7):
        from django.apps import apps

        return [
            a.models_module
            for a in apps.get_app_configs()
            if a.models_module is not None
        ]
    else:
        from django.db import models

        return models.get_apps() 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:18,代碼來源:utils.py

示例2: test_get_fields_only_searches_forward_on_apps_not_ready

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def test_get_fields_only_searches_forward_on_apps_not_ready(self):
        opts = CassandraThing._meta
        # If apps registry is not ready, get_field() searches over only
        # forward fields.
        opts.apps.models_ready = False
        try:
            # 'data_abstract' is a forward field, and therefore will be found
            self.assertTrue(opts.get_field('data_abstract'))
            msg = (
                "CassandraThing has no field named 'relating_baseperson'. The app "
                "cache isn't ready yet, so if this is an auto-created related "
                "field, it won't be available yet."
            )
            # 'data_abstract' is a reverse field, and will raise an exception
            with self.assertRaisesMessage(FieldDoesNotExist, msg):
                opts.get_field('relating_baseperson')
        finally:
            opts.apps.models_ready = True 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:20,代碼來源:tests.py

示例3: setup_django

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def setup_django():
    import django
    from django.conf import settings
    if not settings.configured:
        settings.configure(
            DEBUG=True,
            DATABASES={
                'default': {
                    'ENGINE': 'django.db.backends.sqlite3',
                    'NAME': ':memory:',
                }
            },
            INSTALLED_APPS=(
                'django.contrib.admin',
                'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.sessions',
                'django.contrib.messages',
                'django_ftpserver',
            )
        )
    django.setup()
    from django.apps import apps
    if not apps.ready:
        apps.populate() 
開發者ID:tokibito,項目名稱:django-ftpserver,代碼行數:27,代碼來源:conf.py

示例4: get_test_modules

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def get_test_modules():
    modules = []
    discovery_paths = [(None, RUNTESTS_DIR)]
    if connection.features.gis_enabled:
        # GIS tests are in nested apps
        discovery_paths.append(('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')))
    else:
        SUBDIRS_TO_SKIP.append('gis_tests')

    for modpath, dirpath in discovery_paths:
        for f in os.scandir(dirpath):
            if ('.' not in f.name and
                    os.path.basename(f.name) not in SUBDIRS_TO_SKIP and
                    not f.is_file() and
                    os.path.exists(os.path.join(f.path, '__init__.py'))):
                modules.append((modpath, f.name))
    return modules 
開發者ID:ra-systems,項目名稱:django-ra-erp,代碼行數:19,代碼來源:runtests.py

示例5: mock_django_setup

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def mock_django_setup(settings_module, disabled_features=None):
    """ Must be called *AT IMPORT TIME* to pretend that Django is set up.

    This is useful for running tests without using the Django test runner.
    This must be called before any Django models are imported, or they will
    complain. Call this from a module in the calling project at import time,
    then be sure to import that module at the start of all mock test modules.
    Another option is to call it from the test package's init file, so it runs
    before all the test modules are imported.
    :param settings_module: the module name of the Django settings file,
        like 'myapp.settings'
    :param disabled_features: a list of strings that should be marked as
        *False* on the connection features list. All others will default
        to True.
    """
    if apps.ready:
        # We're running in a real Django unit test, don't do anything.
        return

    if 'DJANGO_SETTINGS_MODULE' not in os.environ:
        os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
    django.setup()
    mock_django_connection(disabled_features) 
開發者ID:stphivos,項目名稱:django-mock-queries,代碼行數:25,代碼來源:mocks.py

示例6: test_install_middleware_old_style

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def test_install_middleware_old_style(list_or_tuple, preinstalled):
    if preinstalled:
        middleware = list_or_tuple(
            [
                "scout_apm.django.middleware.OldStyleMiddlewareTimingMiddleware",
                "django.middleware.common.CommonMiddleware",
                "scout_apm.django.middleware.OldStyleViewMiddleware",
            ]
        )
    else:
        middleware = list_or_tuple(["django.middleware.common.CommonMiddleware"])

    with override_settings(MIDDLEWARE_CLASSES=middleware):
        apps.get_app_config("scout_apm").install_middleware()

        assert settings.MIDDLEWARE_CLASSES == list_or_tuple(
            [
                "scout_apm.django.middleware.OldStyleMiddlewareTimingMiddleware",
                "django.middleware.common.CommonMiddleware",
                "scout_apm.django.middleware.OldStyleViewMiddleware",
            ]
        ) 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:24,代碼來源:test_django.py

示例7: test_install_middleware_new_style

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def test_install_middleware_new_style(list_or_tuple, preinstalled):
    if preinstalled:
        middleware = list_or_tuple(
            [
                "scout_apm.django.middleware.MiddlewareTimingMiddleware",
                "django.middleware.common.CommonMiddleware",
                "scout_apm.django.middleware.ViewTimingMiddleware",
            ]
        )
    else:
        middleware = list_or_tuple(["django.middleware.common.CommonMiddleware"])

    with override_settings(MIDDLEWARE=middleware):
        apps.get_app_config("scout_apm").install_middleware()

        assert settings.MIDDLEWARE == list_or_tuple(
            [
                "scout_apm.django.middleware.MiddlewareTimingMiddleware",
                "django.middleware.common.CommonMiddleware",
                "scout_apm.django.middleware.ViewTimingMiddleware",
            ]
        ) 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:24,代碼來源:test_django.py

示例8: get_test_modules

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def get_test_modules():
    modules = []
    discovery_paths = [(None, RUNTESTS_DIR)]
    if connection.features.gis_enabled:
        # GIS tests are in nested apps
        discovery_paths.append(('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')))
    else:
        SUBDIRS_TO_SKIP.append('gis_tests')

    for modpath, dirpath in discovery_paths:
        for f in os.listdir(dirpath):
            if ('.' in f or
                    os.path.basename(f) in SUBDIRS_TO_SKIP or
                    os.path.isfile(f) or
                    not os.path.exists(os.path.join(dirpath, f, '__init__.py'))):
                continue
            modules.append((modpath, f))
    return modules 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:20,代碼來源:runtests.py

示例9: get_test_modules

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def get_test_modules():
    modules = []
    discovery_paths = [(None, RUNTESTS_DIR)]
    if connection.features.gis_enabled:
        # GIS tests are in nested apps
        discovery_paths.append(('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')))
    else:
        SUBDIRS_TO_SKIP.append('gis_tests')

    for modpath, dirpath in discovery_paths:
        for f in os.listdir(dirpath):
            if ('.' not in f and
                    os.path.basename(f) not in SUBDIRS_TO_SKIP and
                    not os.path.isfile(f) and
                    os.path.exists(os.path.join(dirpath, f, '__init__.py'))):
                modules.append((modpath, f))
    return modules 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:runtests.py

示例10: test_migrate_to_form_question_natural_key_reverse

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def test_migrate_to_form_question_natural_key_reverse(transactional_db):
    executor = MigrationExecutor(connection)
    app = "caluma_form"
    migrate_from = [(app, "0024_auto_20190919_1244")]
    migrate_to = [(app, "0023_auto_20190729_1448")]

    executor.migrate(migrate_from)
    old_apps = executor.loader.project_state(migrate_from).apps

    # Create some old data. Can't use factories here

    Form = old_apps.get_model(app, "Form")
    Question = old_apps.get_model(app, "Question")
    FormQuestion = old_apps.get_model(app, "FormQuestion")

    form_1 = Form.objects.create(slug="form-1")

    question_1 = Question.objects.create(type="text", slug="question-1")
    FormQuestion.objects.create(form=form_1, question=question_1)

    # Migrate backwards.
    executor.loader.build_graph()  # reload.
    with pytest.raises(DataError):
        executor.migrate(migrate_to) 
開發者ID:projectcaluma,項目名稱:caluma,代碼行數:26,代碼來源:test_migration.py

示例11: get_commands

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def get_commands():
    """
    Returns a dictionary mapping command names to their callback applications.

    This works by looking for a management.commands package in django.core, and
    in each installed application -- if a commands package exists, all commands
    in that package are registered.

    Core commands are always included. If a settings module has been
    specified, user-defined commands will also be included.

    The dictionary is in the format {command_name: app_name}. Key-value
    pairs from this dictionary can then be used in calls to
    load_command_class(app_name, command_name)

    If a specific version of a command must be loaded (e.g., with the
    startapp command), the instantiated module can be placed in the
    dictionary in place of the application name.

    The dictionary is cached on the first call and reused on subsequent
    calls.
    """
    commands = {name: 'django.core' for name in find_commands(upath(__path__[0]))}

    if not settings.configured:
        return commands

    for app_config in reversed(list(apps.get_app_configs())):
        path = os.path.join(app_config.path, 'management')
        commands.update({name: app_config.name for name in find_commands(path)})

    return commands 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:34,代碼來源:__init__.py

示例12: handle

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def handle(self, *app_labels, **options):
        from django.apps import apps
        try:
            app_configs = [apps.get_app_config(app_label) for app_label in app_labels]
        except (LookupError, ImportError) as e:
            raise CommandError("%s. Are you sure your INSTALLED_APPS setting is correct?" % e)
        output = []
        for app_config in app_configs:
            app_output = self.handle_app_config(app_config, **options)
            if app_output:
                output.append(app_output)
        return '\n'.join(output) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:14,代碼來源:base.py

示例13: setUp

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def setUp(self):
        # Taken from IsolatedModelsTestCase in
        # django/tests/invalid_models_tests/base.py
        from django.apps import apps

        self._old_models = apps.app_configs["tests"].models.copy() 
開發者ID:MarkusH,項目名稱:django-osm-field,代碼行數:8,代碼來源:test_fields.py

示例14: tearDown

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def tearDown(self):
        # Taken from IsolatedModelsTestCase in
        # django/tests/invalid_models_tests/base.py
        from django.apps import apps

        apps.app_configs["tests"].models = self._old_models
        apps.all_models["tests"] = self._old_models
        apps.clear_cache() 
開發者ID:MarkusH,項目名稱:django-osm-field,代碼行數:10,代碼來源:test_fields.py

示例15: is_installed

# 需要導入模塊: import django [as 別名]
# 或者: from django import apps [as 別名]
def is_installed(appname):
        return appname in settings.INSTALLED_APPS #or apps.is_installed(appname) 
開發者ID:82Flex,項目名稱:DCRM,代碼行數:4,代碼來源:compat.py


注:本文中的django.apps方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。