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