Rename publishable to approved, add profile option to approve by default.
[redakcja.git] / src / catalogue / views.py
index 697a5ac..2ed4216 100644 (file)
@@ -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 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
 
 
 @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({})
     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})