MCPcopy
hub / github.com/django/django / Apps

Class Apps

django/apps/registry.py:13–435  ·  view source on GitHub ↗

A registry that stores the configuration of installed applications. It also keeps track of models, e.g. to provide reverse relations.

Source from the content-addressed store, hash-verified

11
12
13class Apps:
14 """
15 A registry that stores the configuration of installed applications.
16
17 It also keeps track of models, e.g. to provide reverse relations.
18 """
19
20 def __init__(self, installed_apps=()):
21 # installed_apps is set to None when creating the main registry
22 # because it cannot be populated at that point. Other registries must
23 # provide a list of installed apps and are populated immediately.
24 if installed_apps is None and hasattr(sys.modules[__name__], "apps"):
25 raise RuntimeError("You must supply an installed_apps argument.")
26
27 # Mapping of app labels => model names => model classes. Every time a
28 # model is imported, ModelBase.__new__ calls apps.register_model which
29 # creates an entry in all_models. All imported models are registered,
30 # regardless of whether they're defined in an installed application
31 # and whether the registry has been populated. Since it isn't possible
32 # to reimport a module safely (it could reexecute initialization code)
33 # all_models is never overridden or reset.
34 self.all_models = defaultdict(dict)
35
36 # Mapping of labels to AppConfig instances for installed apps.
37 self.app_configs = {}
38
39 # Stack of app_configs. Used to store the current state in
40 # set_available_apps and set_installed_apps.
41 self.stored_app_configs = []
42
43 # Whether the registry is populated.
44 self.apps_ready = self.models_ready = self.ready = False
45 # For the autoreloader.
46 self.ready_event = threading.Event()
47
48 # Lock for thread-safe population.
49 self._lock = threading.RLock()
50 self.loading = False
51
52 # Maps ("app_label", "modelname") tuples to lists of functions to be
53 # called when the corresponding model is ready. Used by this class's
54 # `lazy_model_operation()` and `do_pending_operations()` methods.
55 self._pending_operations = defaultdict(list)
56
57 # Populate apps and models, unless it's the main registry.
58 if installed_apps is not None:
59 self.populate(installed_apps)
60
61 def populate(self, installed_apps=None):
62 """
63 Load application configurations and models.
64
65 Import each application module and then each model module.
66
67 It is thread-safe and idempotent, but not reentrant.
68 """
69 if self.ready:
70 return

Callers 15

enableMethod · 0.90
_remake_tableMethod · 0.90
MetaClass · 0.90
test_singleton_mainMethod · 0.90
test_readyMethod · 0.90
test_dynamic_loadMethod · 0.90
test_model_clashMethod · 0.90
models.pyFile · 0.90
MClass · 0.90

Calls

no outgoing calls