##// END OF EJS Templates
Made feed view use the new-style paginator links
neko259 -
r1378:2ac2fd63 default
parent child Browse files
Show More
@@ -1,71 +1,71 b''
1 1 {% extends "boards/base.html" %}
2 2
3 3 {% load i18n %}
4 4 {% load board %}
5 5 {% load static %}
6 6 {% load tz %}
7 7
8 8 {% block head %}
9 9 <meta name="robots" content="noindex">
10 10
11 11 <title>{{ site_name }} - {% trans "feed" %}</title>
12 12
13 13 {% if prev_page_link %}
14 14 <link rel="prev" href="{{ prev_page_link }}" />
15 15 {% endif %}
16 16 {% if next_page_link %}
17 17 <link rel="next" href="{{ next_page_link }}" />
18 18 {% endif %}
19 19
20 20 {% endblock %}
21 21
22 22 {% block content %}
23 23
24 24 {% get_current_language as LANGUAGE_CODE %}
25 25 {% get_current_timezone as TIME_ZONE %}
26 26
27 27 {% if posts %}
28 28 {% if prev_page_link %}
29 29 <div class="page_link">
30 30 <a href="{{ prev_page_link }}">{% trans "Previous page" %}</a>
31 31 </div>
32 32 {% endif %}
33 33
34 34 {% for post in posts %}
35 35 {% post_view post moderator=moderator truncated=True need_op_data=True %}
36 36 {% endfor %}
37 37
38 38 {% if next_page_link %}
39 39 <div class="page_link">
40 40 <a href="{{ next_page_link }}">{% trans "Next page" %}</a>
41 41 </div>
42 42 {% endif %}
43 43 {% else %}
44 44 <div class="post">
45 45 {% trans 'No posts exist. Create the first one!' %}</div>
46 46 {% endif %}
47 47 {% endblock %}
48 48
49 49 {% block metapanel %}
50 50
51 51 <span class="metapanel">
52 52 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
53 53 {% trans "Pages:" %}
54 54 [
55 55 {% with dividers=paginator.get_dividers %}
56 56 {% for page in paginator.get_divided_range %}
57 57 {% if page in dividers %}
58 58 …,
59 59 {% endif %}
60 60 <a
61 61 {% ifequal page current_page.number %}
62 62 class="current_page"
63 63 {% endifequal %}
64 href="{% url "feed" %}?page={{ page }}{{ additional_attrs }}">{{ page }}</a>
64 href="{% page_url paginator page %}">{{ page }}</a>
65 65 {% if not forloop.last %},{% endif %}
66 66 {% endfor %}
67 67 {% endwith %}
68 68 ]
69 69 </span>
70 70
71 71 {% endblock %}
@@ -1,81 +1,71 b''
1 1 from django.core.urlresolvers import reverse
2 2 from django.shortcuts import render
3 3
4 4 from boards.abstracts.paginator import get_paginator
5 5 from boards.abstracts.settingsmanager import get_settings_manager
6 6 from boards.models import Post
7 7 from boards.views.base import BaseBoardView
8 8 from boards.views.posting_mixin import PostMixin
9 9
10 10 POSTS_PER_PAGE = 10
11 11
12 12 PARAMETER_CURRENT_PAGE = 'current_page'
13 13 PARAMETER_PAGINATOR = 'paginator'
14 14 PARAMETER_POSTS = 'posts'
15 15 PARAMETER_ADDITONAL_ATTRS = 'additional_attrs'
16 16
17 17 PARAMETER_PREV_LINK = 'prev_page_link'
18 18 PARAMETER_NEXT_LINK = 'next_page_link'
19 19
20 20 TEMPLATE = 'boards/feed.html'
21 21 DEFAULT_PAGE = 1
22 22
23 23
24 24 class FeedView(PostMixin, BaseBoardView):
25 25
26 26 def get(self, request):
27 27 page = request.GET.get('page', DEFAULT_PAGE)
28 28 tripcode = request.GET.get('tripcode', None)
29 29
30 30 params = self.get_context_data(request=request)
31 31
32 32 settings_manager = get_settings_manager(request)
33 33
34 34 posts = Post.objects.exclude(
35 35 threads__tags__in=settings_manager.get_hidden_tags()).order_by(
36 36 '-pub_time').prefetch_related('images', 'thread', 'threads')
37 37 if tripcode:
38 38 posts = posts.filter(tripcode=tripcode)
39 39
40 40 paginator = get_paginator(posts, POSTS_PER_PAGE)
41 41 paginator.current_page = int(page)
42 42
43 43 params[PARAMETER_POSTS] = paginator.page(page).object_list
44 44
45 45 additional_params = dict()
46 46 if tripcode:
47 47 additional_params['tripcode'] = tripcode
48 48 params[PARAMETER_ADDITONAL_ATTRS] = '&tripcode=' + tripcode
49 49
50 self.get_page_context(paginator, params, page, additional_params)
50 paginator.set_url(reverse('feed'), request.GET.dict())
51
52 self.get_page_context(paginator, params, page)
51 53
52 54 return render(request, TEMPLATE, params)
53 55
54 56 # TODO Dedup this into PagedMixin
55 def get_page_context(self, paginator, params, page, additional_params):
57 def get_page_context(self, paginator, params, page):
56 58 """
57 59 Get pagination context variables
58 60 """
59 61
60 62 params[PARAMETER_PAGINATOR] = paginator
61 63 current_page = paginator.page(int(page))
62 64 params[PARAMETER_CURRENT_PAGE] = current_page
63 65 if current_page.has_previous():
64 params[PARAMETER_PREV_LINK] = self.get_previous_page_link(
65 current_page)
66 for param in additional_params.keys():
67 params[PARAMETER_PREV_LINK] += '&{}={}'.format(
68 param, additional_params[param])
66 params[PARAMETER_PREV_LINK] = paginator.get_page_url(
67 current_page.previous_page_number())
69 68 if current_page.has_next():
70 params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
71 for param in additional_params.keys():
72 params[PARAMETER_NEXT_LINK] += '&{}={}'.format(
73 param, additional_params[param])
69 params[PARAMETER_NEXT_LINK] = paginator.get_page_url(
70 current_page.next_page_number())
74 71
75 def get_previous_page_link(self, current_page):
76 return reverse('feed') + '?page={}'.format(
77 current_page.previous_page_number())
78
79 def get_next_page_link(self, current_page):
80 return reverse('feed') + '?page={}'.format(
81 current_page.next_page_number())
General Comments 0
You need to be logged in to leave comments. Login now