コード例 #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),
    )
コード例 #2
0
ファイル: views.py プロジェクト: mapmeld/pathagar
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))
コード例 #3
0
ファイル: catalog.py プロジェクト: elsamartino/pathagar
def get_catalog(request, qtype='feed'):
    q = None
    q_objects = []
    results = Book.objects.all()
    try:
        q = request.GET['q']
    except:
        pass
    else:
        searchterms = request.GET['q']
        subterms = searchterms.split('AND')
        for subterm in subterms:
            if ':' in subterm:
                key, word = subterm.split(':')
                key = key.strip()
                if key == 'title':
                    q_objects.append(Q(a_title__icontains = word))
                if key == 'author':
                    q_objects.append(Q(a_author__icontains = word))
                if key == 'publisher':
                    q_objects.append(Q(dc_publisher__icontains = word))
                if key == 'identifier':
                    q_objects.append(Q(dc_identifier__icontains = word))
                if key == 'summary':
                    q_objects.append(Q(a_summary__icontains = word))
            else:
                word = subterm
                try:
                    results = results.filter(Q(a_title__icontains = word) | \
                        Q(a_author__icontains = word) | \
                        Q(dc_publisher__icontains = word) | \
                        Q(dc_identifier__icontains = word) | \
                        Q(a_summary__icontains = word))
                except Book.DoesNotExist:
                    results = Book.objects.none()

        for q_object in q_objects:
            results = results.filter(q_object)


    paginator = Paginator(results, settings.ITEMS_PER_PAGE)
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

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

    if qtype == 'feed':
        return generate_catalog(books, q)

    return (books, q)
コード例 #4
0
ファイル: views.py プロジェクト: manuq/pathagar
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),
    )
コード例 #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),
    )
コード例 #6
0
ファイル: views.py プロジェクト: aristippe/pathagar
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)