├── .gitignore ├── AUTHORS ├── CHANGES ├── LICENSE ├── MANIFEST.in ├── README.rst ├── haystack_panel ├── __init__.py ├── panel.py ├── templates │ └── haystack_panel │ │ └── haystack_panel.html └── tests.py ├── setup.cfg └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | 3 | # Packages 4 | *.egg 5 | *.egg-info 6 | dist 7 | build 8 | eggs 9 | parts 10 | bin 11 | var 12 | sdist 13 | develop-eggs 14 | .installed.cfg 15 | 16 | # Installer logs 17 | pip-log.txt 18 | 19 | # Unit test / coverage reports 20 | .coverage 21 | .tox 22 | 23 | #Translations 24 | *.mo 25 | 26 | #Mr Developer 27 | .mr.developer.cfg 28 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | http://github.com/streeter/django-haystack-panel/contributors -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 2 | 0.1.0 3 | * Initial implementation 4 | 5 | 0.1.1 6 | * Bug fixes 7 | 8 | 0.1.2 9 | * ?? 10 | 11 | 0.1.3 12 | * Support Django Debug Toolbar versions 0.8.x 13 | 14 | 0.2.0 15 | * Support Django Debug Toolbar version 1.0+ 16 | 17 | (History beyond 0.1.3 is not present) 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Chris Streeter 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include setup.py README.md MANIFEST.in LICENSE CHANGES AUTHORS 2 | recursive-include haystack_panel/templates * 3 | global-exclude *~ 4 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Django Haystack Panel 2 | ===================== 3 | 4 | A Django Debug Toolbar panel for Haystack 5 | 6 | About 7 | ----- 8 | 9 | This is a panel for `Django Debug Toolbar`_ 1.x that displays query results from 10 | Haystack. 11 | 12 | Installation 13 | ------------ 14 | 15 | Install using ``pip``:: 16 | 17 | pip install django-haystack-panel 18 | 19 | or install the development version from source:: 20 | 21 | pip install git+git@github.com:streeter/django-haystack-panel.git 22 | 23 | Then add ``haystack_panel`` to your ``INSTALLED_APPS`` so that we can find the 24 | templates in the panel. Also, add ``'haystack_panel.panel.HaystackDebugPanel'`` 25 | to your ``DEBUG_TOOLBAR_PANELS``. 26 | 27 | Usage 28 | ----- 29 | 30 | TODO 31 | 32 | Testing 33 | ------- 34 | 35 | There are no tests yet. Yeah, I know, I need to add some tests. However, 36 | this has been tested with Haystack version 2.0. I also expect it to work on 37 | at least Haystack >= 1.2.x. Let me know if other versions also work. 38 | 39 | License 40 | ------- 41 | 42 | Uses the `MIT`_ license. 43 | 44 | 45 | .. _Django Debug Toolbar: https://github.com/django-debug-toolbar/django-debug-toolbar 46 | .. _MIT: http://opensource.org/licenses/MIT 47 | -------------------------------------------------------------------------------- /haystack_panel/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | haystack_panel 5 | ~~~~~~~~~~~~~~ 6 | 7 | :copyright: (c) 2014 by Chris Streeter. 8 | :license: See LICENSE for more details. 9 | 10 | """ 11 | 12 | import pkg_resources 13 | 14 | try: 15 | __version__ = pkg_resources.get_distribution('haystack_panel').version 16 | except Exception: 17 | __version__ = 'unknown' 18 | 19 | 20 | __title__ = 'haystack_panel' 21 | __author__ = 'Chris Streeter' 22 | __copyright__ = 'Copyright 2014 Chris Streeter' 23 | 24 | VERSION = __version__ 25 | -------------------------------------------------------------------------------- /haystack_panel/panel.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.template.loader import render_to_string 3 | from django.utils.translation import ugettext_lazy as _ 4 | from debug_toolbar.panels import Panel 5 | 6 | try: 7 | from haystack.backends import queries 8 | haystack_version = 1 9 | except ImportError: 10 | from haystack import connections 11 | haystack_version = 2 12 | 13 | 14 | class HaystackDebugPanel(Panel): 15 | """ 16 | Panel that displays queries made by Haystack backends. 17 | """ 18 | name = 'Haystack' 19 | template = 'haystack_panel/haystack_panel.html' 20 | has_content = True 21 | 22 | def _get_query_count(self): 23 | if haystack_version == 1: 24 | return len(queries) 25 | else: 26 | return sum(map(lambda conn: len(conn.queries), connections.all())) 27 | 28 | def nav_title(self): 29 | return _('Haystack Queries') 30 | 31 | def nav_subtitle(self): 32 | return "%s queries" % self._get_query_count() 33 | 34 | def url(self): 35 | return '' 36 | 37 | def title(self): 38 | return self.nav_title() 39 | 40 | def get_context(self): 41 | query_list = [] 42 | 43 | if haystack_version == 1: 44 | query_list = [q for q in queries] 45 | else: 46 | query_list = [q for conn in connections.all() for q in conn.queries] 47 | query_list.sort(key=lambda q: q['start']) 48 | 49 | return { 50 | 'queries': query_list, 51 | 'debug': getattr(settings, 'DEBUG', False), 52 | } 53 | 54 | def process_response(self, request, response): 55 | if hasattr(self, 'record_stats'): 56 | self.record_stats(self.get_context()) 57 | -------------------------------------------------------------------------------- /haystack_panel/templates/haystack_panel/haystack_panel.html: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | 3 | {#
{% trans "Query String" %} | 9 |{% trans "Additional Args" %} | 10 |{% trans "Additional Kwargs" %} | 11 |{% trans "Time (ms)" %} | 12 |
---|---|---|---|
{{ query.query_string }} | 18 |{% if query.additional_args %}{{ query.additional_args|pprint }} {% endif %} |
19 | {% if query.additional_kwargs %}{{ query.additional_kwargs|pprint }} {% endif %} |
20 | 21 | {{ query.time|floatformat:"3" }} 22 | | 23 |
No Haystack queries were recorded during this request.
30 | {% else %} 31 |
32 | DEBUG
is set to False
. This means
33 | that Haystack query logging is disabled.
34 |