X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5dbd487fb7e64aa968da9c3fcbe8a0215d2b3298..a01c8d6aa976110336c8073e56faf3f16f272ed8:/src/catalogue/views.py?ds=sidebyside diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 697a5acf..80e97271 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): + shop = depot.models.Shop.objects.filter(shop='woblink').first() + if shop is None: + return JsonResponse({}) + woblink = shop.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})