You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
773 B
19 lines
773 B
import json
|
|
from django.http import HttpResponse
|
|
from theme.models import Tag
|
|
|
|
|
|
def get_tag(request):
|
|
#if request.is_ajax():
|
|
themes = request.GET.getlist('themes[]')
|
|
term = request.GET['term'].capitalize()
|
|
if not term:
|
|
qs = Tag.objects.language().filter(theme__id__in=themes).order_by('translations__name').distinct()
|
|
else:
|
|
qs = Tag.objects.language().filter(theme__id__in=themes, translations__name__contains=term).distinct()
|
|
result = [{'id': tag.id, 'label': '%s (%s)'%(tag.name, tag.theme.name)} for tag in qs]
|
|
result = sorted(result, key=lambda x:x['label'])
|
|
|
|
return HttpResponse(json.dumps(result), content_type='application/json')
|
|
#else:
|
|
# return HttpResponse('not ajax')
|
|
|