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

Make copying context easier (for pasting into an editor or shell). #1840

Open
stuaxo opened this issue Oct 14, 2023 · 3 comments
Open

Make copying context easier (for pasting into an editor or shell). #1840

stuaxo opened this issue Oct 14, 2023 · 3 comments

Comments

@stuaxo
Copy link

stuaxo commented Oct 14, 2023

A lot of the time I'm looking at the context of templates, the next step is top paste it into an editor for reasons[1] - especially including pasting into a python shell or notebook to explore.

At the moment it's inconvenient: You have to manually select the data - making it easy to select things that aren't the context data, and the data isn't exactly in a useable format ready to paste into a python list.

See this example - the first and second items are not comma separated and there is no start and end bracket.:
image

It would be nice to have a "Copy to clipboard" button, perhaps that floats in the top right of the context.
It would also be good if the text was in a format that was likely to work in a python shell, but maybe that is a slightly different issue (at the

[1] - scrolling up and down in the browser is less convenient with everything there, searching is more fiddly etc

@tim-schilling
Copy link
Contributor

This is a solid idea. I suspect we need to print the !r version rather than the string version. The copy logic should be manageable. I believe the Django error page does this for the stacktrace already.

@stuaxo do you have the availability to create a PR?

@stuaxo
Copy link
Author

stuaxo commented Oct 14, 2023

I can probably start with the !r bit, it's a small thing - useful.

Do you have pointers in DDT codebase I can look at?

@tim-schilling
Copy link
Contributor

This is the part of the code that renders that html: https://github.com/jazzband/django-debug-toolbar/blob/main/debug_toolbar/templates/debug_toolbar/panels/templates.html#L23

We'll want to add a button or something to it that allows copying the context here. Then hook into the click event handler in a template specific javascript file. You can see how history.js is defined and included, as well as how it handles button clicks: https://github.com/jazzband/django-debug-toolbar/blob/main/debug_toolbar/static/debug_toolbar/js/history.js


Something that's not entirely clear is what exactly are you hoping to copy and paste? The examples in the original issue are valid python dictionaries.

Another challenge is that some of the context values are not going to be python values (see assignments to temp_layer[key] https://github.com/jazzband/django-debug-toolbar/blob/main/debug_toolbar/panels/templates/panel.py#L143-L170)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants