-class ObjectSetsFormView(AjaxableFormView):
- form_class = forms.ObjectSetsForm
- placeholdize = True
- template = 'social/sets_form.html'
- ajax_redirect = True
- POST_login = True
-
- def get_object(self, request, slug):
- return get_object_or_404(Book, slug=slug)
+def get_sets_for_book_ids(book_ids, user):
+ data = {}
+ tagged = catalogue.models.tag.TagRelation.objects.filter(
+ tag__user=user,
+ #content_type= # for books,
+ object_id__in=book_ids
+ ).order_by('tag__sort_key')
+ for t in tagged:
+ # related?
+ item = data.setdefault(t.object_id, [])
+ if t.tag.name:
+ item.append({
+ "slug": t.tag.slug,
+ "url": t.tag.get_absolute_url(),
+ "name": t.tag.name,
+ })
+ for b in book_ids:
+ if b not in data:
+ data[b] = None
+ return data
+
+
+
+
+@never_cache
+def my_liked(request):
+ if not request.user.is_authenticated:
+ return JsonResponse({})
+ try:
+ ids = [int(x) for x in request.GET.get('ids', '').split(',')]
+ except:
+ return JsonResponse({})
+ return JsonResponse(get_sets_for_book_ids(ids, request.user))