티스토리 수익 글 보기

티스토리 수익 글 보기

feat: add shortcuts by michaelschem · Pull Request #17599 · django/django · GitHub
Skip to content

Conversation

michaelschem
Copy link

@michaelschem michaelschem commented Dec 12, 2023

Add Keyboard Shortcuts to Django Admin Interface

Description

This pull request introduces keyboard shortcuts to the Django admin interface, enhancing the user experience by allowing faster navigation and actions using the keyboard. Three main shortcuts have been implemented:

  1. Save and Continue Editing: Allows users to save changes and remain on the current page.
  2. Save: Saves changes and returns to the admin index page.
  3. Save and Add Another: Saves the current object and opens a new form for adding another object of the same type.

The following table summarizes the keyboard shortcuts for both Windows and Mac users:

Action Windows/Linux Shortcut Mac Shortcut
Save and Continue Editing Ctrl + S Cmd + S
Save Ctrl + Shift + S Cmd + Shift + S
Save and Add Another Ctrl + Alt + S Cmd + Option + S

Implementation Details

  • JavaScript code has been added to base_site.html to listen for specific key combinations and trigger the corresponding actions.
  • The script targets the input elements of the admin forms based on their name attributes (_continue, _save, and _addanother).
  • The implementation ensures no conflict with existing browser or system shortcuts and is designed to enhance usability without disrupting current workflows.

Testing

  • The feature has been tested across various browsers (Chrome, Firefox, Safari) to ensure compatibility and functionality.
  • TODO: Add Additional tests to cover the new feature and ensure it does not interfere with existing admin functionalities.

Documentation

  • TODO: Add documentation to include the new keyboard shortcuts and instructions on their usage.

This feature aims to streamline the workflow in the Django admin interface, making it more efficient and user-friendly, especially for power users who rely heavily on keyboard navigation.

Discussion

A discussion has been created here

@pauloxnet
Copy link
Member

Please add instructions also for Linux users, they are the majority of all Django developers as per the Django Survey 2022
https://lp.jetbrains.com/django-developer-survey-2022/

@michaelschem
Copy link
Author

@pauloxnet windows and linux should be the same. Description updated.

@knyghty knyghty requested a review from a team January 13, 2024 16:42
@thibaudcolas
Copy link
Member

Hi @michaelschem 👋 I think it’d be great to have keyboard shortcuts in Django, but for a feature like this I’d personally expect some discussion in a ticket or forum post beforehand. In particular I’d like to hear people’s thoughts on:

  • Which actions should have shortcuts, based on frequency of use, availability in other similar tools.
  • What key combinations should be used. Based on consistency with other tools.
  • How we could make those shortcuts discoverable by end users (for example, in GitHub on macOS I can press Shift + ? to view a list)

@michaelschem
Copy link
Author

hey, @thibaudcolas, thanks for your feedback! I also agree a discussion about the points you brought up would be great. I was under the impression this would be the correct place for that kind of a thing, but I’ll go ahead and raise the issue on the form and link it here.

@michaelschem
Copy link
Author

@thibaudcolas I added hints to the buttons on hover. I think this would be a good start for discoverability.
image

@thibaudcolas
Copy link
Member

@michaelschem no, any use of the title attribute is completely unusable for keyboard users in particular, so we shouldn’t use it. Personally I’d recommend to never ever use the title attribute in HTML except for iframe elements.

@michaelschem
Copy link
Author

hey, @thibaudcolas I’m happy to make the change to add the keyboard shortcut hints, but can you merge this PR first? It seems pretty low impact as far as risk and a huge time saver for my Django admin users.

@thibaudcolas
Copy link
Member

thibaudcolas commented Feb 2, 2024

@michaelschem please spend some time reading Django’s process for feature requests like this as defined in our docs. I’m not too up to speed with it myself but I believe we expect all proposed features to start with a forum discussion, which hasn’t happened here yet. You’ve started the thread at Django Admin Save Shortcuts, there needs to be some validation / consensus from others now.

As far as this being low impact / a time saver – I don’t think it’s acceptable we’d add shortcuts like this without any way for users to learn them. Django doesn’t have a documentation site for the admin, so we’d have to have docs within the admin in some form.

And we’d definitely want some review of the actual shortcuts. For example, personally without spending too much time thinking about it I’d have expected the “Save” shortcut to be Cmd/Ctrl + S without modifiers.

@thibaudcolas thibaudcolas removed the request for review from a team February 2, 2024 21:44
- Implements Ctrl/Cmd+S for save-and-continue editing
- Implements Ctrl/Cmd+Shift+S for save-and-exit
- Implements Ctrl/Cmd+Alt+S for save-and-add-another
- Includes cross-platform compatibility (Mac/Windows/Linux)
- Adds visual tooltip hints showing available shortcuts
- Provides comprehensive test coverage
- Follows progressive enhancement principles
- Only loads on form pages for optimal performance

Refactored from inline JavaScript in base_site.html to:
- Dedicated shortcuts.js module for better maintainability
- Proper separation of concerns
- Improved code organization following DRY principles
- Enhanced error handling and edge case coverage

Includes:
- Full test suite in test_shortcuts.py
- User documentation in docs/ref/contrib/admin/shortcuts.txt
- Accessibility considerations and screen reader compatibility
- Conflict prevention with browser shortcuts and input fields

Fixes keyboard shortcut implementation to follow Django development best practices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To Review
Development

Successfully merging this pull request may close these issues.

3 participants