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.
31 lines
1.2 KiB
31 lines
1.2 KiB
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()
|
|
qs = Tag.objects.language().exclude(theme__article__id=None).distinct()
|
|
if term:
|
|
qs = qs.filter(translations__name__contains=term)
|
|
if themes:
|
|
qs = qs.filter(theme__id__in=themes).order_by('translations__name')
|
|
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')
|
|
|
|
|
|
def get_article_tags(request):
|
|
term = request.GET['term'].capitalize()
|
|
qs = Tag.objects.language().exclude(article=None).filter(article__type=1).distinct()
|
|
if term:
|
|
qs = qs.filter(translations__name__contains=term)
|
|
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') |