X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/2d538a50605add2666172861744229599487f1b2..0f2ac86f03177aebee66a3890120d9926272cf27:/src/catalogue/views.py diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 73015802..2ed4216d 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -383,23 +383,20 @@ def publish_collection(request, pk): @login_required -def woblink_author_autocomplete(request): - shop = depot.models.Shop.objects.filter(shop='woblink').first() - if shop is None: +def woblink_autocomplete(request, category): + site = depot.models.Site.objects.filter(site_type='woblink').first() + if site is None: return JsonResponse({}) - woblink = shop.get_publisher() + woblink = site.get_publisher() term = request.GET.get('term') if not term: return JsonResponse({}) - response = woblink.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})