本文整理汇总了Python中django.apps.apps.get_app_configs方法的典型用法代码示例。如果您正苦于以下问题:Python apps.get_app_configs方法的具体用法?Python apps.get_app_configs怎么用?Python apps.get_app_configs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.apps.apps
的用法示例。
在下文中一共展示了apps.get_app_configs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: discover_extensions
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def discover_extensions(self):
"""Discover available extensions."""
if self._discovery_done:
return
try:
previous_state = self._extensions.copy()
for app_config in apps.get_app_configs():
indexes_path = "{}.extensions".format(app_config.name)
try:
import_module(indexes_path)
except ImportError:
pass
self._discovery_done = True
except Exception:
# Rollback state to prevent corrupted state on exceptions during import.
self._extensions = previous_state
raise
示例2: get_apps_tools
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def get_apps_tools():
"""Get applications' tools and their paths.
Return a dict with application names as keys and paths to tools'
directories as values. Applications without tools are omitted.
"""
tools_paths = {}
for app_config in apps.get_app_configs():
proc_path = os.path.join(app_config.path, "tools")
if os.path.isdir(proc_path):
tools_paths[app_config.name] = proc_path
custom_tools_paths = getattr(settings, "RESOLWE_CUSTOM_TOOLS_PATHS", [])
if not isinstance(custom_tools_paths, list):
raise KeyError("`RESOLWE_CUSTOM_TOOLS_PATHS` setting must be a list.")
for seq, custom_path in enumerate(custom_tools_paths):
custom_key = "_custom_{}".format(seq)
tools_paths[custom_key] = custom_path
return tools_paths
示例3: sequence_list
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def sequence_list(self):
"Returns a list of information about all DB sequences for all models in all apps."
from django.apps import apps
from django.db import models, router
sequence_list = []
for app_config in apps.get_app_configs():
for model in router.get_migratable_models(app_config, self.connection.alias):
if not model._meta.managed:
continue
if model._meta.swapped:
continue
for f in model._meta.local_fields:
if isinstance(f, models.AutoField):
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
break # Only one AutoField is allowed per model, so don't bother continuing.
for f in model._meta.local_many_to_many:
# If this is an m2m using an intermediate table,
# we don't need to reset the sequence.
if f.rel.through is None:
sequence_list.append({'table': f.m2m_db_table(), 'column': None})
return sequence_list
示例4: get_app_template_dirs
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def get_app_template_dirs(dirname):
"""
Return an iterable of paths of directories to load app templates from.
dirname is the name of the subdirectory containing templates inside
installed applications.
"""
template_dirs = []
for app_config in apps.get_app_configs():
if not app_config.path:
continue
template_dir = os.path.join(app_config.path, dirname)
if os.path.isdir(template_dir):
template_dirs.append(upath(template_dir))
# Immutable return value because it will be cached and shared by callers.
return tuple(template_dirs)
示例5: get_templatetags_modules
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def get_templatetags_modules():
"""
Return the list of all available template tag modules.
Caches the result for faster access.
"""
templatetags_modules_candidates = ['django.templatetags']
templatetags_modules_candidates.extend(
'%s.templatetags' % app_config.name
for app_config in apps.get_app_configs())
templatetags_modules = []
for templatetag_module in templatetags_modules_candidates:
try:
import_module(templatetag_module)
except ImportError:
continue
else:
templatetags_modules.append(templatetag_module)
return templatetags_modules
示例6: load_template_source
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def load_template_source(self, template_name, template_dirs=None):
"""
Loads templates from Python eggs via pkg_resource.resource_string.
For every installed app, it tries to get the resource (app, template_name).
"""
if resource_string is not None:
pkg_name = 'templates/' + template_name
for app_config in apps.get_app_configs():
try:
resource = resource_string(app_config.name, pkg_name)
except Exception:
continue
if six.PY2:
resource = resource.decode(self.engine.file_charset)
return (resource, 'egg:%s:%s' % (app_config.name, pkg_name))
raise TemplateDoesNotExist(template_name)
示例7: __init__
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def __init__(self, app_names=None, *args, **kwargs):
# The list of apps that are handled
self.apps = []
# Mapping of app names to storage instances
self.storages = OrderedDict()
app_configs = apps.get_app_configs()
if app_names:
app_names = set(app_names)
app_configs = [ac for ac in app_configs if ac.name in app_names]
for app_config in app_configs:
app_storage = self.storage_class(
os.path.join(app_config.path, self.source_dir))
if os.path.isdir(app_storage.location):
self.storages[app_config.name] = app_storage
if app_config.name not in self.apps:
self.apps.append(app_config.name)
super(AppDirectoriesFinder, self).__init__(*args, **kwargs)
示例8: emit_pre_migrate_signal
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
# Emit the pre_migrate signal for every application.
for app_config in apps.get_app_configs():
if app_config.models_module is None:
continue
if verbosity >= 2:
print("Running pre-migrate handlers for application %s" % app_config.label)
models.signals.pre_migrate.send(
sender=app_config,
app_config=app_config,
verbosity=verbosity,
interactive=interactive,
using=db)
# For backwards-compatibility -- remove in Django 1.9.
models.signals.pre_syncdb.send(
sender=app_config.models_module,
app=app_config.models_module,
create_models=create_models,
verbosity=verbosity,
interactive=interactive,
db=db)
示例9: emit_post_migrate_signal
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def emit_post_migrate_signal(created_models, verbosity, interactive, db):
# Emit the post_migrate signal for every application.
for app_config in apps.get_app_configs():
if app_config.models_module is None:
continue
if verbosity >= 2:
print("Running post-migrate handlers for application %s" % app_config.label)
models.signals.post_migrate.send(
sender=app_config,
app_config=app_config,
verbosity=verbosity,
interactive=interactive,
using=db)
# For backwards-compatibility -- remove in Django 1.9.
models.signals.post_syncdb.send(
sender=app_config.models_module,
app=app_config.models_module,
created_models=created_models,
verbosity=verbosity,
interactive=interactive,
db=db)
示例10: sequence_list
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def sequence_list(self):
"""
Return a list of information about all DB sequences for all models in
all apps.
"""
from django.apps import apps
from django.db import router
sequence_list = []
cursor = self.connection.cursor()
for app_config in apps.get_app_configs():
for model in router.get_migratable_models(app_config, self.connection.alias):
if not model._meta.managed:
continue
if model._meta.swapped:
continue
sequence_list.extend(self.get_sequences(cursor, model._meta.db_table, model._meta.local_fields))
for f in model._meta.local_many_to_many:
# If this is an m2m using an intermediate table,
# we don't need to reset the sequence.
if f.remote_field.through is None:
sequence = self.get_sequences(cursor, f.m2m_db_table())
sequence_list.extend(sequence if sequence else [{'table': f.m2m_db_table(), 'column': None}])
return sequence_list
示例11: get_app_template_dirs
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def get_app_template_dirs(dirname):
"""
Return an iterable of paths of directories to load app templates from.
dirname is the name of the subdirectory containing templates inside
installed applications.
"""
template_dirs = []
for app_config in apps.get_app_configs():
if not app_config.path:
continue
template_dir = os.path.join(app_config.path, dirname)
if os.path.isdir(template_dir):
template_dirs.append(template_dir)
# Immutable return value because it will be cached and shared by callers.
return tuple(template_dirs)
示例12: get_installed_libraries
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def get_installed_libraries():
"""
Return the built-in template tag libraries and those from installed
applications. Libraries are stored in a dictionary where keys are the
individual module names, not the full module paths. Example:
django.templatetags.i18n is stored as i18n.
"""
libraries = {}
candidates = ['django.templatetags']
candidates.extend(
'%s.templatetags' % app_config.name
for app_config in apps.get_app_configs())
for candidate in candidates:
try:
pkg = import_module(candidate)
except ImportError:
# No templatetags package defined. This is safe to ignore.
continue
if hasattr(pkg, '__path__'):
for name in get_package_libraries(pkg):
libraries[name[len(candidate) + 1:]] = name
return libraries
示例13: __init__
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def __init__(self, app_names=None, *args, **kwargs):
# The list of apps that are handled
self.apps = []
# Mapping of app names to storage instances
self.storages = OrderedDict()
app_configs = apps.get_app_configs()
if app_names:
app_names = set(app_names)
app_configs = [ac for ac in app_configs if ac.name in app_names]
for app_config in app_configs:
app_storage = self.storage_class(
os.path.join(app_config.path, self.source_dir))
if os.path.isdir(app_storage.location):
self.storages[app_config.name] = app_storage
if app_config.name not in self.apps:
self.apps.append(app_config.name)
super().__init__(*args, **kwargs)
示例14: get_config_context
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [as 别名]
def get_config_context():
from django.apps import apps
import importlib
from app.db_manager.config_manager import get_config_by_name
result = {}
for app in apps.get_app_configs():
deeru_config = getattr(app, 'deeru_config_context', None)
if deeru_config:
deeru_config = deeru_config.split('.')
module_name = '.'.join(deeru_config[:-1])
consts = importlib.import_module(module_name)
app_config = getattr(consts, deeru_config[-1], {})
for k, v in app_config.items():
config = get_config_by_name(v)
if config:
result[k] = config.v2_real_config
return result
示例15: get_installed_apps
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_app_configs [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()