本文整理汇总了Python中django.apps.apps.app_configs方法的典型用法代码示例。如果您正苦于以下问题:Python apps.app_configs方法的具体用法?Python apps.app_configs怎么用?Python apps.app_configs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.apps.apps
的用法示例。
在下文中一共展示了apps.app_configs方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: define_fake_model
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def define_fake_model(
fields=None, model_base=PostgresModel, meta_options={}, **attributes
):
"""Defines a fake model (but does not create it in the database)."""
name = str(uuid.uuid4()).replace("-", "")[:8].title()
attributes = {
"app_label": meta_options.get("app_label") or "tests",
"__module__": __name__,
"__name__": name,
"Meta": type("Meta", (object,), meta_options),
**attributes,
}
if fields:
attributes.update(fields)
model = type(name, (model_base,), attributes)
apps.app_configs[attributes["app_label"]].models[name] = model
return model
示例2: define_fake_app
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def define_fake_app():
"""Creates and registers a fake Django app."""
name = str(uuid.uuid4()).replace("-", "")[:8] + "-app"
app_config_cls = type(
name + "Config",
(AppConfig,),
{"name": name, "path": os.path.dirname(__file__)},
)
app_config = app_config_cls(name, "")
app_config.apps = apps
app_config.models = {}
apps.app_configs[name] = app_config
sys.modules[name] = {}
try:
yield app_config
finally:
del apps.app_configs[name]
del sys.modules[name]
示例3: simulate_checks
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def simulate_checks():
app_configs = apps.app_configs
errors = []
all_checks = registry.get_checks(False)
rest_registration_checks = [
check for check in all_checks
if check.__module__.startswith('rest_registration.')
]
for check in rest_registration_checks:
errors.extend(check(app_configs))
return errors
示例4: setUp
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [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()
示例5: tearDown
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [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()
示例6: get_context_data
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
app_list = []
for app_name, app_config in apps.app_configs.items():
if getattr(app_config, "events_module", None) is not None:
app_list.append(app_name)
app_list.sort()
context["apps"] = app_list
return context
示例7: get
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def get(self, request, *args, **kwargs):
app = kwargs['app']
try:
zentral_app = apps.app_configs[app]
search_dict = getattr(zentral_app.events_module, "ALL_EVENTS_SEARCH_DICT")
except (KeyError, AttributeError):
raise Http404
interval = kwargs["interval"]
try:
date_format = self.INTERVAL_DATE_FORMAT[interval]
except KeyError:
raise Http404
labels = []
event_count_data = []
unique_msn_data = []
for dt, event_count, unique_msn in frontend_store.get_app_hist_data(interval, int(kwargs["bucket_number"]),
**search_dict):
labels.append(dt.strftime(date_format))
event_count_data.append(event_count)
unique_msn_data.append(unique_msn)
datasets = {"event_count": {
"label": "{} events".format(app),
"backgroundColor": "rgba(120, 198, 188, 0.7)",
"data": event_count_data
},
"unique_msn": {
"label": "{} machines".format(app),
"backgroundColor": "rgba(234, 81, 100, 0.7)",
"data": unique_msn_data
}}
return JsonResponse({"app": app,
"labels": labels,
"datasets": datasets})
示例8: all_models
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def all_models(self):
models = []
for app_label in apps.app_configs:
models.extend(apps.get_app_config(app_label).get_models())
return models
示例9: setUp
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def setUp(self):
super(MakeMigrationsTests, self).setUp()
self._old_models = apps.app_configs['migrations'].models.copy()
示例10: tearDown
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def tearDown(self):
apps.app_configs['migrations'].models = self._old_models
apps.all_models['migrations'] = self._old_models
apps.clear_cache()
super(MakeMigrationsTests, self).tearDown()
示例11: setUp
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def setUp(self):
super().setUp()
self._old_models = apps.app_configs['migrations'].models.copy()
示例12: tearDown
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def tearDown(self):
apps.app_configs['migrations'].models = self._old_models
apps.all_models['migrations'] = self._old_models
apps.clear_cache()
super().tearDown()
示例13: setUp
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def setUp(self):
# The unmanaged models need to be removed after the test in order to
# prevent bad interactions with the flush operation in other tests.
self._old_models = apps.app_configs['model_options'].models.copy()
for model in Article, Authors, Reviewers, Scientist:
model._meta.managed = True
示例14: tearDown
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import app_configs [as 别名]
def tearDown(self):
for model in Article, Authors, Reviewers, Scientist:
model._meta.managed = False
apps.app_configs['model_options'].models = self._old_models
apps.all_models['model_options'] = self._old_models
apps.clear_cache()