Ejemplo n.º 1
0
def _book_list(request, queryset, qtype=None, list_by='latest', **kwargs):
    """
    Filter the books, paginate the result, and return either a HTML
    book list, or a atom+xml OPDS catalog.
    
    """
    q = request.GET.get('q')
    search_all = request.GET.get('search-all') == 'on'
    search_title = request.GET.get('search-title') == 'on'
    search_author = request.GET.get('search-author') == 'on'

    # If no search options are specified, assumes search all, the
    # advanced search will be used:
    if not search_all and not search_title and not search_author:
        search_all = True

    # If search queried, modify the queryset with the result of the
    # search:
    if q is not None:
        if search_all:
            queryset = advanced_search(queryset, q)
        else:
            queryset = simple_search(queryset, q, search_title, search_author)

    all_books = Book.objects.all()

    paginator = Paginator(queryset, BOOKS_PER_PAGE)
    page = int(request.GET.get('page', '1'))

    try:
        page_obj = paginator.page(page)
    except (EmptyPage, InvalidPage):
        page_obj = paginator.page(paginator.num_pages)

    # Build the query string:
    qstring = page_qstring(request)

    # Return OPDS Atom Feed:
    if qtype == 'feed':
        catalog = generate_catalog(request, page_obj)
        return HttpResponse(catalog, mimetype='application/atom+xml')

    # Return HTML page:
    extra_context = dict(kwargs)
    extra_context.update({
        'book_list': page_obj.object_list,
        'total_books': len(all_books),
        'q': q,
        'paginator': paginator,
        'page_obj': page_obj,
        'search_title': search_title,
        'search_author': search_author,
        'list_by': list_by,
        'qstring': qstring,
    })
    return render_to_response(
        'books/book_list.html',
        extra_context,
        context_instance=RequestContext(request),
    )
Ejemplo n.º 2
0
def _book_list(request, queryset, qtype=None, list_by="latest", **kwargs):
    """
    Filter the books, paginate the result, and return either a HTML
    book list, or a atom+xml OPDS catalog.
    
    """
    q = request.GET.get("q")
    search_all = request.GET.get("search-all") == "on"
    search_title = request.GET.get("search-title") == "on"
    search_author = request.GET.get("search-author") == "on"

    # If no search options are specified, assumes search all, the
    # advanced search will be used:
    if not search_all and not search_title and not search_author:
        search_all = True

    # If search queried, modify the queryset with the result of the
    # search:
    if q is not None:
        if search_all:
            queryset = advanced_search(queryset, q)
        else:
            queryset = simple_search(queryset, q, search_title, search_author)

    all_books = Book.objects.all()

    paginator = Paginator(queryset, BOOKS_PER_PAGE)
    page = int(request.GET.get("page", "1"))

    try:
        page_obj = paginator.page(page)
    except (EmptyPage, InvalidPage):
        page_obj = paginator.page(paginator.num_pages)

    # Build the query string:
    qstring = page_qstring(request)

    # Return OPDS Atom Feed:
    if qtype == "feed":
        catalog = generate_catalog(request, page_obj)
        return HttpResponse(catalog, mimetype="application/atom+xml")

    # Return HTML page:
    extra_context = dict(kwargs)
    extra_context.update(
        {
            "book_list": page_obj.object_list,
            "total_books": len(all_books),
            "q": q,
            "paginator": paginator,
            "page_obj": page_obj,
            "search_title": search_title,
            "search_author": search_author,
            "list_by": list_by,
            "qstring": qstring,
        }
    )
    return render_to_response("books/book_list.html", extra_context, context_instance=RequestContext(request))
Ejemplo n.º 3
0
 def advanced_search(self):
     tegs = simpledialog.askstring(title='Advanced Search', prompt='Enter Tegs: ')
     if tegs is None:
         return
     tegs = tegs.split(' ')
     images = s.advanced_search(tegs)
     count = str(len(images))
     if tegs is None:
         return
     self.root.title("DVP  " + "Search: " + str(tegs) + ' : ' + count)
     if tegs[0] == '':
         self.root.title("DVP  " + "Search without tegs" + ' : ' + count)
     self.refresh_images(images)
Ejemplo n.º 4
0
def _book_list(request, queryset, qtype=None, list_by='latest', **kwargs):
    """
    Filter the books, paginate the result, and return either a HTML
    book list, or a atom+xml OPDS catalog.
    
    """
    q = request.GET.get('q')
    search_all = request.GET.get('search-all') == 'on'
    search_title = request.GET.get('search-title') == 'on'
    search_author = request.GET.get('search-author') == 'on'
    
    context_instance = RequestContext(request)
    user = resolve_variable('user', context_instance)
    if not user.is_authenticated():
        queryset = queryset.filter(a_status = BOOK_PUBLISHED)

    published_books = Book.objects.filter(a_status = BOOK_PUBLISHED)
    unpublished_books = Book.objects.exclude(a_status = BOOK_PUBLISHED)

    # If no search options are specified, assumes search all, the
    # advanced search will be used:
    if not search_all and not search_title and not search_author:
        search_all = True
    
    # If search queried, modify the queryset with the result of the
    # search:
    if q is not None:
        if search_all:
            queryset = advanced_search(queryset, q)
        else:
            queryset = simple_search(queryset, q,
                                     search_title, search_author)
    
    paginator = Paginator(queryset, BOOKS_PER_PAGE)
    page = int(request.GET.get('page', '1'))
    
    try:
        page_obj = paginator.page(page)
    except (EmptyPage, InvalidPage):
        page_obj = paginator.page(paginator.num_pages)
    
    # Build the query string:
    qstring = page_qstring(request)
    
    # Return OPDS Atom Feed:
    if qtype == 'feed':
        catalog = generate_catalog(request, page_obj)
        return HttpResponse(catalog, mimetype='application/atom+xml')
    
    # Return HTML page:
    extra_context = dict(kwargs)
    extra_context.update({
        'book_list': page_obj.object_list,
        'published_books': len(published_books),
        'unpublished_books': len(unpublished_books),
        'q': q,
        'paginator': paginator,
        'page_obj': page_obj,
        'search_title': search_title,
        'search_author': search_author, 'list_by': list_by,
        'qstring': qstring,
    })
    return render_to_response(
        'books/book_list.html',
        extra_context,
        context_instance = RequestContext(request),
    )
Ejemplo n.º 5
0
def _book_list(request, queryset, qtype=None, list_by='latest', **kwargs):
    """
    Filter the books, paginate the result, and return either a HTML
    book list, or a atom+xml OPDS catalog.

    """
    q = request.GET.get('q')
    search_all = request.GET.get('search-all') == 'on'
    search_title = request.GET.get('search-title') == 'on'
    search_author = request.GET.get('search-author') == 'on'

    context_instance = RequestContext(request)
    user = resolve_variable('user', context_instance)
    if not user.is_authenticated():
        queryset = queryset.filter(a_status=BOOK_PUBLISHED)

    published_books_count = Book.objects.filter(
        a_status=BOOK_PUBLISHED).count()
    unpublished_books_count = Book.objects.exclude(
        a_status=BOOK_PUBLISHED).count()

    # If no search options are specified, assumes search all, the
    # advanced search will be used:
    if not search_all and not search_title and not search_author:
        search_all = True

    # If search queried, modify the queryset with the result of the
    # search:
    if q is not None:
        if search_all:
            queryset = advanced_search(queryset, q)
        else:
            queryset = simple_search(queryset, q, search_title, search_author)

    paginator = Paginator(queryset, BOOKS_PER_PAGE)
    page = int(request.GET.get('page', '1'))

    try:
        page_obj = paginator.page(page)
    except (EmptyPage, InvalidPage):
        page_obj = paginator.page(paginator.num_pages)

    # Build the query string:
    qstring = page_qstring(request)

    # Return OPDS Atom Feed:
    if qtype == 'feed':
        catalog = generate_catalog(request, page_obj)
        return HttpResponse(catalog, mimetype='application/atom+xml')

    # Return HTML page:
    extra_context = dict(kwargs)
    extra_context.update({
        'book_list':
        page_obj.object_list,
        'published_books':
        published_books_count,
        'unpublished_books':
        unpublished_books_count,
        'q':
        q,
        'paginator':
        paginator,
        'page_obj':
        page_obj,
        'search_title':
        search_title,
        'search_author':
        search_author,
        'list_by':
        list_by,
        'qstring':
        qstring,
        'allow_public_add_book':
        settings.ALLOW_PUBLIC_ADD_BOOKS
    })
    return render_to_response(
        'books/book_list.html',
        extra_context,
        context_instance=RequestContext(request),
    )
Ejemplo n.º 6
0
def _book_list(request, queryset, qtype=None, list_by='latest', **kwargs):
    """
    Filter the books, paginate the result, and return either a HTML
    book list, or a atom+xml OPDS catalog.
    """
    q = request.GET.get('q')
    search_all = request.GET.get('search-all') == 'on'
    search_title = request.GET.get('search-title') == 'on'
    search_author = request.GET.get('search-author') == 'on'

    if not request.user.is_authenticated():
        queryset = queryset.filter(a_status=settings.BOOK_PUBLISHED)

    published_count = Book.objects.\
        filter(a_status=settings.BOOK_PUBLISHED).count()
    unpublished_count = Book.objects.\
        exclude(a_status=settings.BOOK_PUBLISHED).count()

    # If no search options are specified, assumes search all, the
    # advanced search will be used:
    if not search_all and not search_title and not search_author:
        search_all = True

    # If search queried, modify the queryset with the result of the
    # search:
    if q is not None:
        if search_all:
            queryset = advanced_search(queryset, q)
        else:
            queryset = simple_search(queryset, q,
                                     search_title, search_author)

    paginator = Paginator(queryset, settings.BOOKS_PER_PAGE)
    page = int(request.GET.get('page', '1'))

    try:
        page_obj = paginator.page(page)
    except (EmptyPage, InvalidPage):
        page_obj = paginator.page(paginator.num_pages)

    # Build the query string:
    qstring = page_qstring(request)

    # Return OPDS Atom Feed:
    if qtype == 'feed':
        catalog = generate_catalog(request, page_obj)
        return HttpResponse(catalog, content_type='application/atom+xml')

    # Return HTML page:
    extra_context = dict(kwargs)
    extra_context.update({
        'book_list': page_obj.object_list,
        'published_books': published_count,
        'unpublished_books': unpublished_count,
        'q': q,
        'paginator': paginator,
        'page_obj': page_obj,
        'search_title': search_title,
        'search_author': search_author, 'list_by': list_by,
        'qstring': qstring,
        'allow_public_add_book': settings.ALLOW_PUBLIC_ADD_BOOKS,
        'allow_user_comments': settings.ALLOW_USER_COMMENTS,
    })

    return render(request, 'books/book_list.html', extra_context)