plain 0.23.1__tar.gz → 0.24.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {plain-0.23.1 → plain-0.24.0}/PKG-INFO +1 -1
- {plain-0.23.1 → plain-0.24.0}/plain/assets/finders.py +2 -2
- {plain-0.23.1 → plain-0.24.0}/plain/cli/cli.py +2 -2
- {plain-0.23.1 → plain-0.24.0}/plain/cli/packages.py +2 -2
- plain-0.24.0/plain/packages/__init__.py +4 -0
- {plain-0.23.1 → plain-0.24.0}/plain/packages/config.py +1 -58
- {plain-0.23.1 → plain-0.24.0}/plain/packages/registry.py +40 -22
- {plain-0.23.1 → plain-0.24.0}/plain/runtime/__init__.py +2 -2
- {plain-0.23.1 → plain-0.24.0}/plain/templates/jinja/__init__.py +2 -2
- {plain-0.23.1 → plain-0.24.0}/plain/templates/jinja/environments.py +2 -2
- {plain-0.23.1 → plain-0.24.0}/plain/urls/resolvers.py +1 -1
- {plain-0.23.1 → plain-0.24.0}/plain/urls/routers.py +1 -1
- {plain-0.23.1 → plain-0.24.0}/pyproject.toml +1 -1
- plain-0.23.1/plain/packages/__init__.py +0 -4
- {plain-0.23.1 → plain-0.24.0}/.gitignore +0 -0
- {plain-0.23.1 → plain-0.24.0}/LICENSE +0 -0
- {plain-0.23.1 → plain-0.24.0}/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/__main__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/assets/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/assets/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/assets/compile.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/assets/fingerprints.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/assets/urls.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/assets/views.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/cli/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/cli/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/cli/formatting.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/cli/print.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/cli/startup.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/csrf/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/csrf/middleware.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/csrf/views.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/debug.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/exceptions.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/forms/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/forms/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/forms/boundfield.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/forms/exceptions.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/forms/fields.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/forms/forms.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/http/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/http/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/http/cookie.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/http/multipartparser.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/http/request.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/http/response.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/base.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/locks.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/move.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/temp.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/uploadedfile.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/uploadhandler.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/files/utils.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/handlers/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/handlers/base.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/handlers/exception.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/handlers/wsgi.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/middleware/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/middleware/headers.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/middleware/https.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/internal/middleware/slash.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/json.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/logs/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/logs/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/logs/configure.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/logs/loggers.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/logs/utils.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/packages/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/paginator.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/preflight/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/preflight/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/preflight/files.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/preflight/messages.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/preflight/registry.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/preflight/security.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/preflight/urls.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/runtime/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/runtime/global_settings.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/runtime/user_settings.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/signals/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/signals/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/signals/dispatch/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/signals/dispatch/dispatcher.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/signals/dispatch/license.txt +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/signing.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/templates/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/templates/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/templates/core.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/templates/jinja/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/templates/jinja/extensions.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/templates/jinja/filters.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/templates/jinja/globals.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/test/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/test/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/test/client.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/urls/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/urls/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/urls/converters.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/urls/exceptions.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/urls/patterns.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/urls/utils.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/_os.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/cache.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/connection.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/crypto.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/datastructures.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/dateformat.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/dateparse.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/dates.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/deconstruct.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/decorators.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/duration.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/email.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/encoding.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/functional.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/hashable.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/html.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/http.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/inspect.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/ipv6.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/itercompat.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/module_loading.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/regex_helper.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/safestring.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/text.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/timesince.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/timezone.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/utils/tree.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/validators.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/README.md +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/base.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/csrf.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/errors.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/exceptions.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/forms.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/objects.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/redirect.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/views/templates.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/plain/wsgi.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/.bolt/assets_collected/assets.json +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/.gitignore +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/app/.gitignore +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/app/settings.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/app/test/__init__.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/app/test/default_settings.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/app/urls.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/conftest.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/test_cli.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/test_runtime.py +0 -0
- {plain-0.23.1 → plain-0.24.0}/tests/test_wsgi.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
|
3
|
-
from plain.packages import
|
3
|
+
from plain.packages import packages_registry
|
4
4
|
from plain.runtime import APP_PATH
|
5
5
|
|
6
6
|
APP_ASSETS_DIR = APP_PATH / "assets"
|
@@ -33,7 +33,7 @@ def iter_assets():
|
|
33
33
|
|
34
34
|
def iter_asset_dirs():
|
35
35
|
# Iterate the installed package assets, in order
|
36
|
-
for pkg in
|
36
|
+
for pkg in packages_registry.get_package_configs():
|
37
37
|
asset_dir = os.path.join(pkg.path, "assets")
|
38
38
|
if os.path.exists(asset_dir):
|
39
39
|
yield asset_dir
|
@@ -16,7 +16,7 @@ import plain.runtime
|
|
16
16
|
from plain import preflight
|
17
17
|
from plain.assets.compile import compile_assets, get_compiled_path
|
18
18
|
from plain.exceptions import ImproperlyConfigured
|
19
|
-
from plain.packages import
|
19
|
+
from plain.packages import packages_registry
|
20
20
|
from plain.utils.crypto import get_random_string
|
21
21
|
|
22
22
|
from .formatting import PlainContext
|
@@ -161,7 +161,7 @@ def preflight_checks(package_label, deploy, fail_level, databases):
|
|
161
161
|
|
162
162
|
if package_label:
|
163
163
|
package_configs = [
|
164
|
-
|
164
|
+
packages_registry.get_package_config(label) for label in package_label
|
165
165
|
]
|
166
166
|
else:
|
167
167
|
package_configs = None
|
@@ -4,7 +4,7 @@ from importlib.util import find_spec
|
|
4
4
|
|
5
5
|
import click
|
6
6
|
|
7
|
-
from plain.packages import
|
7
|
+
from plain.packages import packages_registry
|
8
8
|
|
9
9
|
|
10
10
|
class InstalledPackagesGroup(click.Group):
|
@@ -21,7 +21,7 @@ class InstalledPackagesGroup(click.Group):
|
|
21
21
|
command_names = []
|
22
22
|
|
23
23
|
# Get installed packages with a cli.py module
|
24
|
-
for app in
|
24
|
+
for app in packages_registry.get_package_configs():
|
25
25
|
if not find_spec(f"{app.name}.{self.MODULE_NAME}"):
|
26
26
|
continue
|
27
27
|
|
@@ -6,7 +6,6 @@ from plain.exceptions import ImproperlyConfigured
|
|
6
6
|
from plain.utils.module_loading import import_string, module_has_submodule
|
7
7
|
|
8
8
|
CONFIG_MODULE_NAME = "config"
|
9
|
-
MODELS_MODULE_NAME = "models"
|
10
9
|
|
11
10
|
|
12
11
|
class PackageConfig:
|
@@ -24,7 +23,7 @@ class PackageConfig:
|
|
24
23
|
|
25
24
|
# Reference to the Packages registry that holds this PackageConfig. Set by the
|
26
25
|
# registry when it registers the PackageConfig instance.
|
27
|
-
self.
|
26
|
+
self.packages_registry = None
|
28
27
|
|
29
28
|
# The following attributes could be defined at the class level in a
|
30
29
|
# subclass, hence the test-and-set pattern.
|
@@ -43,15 +42,6 @@ class PackageConfig:
|
|
43
42
|
if not hasattr(self, "path"):
|
44
43
|
self.path = self._path_from_module(package_module)
|
45
44
|
|
46
|
-
# Module containing models e.g. <module 'plain.admin.models'
|
47
|
-
# from 'admin/models.py'>. Set by import_models().
|
48
|
-
# None if the application doesn't have a models module.
|
49
|
-
self.models_module = None
|
50
|
-
|
51
|
-
# Mapping of lowercase model names to model classes. Initially set to
|
52
|
-
# None to prevent accidental access before import_models() runs.
|
53
|
-
self.models = None
|
54
|
-
|
55
45
|
def __repr__(self):
|
56
46
|
return f"<{self.__class__.__name__}: {self.label}>"
|
57
47
|
|
@@ -200,53 +190,6 @@ class PackageConfig:
|
|
200
190
|
# Entry is a path to an app config class.
|
201
191
|
return package_config_class(package_name, package_module)
|
202
192
|
|
203
|
-
def get_model(self, model_name, require_ready=True):
|
204
|
-
"""
|
205
|
-
Return the model with the given case-insensitive model_name.
|
206
|
-
|
207
|
-
Raise LookupError if no model exists with this name.
|
208
|
-
"""
|
209
|
-
if require_ready:
|
210
|
-
self.packages.check_models_ready()
|
211
|
-
else:
|
212
|
-
self.packages.check_packages_ready()
|
213
|
-
try:
|
214
|
-
return self.models[model_name.lower()]
|
215
|
-
except KeyError:
|
216
|
-
raise LookupError(
|
217
|
-
f"Package '{self.label}' doesn't have a '{model_name}' model."
|
218
|
-
)
|
219
|
-
|
220
|
-
def get_models(self, include_auto_created=False, include_swapped=False):
|
221
|
-
"""
|
222
|
-
Return an iterable of models.
|
223
|
-
|
224
|
-
By default, the following models aren't included:
|
225
|
-
|
226
|
-
- auto-created models for many-to-many relations without
|
227
|
-
an explicit intermediate table,
|
228
|
-
- models that have been swapped out.
|
229
|
-
|
230
|
-
Set the corresponding keyword argument to True to include such models.
|
231
|
-
Keyword arguments aren't documented; they're a private API.
|
232
|
-
"""
|
233
|
-
self.packages.check_models_ready()
|
234
|
-
for model in self.models.values():
|
235
|
-
if model._meta.auto_created and not include_auto_created:
|
236
|
-
continue
|
237
|
-
if model._meta.swapped and not include_swapped:
|
238
|
-
continue
|
239
|
-
yield model
|
240
|
-
|
241
|
-
def import_models(self):
|
242
|
-
# Dictionary of models for this app, primarily maintained in the
|
243
|
-
# 'all_models' attribute of the Packages this PackageConfig is attached to.
|
244
|
-
self.models = self.packages.all_models[self.label]
|
245
|
-
|
246
|
-
if module_has_submodule(self.module, MODELS_MODULE_NAME):
|
247
|
-
models_module_name = f"{self.name}.{MODELS_MODULE_NAME}"
|
248
|
-
self.models_module = import_module(models_module_name)
|
249
|
-
|
250
193
|
def ready(self):
|
251
194
|
"""
|
252
195
|
Override this method in subclasses to run code when Plain starts.
|
@@ -10,7 +10,7 @@ from plain.exceptions import ImproperlyConfigured, PackageRegistryNotReady
|
|
10
10
|
from .config import PackageConfig
|
11
11
|
|
12
12
|
|
13
|
-
class
|
13
|
+
class PackagesRegistry:
|
14
14
|
"""
|
15
15
|
A registry that stores the configuration of installed applications.
|
16
16
|
|
@@ -21,7 +21,9 @@ class Packages:
|
|
21
21
|
# installed_packages is set to None when creating the main registry
|
22
22
|
# because it cannot be populated at that point. Other registries must
|
23
23
|
# provide a list of installed packages and are populated immediately.
|
24
|
-
if installed_packages is None and hasattr(
|
24
|
+
if installed_packages is None and hasattr(
|
25
|
+
sys.modules[__name__], "packages_registry"
|
26
|
+
):
|
25
27
|
raise RuntimeError("You must supply an installed_packages argument.")
|
26
28
|
|
27
29
|
# Mapping of app labels => model names => model classes.
|
@@ -90,7 +92,7 @@ class Packages:
|
|
90
92
|
)
|
91
93
|
|
92
94
|
self.package_configs[package_config.label] = package_config
|
93
|
-
package_config.
|
95
|
+
package_config.packages_registry = self
|
94
96
|
|
95
97
|
# Check for duplicate app names.
|
96
98
|
counts = Counter(
|
@@ -106,18 +108,14 @@ class Packages:
|
|
106
108
|
|
107
109
|
self.packages_ready = True
|
108
110
|
|
109
|
-
# Phase
|
110
|
-
for package_config in self.
|
111
|
-
package_config.
|
111
|
+
# Phase 3: run ready() methods of app configs.
|
112
|
+
for package_config in self.get_package_configs():
|
113
|
+
package_config.ready()
|
112
114
|
|
113
115
|
self.clear_cache()
|
114
116
|
|
115
117
|
self.models_ready = True
|
116
118
|
|
117
|
-
# Phase 3: run ready() methods of app configs.
|
118
|
-
for package_config in self.get_package_configs():
|
119
|
-
package_config.ready()
|
120
|
-
|
121
119
|
self.ready = True
|
122
120
|
|
123
121
|
def check_packages_ready(self):
|
@@ -160,7 +158,9 @@ class Packages:
|
|
160
158
|
|
161
159
|
# This method is performance-critical at least for Plain's test suite.
|
162
160
|
@functools.cache
|
163
|
-
def get_models(
|
161
|
+
def get_models(
|
162
|
+
self, *, package_label="", include_auto_created=False, include_swapped=False
|
163
|
+
):
|
164
164
|
"""
|
165
165
|
Return a list of all installed models.
|
166
166
|
|
@@ -175,10 +175,27 @@ class Packages:
|
|
175
175
|
self.check_models_ready()
|
176
176
|
|
177
177
|
result = []
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
178
|
+
|
179
|
+
# Get models for a single package
|
180
|
+
if package_label:
|
181
|
+
package_models = self.all_models[package_label]
|
182
|
+
for model in package_models.values():
|
183
|
+
if model._meta.auto_created and not include_auto_created:
|
184
|
+
continue
|
185
|
+
if model._meta.swapped and not include_swapped:
|
186
|
+
continue
|
187
|
+
result.append(model)
|
188
|
+
return result
|
189
|
+
|
190
|
+
# Get models for all packages
|
191
|
+
for package_models in self.all_models.values():
|
192
|
+
for model in package_models.values():
|
193
|
+
if model._meta.auto_created and not include_auto_created:
|
194
|
+
continue
|
195
|
+
if model._meta.swapped and not include_swapped:
|
196
|
+
continue
|
197
|
+
result.append(model)
|
198
|
+
|
182
199
|
return result
|
183
200
|
|
184
201
|
def get_model(self, package_label, model_name=None, require_ready=True):
|
@@ -201,12 +218,13 @@ class Packages:
|
|
201
218
|
if model_name is None:
|
202
219
|
package_label, model_name = package_label.split(".")
|
203
220
|
|
204
|
-
package_config = self.get_package_config(package_label)
|
221
|
+
# package_config = self.get_package_config(package_label)
|
205
222
|
|
206
|
-
if not require_ready and package_config.models is None:
|
207
|
-
|
223
|
+
# if not require_ready and package_config.models is None:
|
224
|
+
# package_config.import_models()
|
208
225
|
|
209
|
-
|
226
|
+
package_models = self.all_models[package_label]
|
227
|
+
return package_models[model_name.lower()]
|
210
228
|
|
211
229
|
def register_model(self, package_label, model):
|
212
230
|
# Since this method is called when models are imported, it cannot
|
@@ -301,8 +319,8 @@ class Packages:
|
|
301
319
|
if self.ready:
|
302
320
|
# Circumvent self.get_models() to prevent that the cache is refilled.
|
303
321
|
# This particularly prevents that an empty value is cached while cloning.
|
304
|
-
for
|
305
|
-
for model in
|
322
|
+
for package_models in self.all_models.values():
|
323
|
+
for model in package_models.values():
|
306
324
|
model._meta._expire_cache()
|
307
325
|
|
308
326
|
def lazy_model_operation(self, function, *model_keys):
|
@@ -355,4 +373,4 @@ class Packages:
|
|
355
373
|
function(model)
|
356
374
|
|
357
375
|
|
358
|
-
|
376
|
+
packages_registry = PackagesRegistry(installed_packages=None)
|
@@ -33,7 +33,7 @@ def setup():
|
|
33
33
|
entry_point.load()()
|
34
34
|
|
35
35
|
from plain.logs import configure_logging
|
36
|
-
from plain.packages import
|
36
|
+
from plain.packages import packages_registry
|
37
37
|
|
38
38
|
if not APP_PATH.exists():
|
39
39
|
raise AppPathNotFound(
|
@@ -48,7 +48,7 @@ def setup():
|
|
48
48
|
|
49
49
|
configure_logging(settings.LOGGING)
|
50
50
|
|
51
|
-
|
51
|
+
packages_registry.populate(settings.INSTALLED_PACKAGES)
|
52
52
|
|
53
53
|
|
54
54
|
__all__ = [
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from importlib import import_module
|
2
2
|
|
3
|
-
from plain.packages import
|
3
|
+
from plain.packages import packages_registry
|
4
4
|
from plain.runtime import settings
|
5
5
|
from plain.utils.functional import LazyObject
|
6
6
|
from plain.utils.module_loading import import_string, module_has_submodule
|
@@ -29,7 +29,7 @@ class JinjaEnvironment(LazyObject):
|
|
29
29
|
import_module(name)
|
30
30
|
self._imported_modules.add(name)
|
31
31
|
|
32
|
-
for package_config in
|
32
|
+
for package_config in packages_registry.get_package_configs():
|
33
33
|
if module_has_submodule(package_config.module, "templates"):
|
34
34
|
# Allow this to fail in case there are import errors inside of their file
|
35
35
|
_maybe_import_module(f"{package_config.name}.templates")
|
@@ -4,7 +4,7 @@ from pathlib import Path
|
|
4
4
|
from jinja2 import Environment, StrictUndefined
|
5
5
|
from jinja2.loaders import FileSystemLoader
|
6
6
|
|
7
|
-
from plain.packages import
|
7
|
+
from plain.packages import packages_registry
|
8
8
|
from plain.runtime import settings
|
9
9
|
|
10
10
|
from .filters import default_filters
|
@@ -40,7 +40,7 @@ def _get_app_template_dirs():
|
|
40
40
|
dirname = "templates"
|
41
41
|
template_dirs = [
|
42
42
|
Path(package_config.path) / dirname
|
43
|
-
for package_config in
|
43
|
+
for package_config in packages_registry.get_package_configs()
|
44
44
|
if package_config.path and (Path(package_config.path) / dirname).is_dir()
|
45
45
|
]
|
46
46
|
# Immutable return value because it will be cached and shared by callers.
|
@@ -108,7 +108,7 @@ def path(route: str | re.Pattern, view: "View", *, name: str = "") -> URLPattern
|
|
108
108
|
)
|
109
109
|
|
110
110
|
# You typically pass a View class and we call as_view() for you
|
111
|
-
if issubclass(view, View):
|
111
|
+
if isinstance(view, type) and issubclass(view, View):
|
112
112
|
return URLPattern(pattern=pattern, view=view.as_view(), name=name)
|
113
113
|
|
114
114
|
# If you called View.as_view() yourself (or technically any callable)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|