-
Notifications
You must be signed in to change notification settings - Fork 108
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
Add management commands to export/import mega menu #6011
Conversation
This commit adds two new management commands for exporting and importing mega menu content to and from JSON. These commands will enable easier and more repeatable updating of menu content. To export: cfgov/manage.py export_mega_menu language output.json OR cfgov/manage.py export_mega_menu language (writes to stdout) For example: cfgov/manage.py export_mega_menu en current.json To import: cfgov/manage.py import_mega_menu language input.json OR cfgov/manage.py import_mega_menu language (reads from stdin) For example: cat new.json | cfgov/manage.py import_mega_menu en The JSON format used is the content of the existing Menu object's submenus StreamField. For testing purposes, I've created two JSON files that can be used to switch back and forth between the current site mega menu and an alternate one. Assuming that you have github.local aliased to our internal GHE server, you can run these commands to toggle back and forth. Current menu: curl -k https://github.local/raw/gist/chosak/4600af0d52fbe588a634ea6fee54f942/raw/5af1c1428f63ddfd7f6fc8ba9fa115b0ac17235a/current.json | cfgov/manage.py import_mega_menu en New menu: curl -k https://github.local/raw/gist/chosak/fdeab64f382ca0d17568cdbd717862d8/raw/9b2e8fb73062ec631c609d69c1e9ee49261b6459/new.json | cfgov/manage.py import_mega_menu en
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.
This works great for me. One minor comment below.
|
||
|
||
class Command(BaseCommand): | ||
help = 'Import mega menu content as JSON' |
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.
Maybe add that it will overwrite any existing mega menu for the given language?
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.
Nice suggestion, @schbetsy. Unfortunately it's tricky to add multiple lines in command help, so we're limited to one line here. I went with "Import (and overwrite) language-specific mega menu content as JSON." -- does that capture this well?
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.
Works for me 👍
This commit adds two new management commands for exporting and importing mega menu content to and from JSON. These commands will enable easier and more repeatable updating of menu content.
How to test this PR
To export:
cfgov/manage.py export_mega_menu language output.json
OR
cfgov/manage.py export_mega_menu language
(writes to stdout)For example:
cfgov/manage.py export_mega_menu en current.json
To import:
cfgov/manage.py import_mega_menu language input.json
OR
cfgov/manage.py import_mega_menu language
(reads from stdin)For example:
cat new.json | cfgov/manage.py import_mega_menu en
The JSON format used is the content of the existing
Menu
object'ssubmenus
StreamField. For testing purposes, I've created two JSON files that can be used to switch back and forth between the current site mega menu and an alternate one. Assuming that you havegithub.local
aliased to our internal GHE server, you can run these commands to toggle back and forth.Current menu:
curl -k https://github.local/raw/gist/chosak/4600af0d52fbe588a634ea6fee54f942/raw/5af1c1428f63ddfd7f6fc8ba9fa115b0ac17235a/current.json | cfgov/manage.py import_mega_menu en
New menu:
curl -k https://github.local/raw/gist/chosak/fdeab64f382ca0d17568cdbd717862d8/raw/9003c98fd5df83a77bd4291b7a8d09eb509d7642/new.json | cfgov/manage.py import_mega_menu en
Checklist