-@ssi_included(use_lang=False)
-def cite_info(request, pk):
- cite = get_object_or_404(Cite, pk=pk)
- return render(request, 'social/cite_info.html', {
- 'cite': cite,
- })
+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))
+
+
+@never_cache
+@login_required
+def my_tags(request):
+ term = request.GET.get('term', '')
+ tags = Tag.objects.filter(user=request.user).order_by('sort_key')
+ if term:
+ tags = tags.filter(name__icontains=term)
+ return JsonResponse(
+ [
+ t.name for t in tags
+ ], safe=False
+ )
+
+
+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 context_description(self, request, obj):
+ return obj.pretty_title()
+
+ def form_args(self, request, obj):
+ return (obj, request.user), {}