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


Python apps.get_app_config方法代码示例

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


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

示例1: make_state_items

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def make_state_items(self):
        state_items = [
            {
                'model_name': app._meta.model_name,
                'verbose_name': app._meta.verbose_name,
                'icon': app._meta.icon,
                'icon_color': 'bg-' + app._meta.icon_color,
                'level': app._meta.level,
                'metric': app._meta.metric,
                'count': app.objects.filter(
                    onidc=self.request.user.onidc).filter(
                    **app._meta.default_filters).count(),
            } for app in apps.get_app_config('idcops').get_models() if getattr(
                app._meta,
                'dashboard')]
        return state_items 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:18,代码来源:views.py

示例2: construct_menus

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def construct_menus():
    model_names = []
    for app in apps.get_app_config('idcops').get_models():
        opts = app._meta
        if not getattr(opts, 'hidden', False):
            meta = {
                'model_name': opts.model_name,
                'verbose_name': opts.verbose_name,
                'icon': opts.icon,
                'icon_color': 'text-' + opts.icon_color,
                'level': opts.level,
            }
            model_names.append(meta)
    counts = list(set([i.get('level') for i in model_names]))
    new_menus = []
    for i in counts:
        new_menus.append(
            [c for c in model_names if c.get('level') == i]
        )
    return new_menus 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:22,代码来源:mixins.py

示例3: initial_user_config

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def initial_user_config(instance, created, **kwargs):
    if created:
        models = apps.get_app_config('idcops').get_models()
        exclude = ['onidc', 'deleted', 'mark']
        configures = []
        for model in models:
            fds = [f for f in fields_for_model(model) if f not in exclude]
            _fields = getattr(model._meta, 'list_display', fds)
            fields = _fields if isinstance(_fields, list) else fds
            content = {'list_only_date': 1, 'list_display': fields}
            config = dict(
                onidc=instance.onidc,
                creator=instance,
                mark='list',
                content_type=get_content_type_for_model(model),
                content=json.dumps(content),
            )
            configures.append(Configure(**config))
        Configure.objects.bulk_create(configures) 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:21,代码来源:signals.py

示例4: handle

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def handle(self, *args, **options):
        ethereum_client = EthereumClientProvider()
        app_name = apps.get_app_config('relay').verbose_name
        network_name = ethereum_client.get_network().name.capitalize()
        startup_message = f'Starting {app_name} version {__version__} on {network_name}'
        self.stdout.write(self.style.SUCCESS(startup_message))

        if settings.SLACK_API_WEBHOOK:
            try:
                r = requests.post(settings.SLACK_API_WEBHOOK, json={'text': startup_message})
                if r.ok:
                    self.stdout.write(self.style.SUCCESS(f'Slack configured, "{startup_message}" sent'))
                else:
                    raise RequestException()
            except RequestException:
                self.stdout.write(self.style.ERROR('Cannot send slack notification'))
        else:
            self.stdout.write(self.style.SUCCESS('Slack not configured, ignoring')) 
开发者ID:gnosis,项目名称:safe-relay-service,代码行数:20,代码来源:send_slack_notification.py

示例5: setUp

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def setUp(self):
        class Meta:
            permissions = (
                ("copy_apptestmodel3", "Can copy apptestmodel3"),
            )

        attrs_1 = {
            '__module__': 'tests.test_app.models',
        }
        attrs_2 = {
            '__module__': 'tests.test_app.models',
            'Meta': Meta,
        }

        self.appconfig = apps.get_app_config('test_app')
        self.model1 = type(str('AppTestModel1'), (models.Model, ),
                           attrs_1.copy())
        self.model2 = type(str('AppTestModel2'), (models.Model, ),
                           attrs_1.copy())
        self.model3 = type(str('AppTestModel3'), (models.Model, ),
                           attrs_2.copy()) 
开发者ID:ctxis,项目名称:django-admin-view-permission,代码行数:23,代码来源:test_apps.py

示例6: test_signal_receiver_registered_in_test

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def test_signal_receiver_registered_in_test(mocker, signal):
    """Ensure migration signal receivers registered in tests are called."""
    signal_receiver_mock = mocker.MagicMock()
    main_app_config = apps.get_app_config('main_app')
    signal.connect(
        signal_receiver_mock,
        sender=main_app_config,
        dispatch_uid=DISPATCH_UID,
    )
    verbosity = 0
    interactive = False
    # call `migrate` management command to trigger ``pre_migrate`` and
    # ``post_migrate`` signals
    call_command('migrate', verbosity=verbosity, interactive=interactive)

    signal_receiver_mock.assert_called_once_with(
        sender=main_app_config,
        app_config=main_app_config,
        apps=mocker.ANY,  # we don't have any reference to this object
        using=DEFAULT_DB_ALIAS,
        verbosity=verbosity,
        interactive=interactive,
        plan=mocker.ANY,  # not important for this test
        signal=signal,
    ) 
开发者ID:wemake-services,项目名称:django-test-migrations,代码行数:27,代码来源:test_signals.py

示例7: prepare

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def prepare(self):
        """Connect testing ``pre_migrate`` and ``post_migrate`` receivers."""
        self.pre_migrate_receiver_mock = mock.MagicMock()
        self.post_migrate_receiver_mock = mock.MagicMock()
        # ``old_apps`` is not real ``ProjectState`` instance, so we cannot use
        # it to get "original" main_app ``AppConfig`` instance needed to
        # connect signal receiver, that's the reason we are using
        # ``apps`` imported directly from ``django.apps``
        self.main_app_config = apps.get_app_config('main_app')
        pre_migrate.connect(
            self.pre_migrate_receiver_mock,
            sender=self.main_app_config,
        )
        post_migrate.connect(
            self.post_migrate_receiver_mock,
            sender=self.main_app_config,
        ) 
开发者ID:wemake-services,项目名称:django-test-migrations,代码行数:19,代码来源:test_signals.py

示例8: app_index

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def app_index(self, request, app_label, extra_context=None):
        app_dict = self._build_app_dict(request, app_label)
        if not app_dict:
            raise Http404('The requested admin page does not exist.')
        # Sort the models alphabetically within each app.
        app_dict['models'].sort(key=lambda x: x['name'])
        app_name = apps.get_app_config(app_label).verbose_name
        context = dict(
            self.each_context(request),
            title=_('%(app)s administration') % {'app': app_name},
            app_list=[app_dict],
            app_label=app_label,
        )
        context.update(extra_context or {})

        request.current_app = self.name

        return TemplateResponse(request, self.app_index_template or [
            'admin/%s/app_index.html' % app_label,
            'admin/app_index.html'
        ], context)


# This global object represents the default admin site, for the common case.
# You can instantiate AdminSite in your own code to create a custom admin site. 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:sites.py

示例9: get_view_names

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def get_view_names(seo_views):
    output = []
    for name in seo_views:
        try:
            app = apps.get_app_config(name).models_module
        except:
            output.append(name)
        else:
            app_name = app.__name__.split(".")[:-1]
            app_name.append("urls")
            try:
                urls = importlib.import_module(".".join(app_name)).urlpatterns
            except (ImportError, AttributeError):
                output.append(name)
            else:
                for url in urls:
                    if getattr(url, 'name', None):
                        output.append(url.name)
    return output 
开发者ID:whyflyru,项目名称:django-seo,代码行数:21,代码来源:systemviews.py

示例10: _set_seo_models

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def _set_seo_models(self, value):
        """ Gets the actual models to be used. """
        seo_models = []
        for model_name in value:
            if "." in model_name:
                app_label, model_name = model_name.split(".", 1)
                model = apps.get_model(app_label, model_name)
                if model:
                    seo_models.append(model)
            else:
                app = apps.get_app_config(model_name)
                if app:
                    seo_models.extend(app.get_models())

        # This fix the trouble on Django 1.9 when django-seo conflicts with session model
        seo_models = [
            model for model in seo_models if model._meta.model_name != 'session' and model._meta.app_label != 'sessions'
        ]

        self.seo_models = seo_models 
开发者ID:whyflyru,项目名称:django-seo,代码行数:22,代码来源:options.py

示例11: test_do_drop_all_analytics_tables

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def test_do_drop_all_analytics_tables(self) -> None:
        user = self.create_user()
        stream = self.create_stream_with_recipient()[0]
        count_args = {'property': 'test', 'end_time': self.TIME_ZERO, 'value': 10}

        UserCount.objects.create(user=user, realm=user.realm, **count_args)
        StreamCount.objects.create(stream=stream, realm=stream.realm, **count_args)
        RealmCount.objects.create(realm=user.realm, **count_args)
        InstallationCount.objects.create(**count_args)
        FillState.objects.create(property='test', end_time=self.TIME_ZERO, state=FillState.DONE)

        analytics = apps.get_app_config('analytics')
        for table in list(analytics.models.values()):
            self.assertTrue(table.objects.exists())

        do_drop_all_analytics_tables()
        for table in list(analytics.models.values()):
            self.assertFalse(table.objects.exists()) 
开发者ID:zulip,项目名称:zulip,代码行数:20,代码来源:test_counts.py

示例12: test_do_drop_single_stat

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def test_do_drop_single_stat(self) -> None:
        user = self.create_user()
        stream = self.create_stream_with_recipient()[0]
        count_args_to_delete = {'property': 'to_delete', 'end_time': self.TIME_ZERO, 'value': 10}
        count_args_to_save = {'property': 'to_save', 'end_time': self.TIME_ZERO, 'value': 10}

        for count_args in [count_args_to_delete, count_args_to_save]:
            UserCount.objects.create(user=user, realm=user.realm, **count_args)
            StreamCount.objects.create(stream=stream, realm=stream.realm, **count_args)
            RealmCount.objects.create(realm=user.realm, **count_args)
            InstallationCount.objects.create(**count_args)
        FillState.objects.create(property='to_delete', end_time=self.TIME_ZERO, state=FillState.DONE)
        FillState.objects.create(property='to_save', end_time=self.TIME_ZERO, state=FillState.DONE)

        analytics = apps.get_app_config('analytics')
        for table in list(analytics.models.values()):
            self.assertTrue(table.objects.exists())

        do_drop_single_stat('to_delete')
        for table in list(analytics.models.values()):
            self.assertFalse(table.objects.filter(property='to_delete').exists())
            self.assertTrue(table.objects.filter(property='to_save').exists()) 
开发者ID:zulip,项目名称:zulip,代码行数:24,代码来源:test_counts.py

示例13: app_index

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def app_index(self, request, app_label, extra_context=None):
        app_name = apps.get_app_config(app_label).verbose_name
        context = self.each_context(request)
        app_list = context['app_list']
        current_app_list = get_from_list(False, app_list, 'app_label', app_label)
        context.update(dict(
            title=_('%(app)s administration') % {'app': app_name},
            # current_app_list=[app_dict],
            current_app_list=[current_app_list],
            app_label=app_label,
            app_name=app_name,
        ))
        context.update(extra_context or {})
        request.current_app = self.name

        return TemplateResponse(request, self.app_index_template or [
            'admin/%s/app_index.html' % app_label,
            'admin/app_index.html'
        ], context) 
开发者ID:ra-systems,项目名称:django-ra-erp,代码行数:21,代码来源:base.py

示例14: app_index

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def app_index(self, request, app_label, extra_context=None):
        app_dict = self._build_app_dict(request, app_label)
        if not app_dict:
            raise Http404('The requested admin page does not exist.')
        # Sort the models alphabetically within each app.
        app_dict['models'].sort(key=lambda x: x['name'])
        app_name = apps.get_app_config(app_label).verbose_name
        context = {
            **self.each_context(request),
            'title': _('%(app)s administration') % {'app': app_name},
            'app_list': [app_dict],
            'app_label': app_label,
            **(extra_context or {}),
        }

        request.current_app = self.name

        return TemplateResponse(request, self.app_index_template or [
            'admin/%s/app_index.html' % app_label,
            'admin/app_index.html'
        ], context) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:23,代码来源:sites.py

示例15: get_index_mapping

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_config [as 别名]
def get_index_mapping(index: str) -> dict:
    """
    Return the JSON mapping file for an index.

    Mappings are stored as JSON files in the mappings subdirectory of this
    app. They must be saved as {{index}}.json.

    Args:
        index: string, the name of the index to look for.

    """
    # app_path = apps.get_app_config('elasticsearch_django').path
    mappings_dir = get_setting("mappings_dir")
    filename = "%s.json" % index
    path = os.path.join(mappings_dir, filename)
    with open(path, "r") as f:
        return json.load(f) 
开发者ID:yunojuno,项目名称:elasticsearch-django,代码行数:19,代码来源:settings.py


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