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

Redirect to collection listing after editing/deleting an item from it #7810

Closed

Conversation

Tijani-Dia
Copy link
Collaborator

@Tijani-Dia Tijani-Dia commented Dec 23, 2021

When a user selects a collection to browse in the admin and opens a file to make some changes to it, on save, the admin browser defaults back to a default view of documents/images instead of staying on the collection and the page of the collection the users was on when they clicked on the file to make changes.

The goal of this PR is to make the view remember the collection users were exploring before editing one item from that collection.

  • Do the tests still pass? Yes
  • Does the code comply with the style guide? Yes
  • For Python changes: Have you added tests to cover the new/fixed behaviour? Yes
  • For new features: Has the documentation been updated accordingly? No

@squash-labs
Copy link

squash-labs bot commented Dec 23, 2021

Manage this branch in Squash

Test this branch here: https://tijani-diafeaturecollection-re-t7n7q.squash.io

Copy link
Member

@jacobtoppm jacobtoppm left a comment

Choose a reason for hiding this comment

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

Looking good! A few bits to consider - also, we lose the information when following the edit -> delete -> listing path

edit_url = reverse('wagtaildocs:edit', args=(doc.id,))
redirect_url = 'wagtaildocs:index'
if next_url:
edit_url += "?" + urlencode({"next": next_url})
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: You can probably use an f-string or similar instead of concatenation here

wagtail/documents/views/documents.py Show resolved Hide resolved
collection_id = self.request.GET.get('collection_id')
if collection_id:
try:
self.current_collection = Collection.objects.get(id=collection_id)
images = images.filter(collection=self.current_collection)
next_url = reverse('wagtailimages:index') + "?" + urlencode({"collection_id": collection_id})
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this? Shouldn't we just use the current url, so we get tags (for instance) as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure! I've updated it to use the current url so we don't lose information.

@Tijani-Dia Tijani-Dia changed the title Redirect to collection listing after editing an item from it Redirect to collection listing after editing/deleting an item from it Jan 10, 2022
Copy link
Member

@jacobtoppm jacobtoppm left a comment

Choose a reason for hiding this comment

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

Nice work! LGTM

@jacobtoppm
Copy link
Member

Merged in bafb435

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.

None yet

4 participants