8000 Integrate wizards with app registration by monikasulik · Pull Request #6436 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

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

Merged

Conversation

monikasulik
Copy link
Contributor

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:

  1. Create a cms_config.py file in the app (if one doesn't exist already)
  2. Implement a class that inherits from app_base.CMSAppConfig (if it doesn't exist already) and make sure it has the following attributes:
class Config(CMSAppConfig):
    cms_enabled = True
    cms_wizards = [wizard1, wizard2]

where wizard1 and wizard2 are wizards as they are currently defined in cms_wizards.py

Documentation checklist

  • I have updated CHANGELOG.txt if appropriate
  • I have updated the release notes document if appropriate, with:
    • general notes
    • bug-fixes
    • improvements/new features
    • backwards-incompatible changes
    • required upgrade steps
    • names of contributors
  • I have updated other documentation
  • I have added my name to the AUTHORS file
  • This PR's documentation has been approved by Daniele Procida


# PRIVATE METHODS -----------------

def _discover(self):
Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

@coveralls
Copy link
coveralls commented Jul 5, 2018

Coverage Status

Coverage remained the same at 78.189% when pulling 785153c on FidelityInternational:FIL-256-wizard-app-reg into 0394153 on divio:release/4.0.x.

Copy link
Contributor
@czpython czpython left a 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!

Adds all registered wizards from apps that define them to the
wizards dictionary on this class
"""
if not hasattr(cms_config, 'cms_wizards'):
Copy link
Contributor

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.

# The cms_wizards settings is optional. If it's not here
# just move on.
return
if type(cms_config.cms_wizards) != list:
Copy link
Contributor

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

if not isinstance(wizard, Wizard):
raise ImproperlyConfigured(
"all wizards defined in cms_wizards must inherit "
"from cms.wizards.wizard_base.Wizard")
Copy link
Contributor

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

raise ImproperlyConfigured(
"all wizards defined in cms_wizards must inherit "
"from cms.wizards.wizard_base.Wizard")
else:
Copy link
Contributor

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?

Copy link
Contributor Author

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:

  1. The test setup is loading cms and sampleapp as expected and their wizards are getting registered
  2. 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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -0,0 +1,97 @@
from mock import Mock
Copy link
Contributor

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.

Test for backwards compatibility of the unregister method.
Removes a wizard from the wizards dict.
"""
was_unregistered = wizard_pool.unregister(cms_page_wizard)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove newline

"""
user = self.get_superuser()
page = create_page('home', 'nav_playground.html', 'en', published=True)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove newline

page = create_page('home', 'nav_playground.html', 'en', published=True)

wizard_choices = [option for option in entry_choices(user, page)]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove newline

page = create_page('home', 'nav_playground.html', 'en', published=True)

wizard_choices = [option for option in entry_choices(user, page)]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove newline

"""
user = self.get_superuser()
page = create_page('home', 'nav_playground.html', 'en', published=True)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove newline

@czpython czpython changed the title WIP: Register wizards with the new app registration Integrate wizards with app registration Jul 5, 2018
@czpython czpython self-assigned this Jul 5, 2018
@czpython czpython added this to the 4.0.0 milestone Jul 5, 2018
@czpython czpython merged commit c8f56a9 into django-cms:release/4.0.x Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0