|
|
|
|
@ -5,16 +5,30 @@ 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']) |
|
|
|
|
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') |
|
|
|
|
return HttpResponse(json.dumps(result), content_type='application/json') |
|
|
|
|
#else: |
|
|
|
|
# return HttpResponse('not ajax') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_article_tags(request): |
|
|
|
|
themes = request.GET.getlist('themes[]') |
|
|
|
|
term = request.GET['term'].capitalize() |
|
|
|
|
qs = Tag.objects.language().exclude(article=None).filter(article__type=1).distinct() |
|
|
|
|
if themes: |
|
|
|
|
qs = qs.filter(theme__id__in=themes).order_by('translations__name') |
|
|
|
|
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') |