Suggest adding:
from django.utils.http import urlquote
from django.template import RequestContext
from django import template
from django.utils.html import *
from django.template import RequestContext
from django import template
from django.utils.html import *
+from django.utils.http import urlquote
from django.db.models import Q, Count
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from django.db.models import Q, Count
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse