Add filtering by Date range. Allow users to filter stats screens by saved queries (closes GH-58)

This commit is contained in:
Ross Poulton 2011-05-13 08:02:59 +10:00
parent 04ad20d42f
commit cc4ea9a4f8
3 changed files with 36 additions and 0 deletions

View File

@ -15,6 +15,20 @@
{% block helpdesk_body %} {% block helpdesk_body %}
<h2>{% trans "Reports &amp; Statistics" %}</h2> <h2>{% trans "Reports &amp; Statistics" %}</h2>
{% if user_saved_queries_ %}
<p>{% trans "You can run this query on filtered data by using one of your saved queries." %}</p>
<form method='GET' action='./'>
<label for='saved_query'>{% trans "Select Query:" %}</label>
<select name='saved_query'>
<option value="">--------</option>{% for q in user_saved_queries_ %}
<option value="{{ q.id }}"{% ifequal saved_query q %} selected{% endifequal %}>{{ q.title }}</option>{% endfor %}
</select>
<input type='submit' value='{% trans "Filter Report" %}'>
</form>
{% else %}
<p>{% trans "Want to filter this report to just show a subset of data? Go to the Ticket List, filter your query, and save your query." %}</p>
{% endif %}
<table> <table>
<tr class='row_tablehead'><td colspan='{{ headings|length }}'>{{ title }}</td></tr> <tr class='row_tablehead'><td colspan='{{ headings|length }}'>{{ title }}</td></tr>
<tr class='row_columnheads'>{% for h in headings %}<th>{% if forloop.first %}{{ h|title }}{% else %}{{ h }}{% endif %}</th>{% endfor %}</tr> <tr class='row_columnheads'>{% for h in headings %}<th>{% if forloop.first %}{{ h|title }}{% else %}{{ h }}{% endif %}</th>{% endfor %}</tr>

View File

@ -42,7 +42,9 @@ $(document).ready(function() {
{% if not from_saved_query %} {% if not from_saved_query %}
<li><a href='#tabsave'>Save This Query</a></li> <li><a href='#tabsave'>Save This Query</a></li>
{% endif %} {% endif %}
{% if user_saved_queries %}
<li><a href='#tabload'>Load Saved Query</a></li> <li><a href='#tabload'>Load Saved Query</a></li>
{% endif %}
</ul> </ul>
<div id='tabfilter'> <div id='tabfilter'>
@ -54,6 +56,7 @@ $(document).ready(function() {
<option value='Queue'>{% trans "Queue" %}</option> <option value='Queue'>{% trans "Queue" %}</option>
<option value='Status'>{% trans "Status" %}</option> <option value='Status'>{% trans "Status" %}</option>
<option value='Keywords'>{% trans "Keywords" %}</option> <option value='Keywords'>{% trans "Keywords" %}</option>
<option value='Dates'>{% trans "Date Range" %}</option>
{% if tags_enabled %} {% if tags_enabled %}
<option value='Tags'>{% trans "Tags" %}</option> <option value='Tags'>{% trans "Tags" %}</option>
{% endif %} {% endif %}
@ -114,6 +117,13 @@ $(document).ready(function() {
<p class='filterHelp'>Ctrl-click to select multiple options</p> <p class='filterHelp'>Ctrl-click to select multiple options</p>
<input type='button' class='filterBuilderRemove' value='-' /> <input type='button' class='filterBuilderRemove' value='-' />
</div> </div>
<div class='filterBox{% if query_params.filtering.created__gte or query_params.filtering.created__lte %} filterBoxShow{% endif %}' id='filterBoxDates'>
<label for='id_date_from'>{% trans "Date (From)" %}</label><input type='text' name='date_from' value='{{ query_params.filtering.created__gte }}' id='id_date_from' />
<label for='id_date_to'>{% trans "Date (To)" %}</label><input type='text' name='date_to' value='{{ query_params.filtering.created__lte }}' id='id_date_to' />
<p class='filterHelp'>Use YYYY-MM-DD date format, eg 2011-05-29</p>
<input type='button' class='filterBuilderRemove' value='-' />
</div>
{% if tags_enabled %} {% if tags_enabled %}
<div class='filterBox{% if query_params.tags %} filterBoxShow{% endif %}' id='filterBoxTags'> <div class='filterBox{% if query_params.tags %} filterBoxShow{% endif %}' id='filterBoxTags'>
@ -133,6 +143,9 @@ $(document).ready(function() {
{% if from_saved_query and saved_query.user = user %} {% if from_saved_query and saved_query.user = user %}
<p>{% blocktrans with saved_query.title as query_name %}You are currently viewing saved query <em>{{ query_name }}</em>.{% endblocktrans %} <a href='{% url helpdesk_delete_query saved_query.id %}'>{% trans "Delete Saved Query" %}</a></p> <p>{% blocktrans with saved_query.title as query_name %}You are currently viewing saved query <em>{{ query_name }}</em>.{% endblocktrans %} <a href='{% url helpdesk_delete_query saved_query.id %}'>{% trans "Delete Saved Query" %}</a></p>
{% endif %} {% endif %}
{% if from_saved_query %}
<p>{% blocktrans with saved_query.id as query_id %}<a href='../reports/?saved_query={{ query_id }}'>Run a report</a> on this query to see stats and charts for the data listed below.{% endblocktrans %}</p>
{% endif %}
{% csrf_token %}</form> {% csrf_token %}</form>
</div> </div>

View File

@ -558,6 +558,14 @@ def ticket_list(request):
statuses = [int(s) for s in statuses] statuses = [int(s) for s in statuses]
query_params['filtering']['status__in'] = statuses query_params['filtering']['status__in'] = statuses
date_from = request.GET.get('date_from')
if date_from:
query_params['filtering']['created__gte'] = date_from
date_to = request.GET.get('date_to')
if date_to:
query_params['filtering']['created__lte'] = date_to
### KEYWORD SEARCHING ### KEYWORD SEARCHING
q = request.GET.get('q', None) q = request.GET.get('q', None)
@ -582,6 +590,7 @@ def ticket_list(request):
query_params['sortreverse'] = sortreverse query_params['sortreverse'] = sortreverse
ticket_qs = apply_query(Ticket.objects.select_related(), query_params) ticket_qs = apply_query(Ticket.objects.select_related(), query_params)
print str(ticket_qs.query)
## TAG MATCHING ## TAG MATCHING
if HAS_TAG_SUPPORT: if HAS_TAG_SUPPORT: