diff --git a/helpdesk/templates/helpdesk/base.html b/helpdesk/templates/helpdesk/base.html index cff8e61f..fcf3d5a3 100644 --- a/helpdesk/templates/helpdesk/base.html +++ b/helpdesk/templates/helpdesk/base.html @@ -1,4 +1,7 @@ -{% load i18n %} +{% load i18n %} +{% load saved_queries %} +{% with request|saved_queries as user_saved_queries_ %} + {% block helpdesk_title %}Helpdesk{% endblock %} :: {% trans "Powered by django-helpdesk" %} @@ -36,26 +39,26 @@
  • {% trans "Tickets" %}
  • {% trans "New Ticket" %}
  • {% trans "Stats" %}
  • - {% if user_saved_queries %} + {% if user_saved_queries_ %}
  • Load Saved Query
  • - {% endif %} + {% endif %}
  • {% trans "Logout" %}
  • {% if not query %}
  • {% csrf_token %}
  • {% endif %} - {% if user_saved_queries %} -
    -
    - - - {% csrf_token %}
    -
    - {% endif %} + {% if user_saved_queries_ %} +
    +
    + + + {% csrf_token %}
    +
    + {% endif %}
    {% block helpdesk_body %}{% endblock %} @@ -67,3 +70,4 @@ {% include "helpdesk/debug.html" %} +{% endwith %} diff --git a/helpdesk/templatetags/saved_queries.py b/helpdesk/templatetags/saved_queries.py new file mode 100644 index 00000000..057ef119 --- /dev/null +++ b/helpdesk/templatetags/saved_queries.py @@ -0,0 +1,19 @@ +""" +django-helpdesk - A Django powered ticket tracker for small enterprise. + +templatetags/saved_queries.py - This template tag returns previously saved + queries. Therefore you don't need to modify + any views. +""" + +from django.template import Library +from django.db.models import Q +from helpdesk.models import SavedSearch + + +def saved_queries(request): + user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True)) + return user_saved_queries + +register = Library() +register.filter('saved_queries', saved_queries) diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 4585e3c4..9a148f41 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -74,14 +74,12 @@ def dashboard(request): ORDER BY q.id; """) dash_tickets = query_to_dict(cursor.fetchall(), cursor.description) - user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True)) return render_to_response('helpdesk/dashboard.html', RequestContext(request, { 'user_tickets': tickets, 'unassigned_tickets': unassigned_tickets, 'dash_tickets': dash_tickets, - 'user_saved_queries': user_saved_queries, })) dashboard = staff_member_required(dashboard) @@ -135,7 +133,6 @@ def followup_edit(request, ticket_id, followup_id, ): def view_ticket(request, ticket_id): ticket = get_object_or_404(Ticket, id=ticket_id) - user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True)) if request.GET.has_key('take'): # Allow the user to assign the ticket to themselves whilst viewing it. @@ -156,7 +153,6 @@ def view_ticket(request, ticket_id): 'owner': owner, 'title': ticket.title, 'comment': _('Accepted resolution and closed ticket'), - 'user_saved_queries': user_saved_queries, } return update_ticket(request, ticket_id) @@ -168,7 +164,6 @@ def view_ticket(request, ticket_id): 'priorities': Ticket.PRIORITY_CHOICES, 'preset_replies': PreSetReply.objects.filter(Q(queues=ticket.queue) | Q(queues__isnull=True)), 'tags_enabled': HAS_TAG_SUPPORT, - 'user_saved_queries': user_saved_queries, })) view_ticket = staff_member_required(view_ticket)