X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5dbd487fb7e64aa968da9c3fcbe8a0215d2b3298..51ea493dd4c46246c80ed3190b43ebfc0d75d67c:/src/catalogue/views.py diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 697a5acf..2ed4216d 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -20,7 +20,7 @@ from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import serializers -from depot.woblink import get_woblink_session +import depot.models @@ -383,20 +383,20 @@ def publish_collection(request, pk): @login_required -def woblink_author_autocomplete(request): - session = get_woblink_session() +def woblink_autocomplete(request, category): + site = depot.models.Site.objects.filter(site_type='woblink').first() + if site is None: + return JsonResponse({}) + woblink = site.get_publisher() term = request.GET.get('term') if not term: return JsonResponse({}) - response = session.get( - 'https://publisher.woblink.com/author/autocomplete/' + term - ).json() - return JsonResponse({ - "results": [ - { - "id": item['autId'], - "text": item['autFullname'], - } - for item in response - ], - }) + + if category == 'author': + results = woblink.search_author_catalogue(term) + elif category == 'series': + results = woblink.search_series_catalogue(term) + else: + raise Http404 + + return JsonResponse({"results": results})