def extended_search(request): """ extended search """ tags = Tag.objects.all().order_by("name") langs = available_languages() return render_response(request, 'book/xhtml/extended_search.xml', { 'tags': tags, 'langs': langs, })
def books_by_language(request, response_type): """builds opds and xhtml response for books by lang request""" languages = available_languages() if response_type == "atom": return render_response(request, 'book/opds/books_by_lang.xml', {'languages': languages}) if response_type == "xhtml": return render_response(request, 'book/xhtml/books_by_lang.xml', {'languages': languages})
def books_by_tags(request, response_type, site=""): """builds opds and xhtml response for books by tags request""" add_request = Q() book_add_req = Q() all_tags = Tag.objects.all() if site == "libru": add_request = Q(book__pagelink__startswith="http://lib.ru") book_add_req = Q(pagelink__startswith="http://lib.ru") all_tags = available_tags() tags_top = [] for tag in all_tags: if tag.credit == 2: tags_top.append(tag) tags_sub = {} for t in tags_top: num = Book.objects.filter(Q(tag=t) & book_add_req).count() tempt = [] for tag in all_tags: if tag.parent == t and tag.credit == 1: tempt.append(tag) tempt = sorted(tempt, key = lambda x: x.name) first_level = Q(parent__name=t.name) & add_request second_level = Q(parent__parent__name=t.name) & add_request third_level = Q(parent__parent__parent__name=t.name) & add_request req = (first_level | second_level | third_level) & Q(credit=-1) tempt_sub = Tag.objects.filter(req).order_by("name") tempt1 = [] for st in tempt: tempt1.append( (st, Book.objects.filter(Q(tag=st) & book_add_req).count()) ) q = Q(tag=t) & book_add_req for tt in tempt: q = q & ~Q(tag=tt) tempt1.append( (None, Book.objects.filter(q).count()) ) tempt1_sub = [] for st in tempt_sub: tempt1_sub.append( (st, Book.objects.filter(tag=st).count()) ) tags_sub[(t, num)] = (tempt1, tempt1_sub) languages = available_languages(site) tags = [] for tag in tags_sub: tags.append(tag[0].name) if response_type == "atom": return render_response_atom(request, 'book/opds/books_by_tag.xml', {'tags':tags, 'languages':languages}) if response_type == "xhtml": return render_response(request, 'book/xhtml/books_by_tag.xml', {'tags_sub':sorted(tags_sub.iteritems(), key = lambda ((k, n), v): k.name), 'languages':languages})
def books_by_tags(request, response_type): """builds opds and xhtml response for books by tags request""" tags = Tag.objects.all().order_by("name") languages = available_languages() if response_type == "atom": return render_response(request, 'book/opds/books_by_tag.xml', { 'tags': tags, 'languages': languages }) if response_type == "xhtml": return render_response(request, 'book/xhtml/books_by_tag.xml', { 'tags': tags, 'languages': languages })
def books_by_language(request, response_type, site=""): """ builds opds and xhtml response for books by lang request """ languages = available_languages(site) comparator = lambda x, y: Book.objects.filter(language=y).count() - \ Book.objects.filter(language=x).count() languages = sorted(languages, cmp=comparator) if response_type == "atom": return render_response_atom(request, 'book/opds/books_by_lang.xml', {'languages':languages}) if response_type == "xhtml": return render_response(request, 'book/xhtml/books_by_lang.xml', {'languages':languages})
def extended_search(request, site=""): """ extended search """ tags = Tag.objects.all().order_by("name") langs =available_languages(site) return render_response(request, 'book/xhtml/extended_search.xml', {'tags': tags, 'langs': langs,})