Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from fhahn/master

Fixed MultiValueDictKeyError import error
  • Loading branch information...
commit 2a6c7403c4be22018c57be47b77ae0c6bd257ea0 2 parents 9655597 + bf23721
@nealtodd nealtodd authored
View
5 tagging_autocomplete/models.py
@@ -1,7 +1,8 @@
-from django.db import models
+from django.contrib.admin.widgets import AdminTextInputWidget
+
from tagging.fields import TagField
from tagging_autocomplete.widgets import TagAutocomplete
-from django.contrib.admin.widgets import AdminTextInputWidget
+
# The following code is based on models.py file from django-tinymce by Joost Cassee
View
14 tagging_autocomplete/tests.py
@@ -0,0 +1,14 @@
+from django.core.urlresolvers import reverse
+from django.test import TestCase
+from django.utils import simplejson
+
+class TaggingAutocompleteViewTest(TestCase):
+ urls = 'tagging_autocomplete.urls'
+
+ def test_no_term(self):
+ """
+ test view list_tags without submitting a term
+ """
+ response = self.client.get(reverse('tagging_autocomplete-list'))
+ data = simplejson.loads(response.content)
+ self.assertEqual(data, [])
View
1  tagging_autocomplete/urls.py
@@ -1,5 +1,6 @@
from django.conf.urls.defaults import *
+
urlpatterns = patterns('tagging_autocomplete.views',
url(r'^list$', 'list_tags', name='tagging_autocomplete-list'),
)
View
16 tagging_autocomplete/views.py
@@ -1,16 +1,16 @@
-from django.core import serializers
-from tagging.models import Tag
from django.http import HttpResponse
from django.utils import simplejson
+from django.utils.datastructures import MultiValueDictKeyError
+
+from tagging.models import Tag
def list_tags(request):
- try:
- tags = Tag.objects.filter(name__istartswith=request.GET['term']).values_list('name', flat=True)
- except MultiValueDictKeyError:
- tags = []
-
- return JsonResponse([x.encode('utf-8') for x in tags])
+ try:
+ tags = Tag.objects.filter(name__istartswith=request.GET['term']).values_list('name', flat=True)
+ except MultiValueDictKeyError:
+ tags = []
+ return JsonResponse([x.encode('utf-8') for x in tags])
class JsonResponse(HttpResponse):
Please sign in to comment.
Something went wrong with that request. Please try again.