Skip to content

Ajax Requests panel - proof of concept #253

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

Closed
wants to merge 2 commits into from

Conversation

tobiasmcnulty
Copy link

It's certainly not commit ready yet, but I wanted to open this pull request to facilitate feedback on this idea.

The code implements an "Ajax Requests" panel that lists out ajax requests that have occurred. You can then click on one of the requests to replace your current debug toolbar with the toolbar rendered for that ajax request.

Would you consider integrating a panel like this? If so, what sorts of changes would need to be made first? I'll happily write some tests. I'm also not very happy with storing the rendered toolbars in the session, so I'll probably have to come up with some other form of semi-persistent server-side storage.

Apologies if someone else has done something like this already - if they have I didn't find it. I did find an old fork that did something like this (used the cache to store the most recent AJAX request and load that), but nothing that added a panel and allowed debugging multiple AJAX requests at once, which is probably a necessity in most cases.

Anyways, looking forward to your feedback. Thanks!

@dcramer
Copy link
Contributor

dcramer commented Jan 17, 2012

This idea has been brought up before, and I like the concept a lot. I'm also not sure the session is the right place to store it. Someone else suggested memcache, which seems a bit more bearable.

@jezdez
Copy link
Contributor

jezdez commented Jan 17, 2012

I was just about to implement exactly that, woot! I agree with @dcramer that putting this in a cache (preferable in an own cache backend, falling back to the default one) with the str(uuid.uuid4())-key as the cache key should be better than straining the session API to do the same thing. For local development purposes the locmem backend is totally able to handle that kind of data, too.

@tobiasmcnulty
Copy link
Author

Thanks for the feedback guys. I think your suggestion to use the cache sounds good. @jezdez I'm not quite sure what you mean by its own cache backend though? I'd hoped to have some code ready when I replied, but I've been completely swamped this week and haven't had a chance to do anything yet. I'll try to work on these improvements soon and update the pull request accordingly.

@jezdez
Copy link
Contributor

jezdez commented Feb 24, 2012

@tobiasmcnulty Oh, I meant that the CACHES setting now can be configured to have multiple backends to have different setup, e.g. using locmem in development and different memcache servers in production:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    },
    'debug_toolbar': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'debug_toolbar',
        'TIMEOUT': 60,
    }
}

Later in the code we could check if a debug_toolbar cache has been configured and fall back to the default cache if not:

from django.core.cache import (get_cache, cache as default_cache,
                               InvalidCacheBackendError)

try:
    debug_toolbar_cache = get_cache('debug_toolbar')
except InvalidCacheBackendError:
    # Use the default backend
    debug_toolbar_cache = default_cache

@Pewpewarrows
Copy link

@tobiasmcnulty Keep in mind that when looking at the toolbar for a specific AJAX request there should still be an easy way to get back to the original page's toolbar. I believe as it stands this only allows switching between other AJAX requests once inside one's toolbar.

@jonahblake
Copy link

@tobiasmcnulty Thanks for getting this started! I would love to have this working, have there been any recent updates? I tried using the posted changes, but now my toolbar does not show up. Any ideas? Thanks.

@tobiasmcnulty
Copy link
Author

Sorry, I've not had the time to polish this off - feel free to give it a whirl if you'd like!

aflukasz pushed a commit to aflukasz/django-debug-toolbar that referenced this pull request Feb 18, 2013
This is a rebase+squash of the original commits by Tobias McNulty (@tobiasmcnulty),
taken from pull request django-commons#253, with some
minor changes to resolve merge conflicts.
@jezdez
Copy link
Contributor

jezdez commented Apr 23, 2013

Closing in favor of #356.

@jezdez jezdez closed this Apr 23, 2013
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.

5 participants