forked from pinax/code.pinaxproject.com
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed the tagging widget to use ajax
- Loading branch information
Showing
4 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.conf.urls.defaults import * | ||
|
||
urlpatterns = patterns('', | ||
url(r'^autocomplete/(?P<app_label>\w+)/(?P<model>\w+)/$', 'tagging_utils.views.autocomplete', name='tagging_utils_autocomplete'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.http import HttpResponse, Http404 | ||
from django.db.models import get_model | ||
from django.utils import simplejson | ||
from tagging.models import Tag | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
def autocomplete(request, app_label, model): | ||
try: | ||
model = ContentType.objects.get(app_label=app_label, model=model) | ||
except: | ||
raise Http404 | ||
|
||
if not request.GET.has_key('q'): | ||
raise Http404 | ||
else: | ||
q = request.GET['q'] | ||
|
||
limit = request.GET.get('limit', None) | ||
|
||
tags = Tag.objects.filter(items__content_type=model, name__istartswith=q).distinct().order_by('name')[:limit] | ||
tag_list = '\n'.join([tag.name for tag in tags if tag]) | ||
|
||
return HttpResponse(tag_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters