Skip to content
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

Merged
merged 2 commits into from
Sep 16, 2020

Conversation

chosak
Copy link
Member

@chosak chosak commented Sep 15, 2020

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'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/9003c98fd5df83a77bd4291b7a8d09eb509d7642/new.json | cfgov/manage.py import_mega_menu en

Checklist

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
Copy link
Contributor

@schbetsy schbetsy left a 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'
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me 👍

@chosak chosak merged commit ef48c89 into main Sep 16, 2020
@chosak chosak deleted the feature/menu-export-import branch September 16, 2020 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants