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

Support parent selection in breadcrumb navigation and new child creation #2

Merged
merged 6 commits into from
May 18, 2018

Conversation

willbarton
Copy link
Member

@willbarton willbarton commented May 17, 2018

This PR adds support for maintaining parent selection while navigating the tree in breadcrumbs and when creating a new child.

Additions

  • Clicking on a model name in the breadcrumbs while having a parent selected will maintain the parent selection throughout the tree.
  • Creating a new child from a page with a parent selection (either the + button on an empty parent or the "Add {Model Name}" button) will have that field in the creation form filled out with the selected parent.
  • Editing a child will redirect to the parent-filtered listing page.
  • Deleting a child will redirect to the parent-filtered listing page.

Changes

  • Fixed the "Edit" button under the parent name. Previously it was editing the child object with the parent's primary key.
  • Refactored some of the TreeIndexView parent logic into a mixin class.
  • Refactored the breadcrumb logic to make use of a URL helper subclass.
  • Changed treemodeladmin/index.html to extend modeladmin/index.html and removed all the blocks that aren't modified by TreeModelAdmin.

Testing

  1. Standlone (thanks, @higs4281!):

    export DJANGO_SETTINGS_MODULE=treemodeladmin.tests.settings
    export PYTHONPATH='[PATH TO PROJECT]'
    django-admin.py migrate
    django-admin.py loaddata treemodeladmin_test
    django-admin.py runserver

    Then visit http://localhost:8000/admin. Author will be available under the "TreeModelAdmin Test" menu item.

  2. With cfgov-refresh and docker:

    git checkout origin/treemodeladmin
    docker-compose build python
    docker-compose up

    Then visit http://localhost:8000/admin. The Regulations 3000 models will be navigable via TreeModelAdmin under the "Regulations" menu item.

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows the standards laid out in the development playbook
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Visually tested in supported browsers and devices (see checklist below 👇)
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Copy link
Member

@higs4281 higs4281 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 well for me and is a great improvement.

One nit I noticed was that when adding or editing an object (such as book in your demo), after saving the admin URL loses the ?author= parental reference, and I see all books.

I don't see including all the children as bad parenting per se.

@willbarton
Copy link
Member Author

@higs4281 Ah yes, that is an oversight!

@willbarton
Copy link
Member Author

willbarton commented May 18, 2018

@higs4281 alrighty, that should be fixed now too! Creating, editing, and deleting an object should redirect to the parent-filtered child listing!

@willbarton willbarton force-pushed the good-parenting branch 4 times, most recently from 5c02112 to 081533b Compare May 18, 2018 17:59
@willbarton willbarton merged commit 0345140 into master May 18, 2018
@willbarton willbarton deleted the good-parenting branch May 18, 2018 19:44
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.

2 participants