-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Allow lazy wizard initialization #8266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -49,8 +49,10 @@ def test_raises_exception_if_doesnt_inherit_from_wizard_class(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||
wizard = Mock(id=3, spec=object) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
cms_config = Mock( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
cms_enabled=True, cms_wizards=[wizard]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensions.configure_wizards(cms_config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
with self.assertRaises(ImproperlyConfigured): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensions.configure_wizards(cms_config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensions.wizards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
49
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Test for exception when non-Wizard instance is present now triggers on property access. Consider adding a comment or separate test to document that the exception is now raised on 'wizards' property access, not during configuration, to clarify intent and timing.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_raises_exception_if_not_iterable(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -63,22 +65,6 @@ def test_raises_exception_if_not_iterable(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||
with self.assertRaises(ImproperlyConfigured): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensions.configure_wizards(cms_config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@patch('cms.cms_config.logger.warning') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_warning_if_registering_the_same_wizard_twice(self, mocked_logger): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
If a wizard is already added to the dict log a warning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensions = CMSCoreExtensions() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
wizard = Mock(id=81, spec=Wizard) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
cms_config = Mock( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
cms_enabled=True, cms_wizards=[wizard, wizard]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensions.configure_wizards(cms_config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
warning_msg = f"Wizard for model {wizard.get_model()} has already been registered" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Warning message displayed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocked_logger.assert_called_once_with(warning_msg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
# wizards dict is still what we expect it to be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.assertDictEqual(extensions.wizards, {81: wizard}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
class ConfigureWizardsIntegrationTestCase(CMSTestCase): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
from django.apps import apps | ||
import warnings | ||
|
||
from cms.utils.compat.warnings import RemovedInDjangoCMS60Warning | ||
|
||
def get_entries(): | ||
""" | ||
Returns a list of (wizard.id, wizard) tuples (for all registered | ||
wizards) ordered by weight | ||
from .wizard_base import get_entries, get_entry # noqa: F401 | ||
|
||
``get_entries()`` is useful if it is required to have a list of all registered | ||
wizards. Typically, this is used to iterate over them all. Note that they will | ||
be returned in the order of their ``weight``: smallest numbers for weight are | ||
returned first.:: | ||
|
||
for wizard_id, wizard in get_entries(): | ||
# do something with a wizard... | ||
""" | ||
wizards = apps.get_app_config('cms').cms_extension.wizards | ||
return [value for (key, value) in sorted( | ||
wizards.items(), key=lambda e: e[1].weight)] | ||
|
||
|
||
def get_entry(entry_key): | ||
""" | ||
Returns a wizard object based on its :attr:`~.cms.wizards.wizard_base.Wizard.id`. | ||
""" | ||
return apps.get_app_config('cms').cms_extension.wizards[entry_key] | ||
warnings.warn( | ||
"The cms.wizards.helpers module is deprecated and will be removed in django CMS 5.1. " | ||
"Use cms.wizards.wizard_base.get_entries and cms.wizards.wizard_pool.get_entry instead.", | ||
RemovedInDjangoCMS60Warning, | ||
stacklevel=2, | ||
) |
Uh oh!
There was an error while loading. Please reload this page.