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

IA Refresh: Scripts to add redirects and move Wagtail pages #6026

Merged
merged 9 commits into from
Sep 25, 2020

Conversation

schbetsy
Copy link
Contributor

Add three scripts that we will use to update consumerfinance.gov to its new IA next week.

  1. pages_to_redirect, which takes a CSV of top-level pages that will move along with their children. Generates a full list of all URLs that will require Wagtail redirects.
  2. add_wagtail_redirects, which takes the output of pages_to_redirect and uses it to add all necessary Wagtail redirects
  3. move_wagtail_pages, which takes the same CSV as pages_to_redirect and moves all Wagtail pages to their new URLs.

How to test this PR

  1. Get a copy of our latest "Current redirects" spreadsheet and convert the first tab to CSV. There's a link to it in GHE/CFPB/super-regular/issues/148.
  2. Get a recent Production database dump.
  3. On this branch, from the project root, run the following: cfgov/manage.py runscript pages_to_redirect --script-args [redirects_spreadsheet.csv]
    • This will generate a file called redirects_list.csv with ~38 rows.
  4. cfgov/manage.py runscript add_wagtail_redirects --script-args redirects_list.csv
    • This will create a Wagtail redirect for each row in the redirects_list.csv file. If you run it again, it will delete the redirects and create new ones. It won't cause duplication.
  5. cfgov/manage.py runscript move_wagtail_pages --script-args [redirects_spreadsheet.csv]
    • This will move each of the page trees listed in the redirects spreadsheet. When a page moves, it brings all of its child pages with it, so there will be a total of >1300 pages moved.
  6. Run the server, log into the Wagtail admin, and see that the pages have moved and redirects have been added.

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code follows the standards laid out in the CFPB development guidelines
  • Future todos are captured in comments and/or tickets

@schbetsy schbetsy changed the title IA Refresh: Scripts for adding redirects and moving Wagtail pages IA Refresh: Scripts to add redirects and move Wagtail pages Sep 24, 2020
Copy link
Member

@chosak chosak left a comment

Choose a reason for hiding this comment

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

These scripts run properly for me.

If I run the validate_redirects script introduced in #6023, I expect to see half of the tests pass (the ones covered by this PR) and half fail (the ones to be covered by #6024). There are some unexpected failures, though, which I think are due to a missing content step. Will follow up about that offline.

cfgov/scripts/pages_to_redirect.py Outdated Show resolved Hide resolved
cfgov/scripts/pages_to_redirect.py Show resolved Hide resolved
cfgov/scripts/add_wagtail_redirects.py Outdated Show resolved Hide resolved
cfgov/scripts/add_wagtail_redirects.py Outdated Show resolved Hide resolved
@chosak
Copy link
Member

chosak commented Sep 24, 2020

a missing content step

Thanks to your suggested fix in the source spreadsheet, this is no longer an issue. validate_redirects now properly passes all of the "Wagtail redirect? TRUE" rows as expected. 👍

Also, if the page should be moved to a new slug, make that change too.
- improve logging messages
- order list of redirects by page ID
- use atomic transactions when adding and deleting redirects
- use atomic transactions when moving pages to new slugs and locations
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.

3 participants