-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Integrate wizards with app registration #6436
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
Integrate wizards with app registration #6436
Conversation
|
||
# PRIVATE METHODS ----------------- | ||
|
||
def _discover(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about this later, I'm getting the impression I may have messed up backwards compatibility with this. Because although the method wizard_pool.register
still works, there is now no code that actually looks for cms_wizards.py
@czpython Where would you like the code that searches for cms_wizards.py files to live now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the __init__
in CMSCoreExtensions
might be a good place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is bizarre. Just wrote a test with an app that doesn't have cms_config.py but only cms_wizards.py and it seems to have registered the wizard from cms_wizards.py without me adding this into the init! Will check what's up there Monday morning, but possibly all that is needed is that test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely there is an import somewhere of cms_wizards.py which should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I can't use the __init__
in CMSCoreExtensions due to the order in which things happen (it means attempting to add wizards to a CMSCoreExtensions instance that doesn't exist yet). However, I have added this elsewhere. Hope this will work for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looking good!
cms/cms_config.py
Outdated
Adds all registered wizards from apps that define them to the | ||
wizards dictionary on this class | ||
""" | ||
if not hasattr(cms_config, 'cms_wizards'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be better in the configure_app
method.
So this method only runs if wizards is configured.
cms/cms_config.py
Outdated
# The cms_wizards settings is optional. If it's not here | ||
# just move on. | ||
return | ||
if type(cms_config.cms_wizards) != list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think we need to do a type check here
maybe just check if cms_wizards
is iterable
cms/cms_config.py
Outdated
if not isinstance(wizard, Wizard): | ||
raise ImproperlyConfigured( | ||
"all wizards defined in cms_wizards must inherit " | ||
"from cms.wizards.wizard_base.Wizard") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match closing bracket with raise
cms/cms_config.py
Outdated
raise ImproperlyConfigured( | ||
"all wizards defined in cms_wizards must inherit " | ||
"from cms.wizards.wizard_base.Wizard") | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we do an elif checking that the wizard has not been registered already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I did this locally and am now struggling with random tests failing. What seems to be happening is:
- The test setup is loading cms and sampleapp as expected and their wizards are getting registered
- The individual tests use the
override_settings
decorator with INSTALLED_APPS and include the cms app on the revised list, which in turn triggers another autodiscover thing because the cms's ready method is getting called twice. And therefore raises an error.
I can think of some ways of fixing this, but all these ways seem really hacky and will be really annoying and unobvious for future test writers. Do you have an idea for a nice way of doing this?
Alternatively, because we're using a dict, nothing bad is actually going to happen if a wizard is added to the dict twice (it'll just override the previous wizard), so we could just change this to a logger.warning
? Really our code can cope with double registration of wizards, it's just that the developer has done something fishy if that's what's happening, so we should warn them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the app config instance setup on the first load, persisting through to the second load on the tests that use override_settings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@czpython I believe so, yes. I seem to be struggling on a similar issue with the integration test on backwards compatibility (needed for th 8000 e work on retaining the autodiscover of cms_wizards) as well. I've just pushed that.
cms/tests/test_cms_config.py
Outdated
@@ -0,0 +1,97 @@ | |||
from mock import Mock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to make this test_cms_config_wizards
Basically each feature in the config should have its own file.
cms/tests/test_wizards.py
Outdated
Test for backwards compatibility of the unregister method. | ||
Removes a wizard from the wizards dict. | ||
""" | ||
was_unregistered = wizard_pool.unregister(cms_page_wizard) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
cms/tests/test_wizards.py
Outdated
""" | ||
user = self.get_superuser() | ||
page = create_page('home', 'nav_playground.html', 'en', published=True) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
cms/tests/test_wizards.py
Outdated
page = create_page('home', 'nav_playground.html', 'en', published=True) | ||
|
||
wizard_choices = [option for option in entry_choices(user, page)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
cms/tests/test_wizards.py
Outdated
page = create_page('home', 'nav_playground.html', 'en', published=True) | ||
|
||
wizard_choices = [option for option in entry_choices(user, page)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
cms/tests/test_wizards.py
Outdated
""" | ||
user = self.get_superuser() | ||
page = create_page('home', 'nav_playground.html', 'en', published=True) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
Summary
Implement wizards via the new app registration system. Ensure backwards compatibility
Proposed changes in this pull request
This changes (although ensures backwards compatibility with) how wizards will be registered with the cms going forwards. From now on to register wizards one needs to do the following:
app_base.CMSAppConfig
(if it doesn't exist already) and make sure it has the following attributes:where wizard1 and wizard2 are wizards as they are currently defined in cms_wizards.py
Documentation checklist