diff --git a/TODO b/TODO index 16fe68b..00e65bf 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ TODO ---- -* pagination not working in feed * tag cloud page * "by tag" menu item links to tag cloud page when no tag * since tags added, edit is broken in site (not in admin) diff --git a/books/opds.py b/books/opds.py index b17c190..86eb06a 100644 --- a/books/opds.py +++ b/books/opds.py @@ -27,22 +27,44 @@ def __get_mimetype(item): else: return 'Unknown' -def generate_catalog(page_obj, qstring, q=None): +def page_qstring(request, page_number=None): + """ + Return the query string for the URL. + + If page_number is given, modify the query for that page. + """ + qdict = dict(request.GET.items()) + if page_number is not None: + qdict['page'] = str(page_number) + + if len(qdict) > 0: + qstring = '?'+'&'.join(('%s=%s' % (k, v) for k, v in qdict.items())) + else: + qstring = '' + + return qstring + + +def generate_catalog(request, page_obj): attrs = {} attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/' attrs[u'xmlns:opds'] = u'http://opds-spec.org/' attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/' attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/' - + links = [] - + if page_obj.has_previous(): + previous_page = page_obj.previous_page_number() links.append({'title': 'Previous results', 'type': 'application/atom+xml', - 'rel': 'previous','href': qstring}) - + 'rel': 'previous', + 'href': page_qstring(request, previous_page)}) + if page_obj.has_next(): + next_page = page_obj.next_page_number() links.append({'title': 'Next results', 'type': 'application/atom+xml', - 'rel': 'next', 'href': qstring}) + 'rel': 'next', + 'href': page_qstring(request, next_page)}) feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \ atom_id = 'pathagar:full-catalog', subtitle = \ diff --git a/books/views.py b/books/views.py index acce687..0a2d95f 100644 --- a/books/views.py +++ b/books/views.py @@ -37,7 +37,7 @@ from langlist import langs as LANG_CHOICES from models import * from popuphandler import handlePopAdd -from opds import generate_catalog +from opds import page_qstring, generate_catalog @login_required def add_language(request): @@ -79,9 +79,13 @@ def _book_list(request, queryset, qtype=None, list_by='latest', **kwargs): 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) @@ -100,14 +104,11 @@ def _book_list(request, queryset, qtype=None, list_by='latest', **kwargs): page_obj = paginator.page(paginator.num_pages) # Build the query string: - if len(request.GET) > 0: - qstring = '?'+'&'.join(('%s=%s' % (k, v) for k, v in request.GET.items())) - else: - qstring = '' + qstring = page_qstring(request) # Return OPDS Atom Feed: if qtype == 'feed': - catalog = generate_catalog(page_obj, qstring, q) + catalog = generate_catalog(request, page_obj) return HttpResponse(catalog, mimetype='application/atom+xml') # Return HTML page: