# HG changeset patch # User neko259 # Date 2017-03-03 16:16:40 # Node ID 7fb52044f84e2b3b8ecf09be3734a4590f8bb27c # Parent fdc4df62493db052572453a91cd08cd0d4ce568f Simplified pagination templates. Added a list of pages to the search results page diff --git a/boards/templates/boards/all_threads.html b/boards/templates/boards/all_threads.html --- a/boards/templates/boards/all_threads.html +++ b/boards/templates/boards/all_threads.html @@ -1,4 +1,4 @@ -{% extends "boards/base.html" %} +{% extends "boards/paginated.html" %} {% load i18n %} {% load board %} diff --git a/boards/templates/boards/feed.html b/boards/templates/boards/feed.html --- a/boards/templates/boards/feed.html +++ b/boards/templates/boards/feed.html @@ -1,4 +1,4 @@ -{% extends "boards/base.html" %} +{% extends "boards/paginated.html" %} {% load i18n %} {% load board %} @@ -50,24 +50,3 @@ {% endif %} {% endblock %} -{% block metapanel %} - - - {% trans "Pages:" %} - [ - {% with dividers=paginator.get_dividers %} - {% for page in paginator.get_divided_range %} - {% if page in dividers %} - …, - {% endif %} - {{ page }}{% if not forloop.last %},{% endif %} - {% endfor %} - {% endwith %} - ] - - -{% endblock %} diff --git a/boards/templates/boards/paginated.html b/boards/templates/boards/paginated.html new file mode 100644 --- /dev/null +++ b/boards/templates/boards/paginated.html @@ -0,0 +1,26 @@ +{% extends 'boards/base.html' %} + +{% load i18n %} +{% load board %} + +{% block metapanel %} + + + {% trans "Pages:" %} + [ + {% with dividers=paginator.get_dividers %} + {% for page in paginator.get_divided_range %} + {% if page in dividers %} + …, + {% endif %} + {{ page }}{% if not forloop.last %},{% endif %} + {% endfor %} + {% endwith %} + ] + + +{% endblock %} diff --git a/boards/templates/search/search.html b/boards/templates/search/search.html --- a/boards/templates/search/search.html +++ b/boards/templates/search/search.html @@ -1,4 +1,4 @@ -{% extends 'boards/base.html' %} +{% extends 'boards/paginated.html' %} {% load board %} {% load i18n %} @@ -6,6 +6,13 @@ {% block head %} {% trans 'Search' %} - {{ site_name }} + + {% if prev_page_link %} + + {% endif %} + {% if next_page_link %} + + {% endif %} {% endblock %} {% block content %} @@ -20,23 +27,22 @@ - {% if page %} - {% if page.has_previous %} + {% if current_page %} + {% if prev_page_link %} {% endif %} - {% for result in page.object_list %} + {% for result in current_page.object_list %} {% post_view result truncated=True need_op_data=True %} {% endfor %} - {% if page.has_next %} + {% if next_page_link %} {% endif %} {% endif %} {% endblock %} + diff --git a/boards/views/search.py b/boards/views/search.py --- a/boards/views/search.py +++ b/boards/views/search.py @@ -1,10 +1,12 @@ from django.shortcuts import render from django.views.generic import View from django.db.models import Q +from django.core.urlresolvers import reverse from boards.abstracts.paginator import get_paginator from boards.forms import SearchForm, PlainErrorList from boards.models import Post +from boards.views.mixins import PaginatedMixin MIN_QUERY_LENGTH = 3 @@ -23,7 +25,7 @@ REQUEST_PAGE = 'page' TEMPLATE = 'search/search.html' -class BoardSearchView(View): +class BoardSearchView(View, PaginatedMixin): def get(self, request): params = dict() @@ -37,10 +39,11 @@ class BoardSearchView(View): | Q(title__icontains=query) | Q(opening=True, thread__tags__aliases__name__icontains=query)).order_by('-id').distinct() paginator = get_paginator(results, RESULTS_PER_PAGE) + paginator.set_url(reverse('search'), request.GET.dict()) page = int(request.GET.get(REQUEST_PAGE, '1')) - params[CONTEXT_PAGE] = paginator.page(page) params[CONTEXT_QUERY] = query + params.update(self.get_page_context(paginator, page)) return render(request, TEMPLATE, params)