mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2024-12-13 18:31:10 +01:00
Add filtering by Date range. Allow users to filter stats screens by saved queries (closes GH-58)
This commit is contained in:
parent
04ad20d42f
commit
cc4ea9a4f8
@ -15,6 +15,20 @@
|
||||
{% block helpdesk_body %}
|
||||
<h2>{% trans "Reports & 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>
|
||||
<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>
|
||||
|
@ -42,7 +42,9 @@ $(document).ready(function() {
|
||||
{% if not from_saved_query %}
|
||||
<li><a href='#tabsave'>Save This Query</a></li>
|
||||
{% endif %}
|
||||
{% if user_saved_queries %}
|
||||
<li><a href='#tabload'>Load Saved Query</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<div id='tabfilter'>
|
||||
@ -54,6 +56,7 @@ $(document).ready(function() {
|
||||
<option value='Queue'>{% trans "Queue" %}</option>
|
||||
<option value='Status'>{% trans "Status" %}</option>
|
||||
<option value='Keywords'>{% trans "Keywords" %}</option>
|
||||
<option value='Dates'>{% trans "Date Range" %}</option>
|
||||
{% if tags_enabled %}
|
||||
<option value='Tags'>{% trans "Tags" %}</option>
|
||||
{% endif %}
|
||||
@ -115,6 +118,13 @@ $(document).ready(function() {
|
||||
<input type='button' class='filterBuilderRemove' value='-' />
|
||||
</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 %}
|
||||
<div class='filterBox{% if query_params.tags %} filterBoxShow{% endif %}' id='filterBoxTags'>
|
||||
<label for='id_tags'>{% trans "Tag(s)" %}</label><select id='id_tags' name='tags' multiple='selected' size='5'>{% for t in tag_choices %}<option value='{{t.name}}'{% if t.name|in_list:query_params.tags %} selected='selected'{% endif %}>{{ t.name }}</option>{% endfor %}</select>
|
||||
@ -133,6 +143,9 @@ $(document).ready(function() {
|
||||
{% 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>
|
||||
{% 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>
|
||||
</div>
|
||||
|
||||
|
@ -558,6 +558,14 @@ def ticket_list(request):
|
||||
statuses = [int(s) for s 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
|
||||
q = request.GET.get('q', None)
|
||||
|
||||
@ -582,6 +590,7 @@ def ticket_list(request):
|
||||
query_params['sortreverse'] = sortreverse
|
||||
|
||||
ticket_qs = apply_query(Ticket.objects.select_related(), query_params)
|
||||
print str(ticket_qs.query)
|
||||
|
||||
## TAG MATCHING
|
||||
if HAS_TAG_SUPPORT:
|
||||
|
Loading…
Reference in New Issue
Block a user