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 · 6 comments
Open

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

stuaxo opened this issue Oct 14, 2023 · 6 comments
Assignees

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
Member

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
Member

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)

@lav6301
Copy link

lav6301 commented Oct 19, 2024

Hello,

I'm new to open source contributions and would love to start contributing to this project. I've noticed that this issue is already assigned to @elijah0kello, but if there are any other beginner-friendly tasks or issues available, I would appreciate the opportunity to help out. As a newbie, I'm eager to learn and contribute, so any guidance or work you could assign to me would be great.

Thank you!

@tim-schilling
Copy link
Member

Hi @lav6301, I think it's fair for you to pick this issue up. As for other introductory issues we should have a beginner friendly label on them.

@lav6301
Copy link

lav6301 commented Oct 19, 2024

Hi @tim-schilling,

Thank you for assigning the issue to me! I'll start working on it right away. If I have any questions while working on this issue, I'll reach out for clarification. Thanks again for the opportunity!

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

4 participants