##// END OF EJS Templates
Set previous and next page links in the thread list view instead of template
neko259 -
r1129:fb183582 default
parent child Browse files
Show More
@@ -14,23 +14,11 b''
14 <title>{{ site_name }}</title>
14 <title>{{ site_name }}</title>
15 {% endif %}
15 {% endif %}
16
16
17 {% if current_page.has_previous %}
17 {% if prev_page_link %}
18 <link rel="prev" href="
18 <link rel="prev" href="{{ prev_page_link }}" />
19 {% if tag %}
20 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
21 {% else %}
22 {% url "index" page=current_page.previous_page_number %}
23 {% endif %}
24 " />
25 {% endif %}
19 {% endif %}
26 {% if current_page.has_next %}
20 {% if next_page_link %}
27 <link rel="next" href="
21 <link rel="next" href="{{ next_page_link }}" />
28 {% if tag %}
29 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
30 {% else %}
31 {% url "index" page=current_page.next_page_number %}
32 {% endif %}
33 " />
34 {% endif %}
22 {% endif %}
35
23
36 {% endblock %}
24 {% endblock %}
@@ -69,15 +57,9 b''
69 {% endif %}
57 {% endif %}
70
58
71 {% if threads %}
59 {% if threads %}
72 {% if current_page.has_previous %}
60 {% if prev_page_link %}
73 <div class="page_link">
61 <div class="page_link">
74 <a href="
62 <a href="{{ prev_page_link }}">{% trans "Previous page" %}</a>
75 {% if tag %}
76 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
77 {% else %}
78 {% url "index" page=current_page.previous_page_number %}
79 {% endif %}
80 ">{% trans "Previous page" %}</a>
81 </div>
63 </div>
82 {% endif %}
64 {% endif %}
83
65
@@ -107,15 +89,9 b''
107 </div>
89 </div>
108 {% endfor %}
90 {% endfor %}
109
91
110 {% if current_page.has_next %}
92 {% if next_page_link %}
111 <div class="page_link">
93 <div class="page_link">
112 <a href="
94 <a href="{{ next_page_link }}">{% trans "Next page" %}</a>
113 {% if tag %}
114 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
115 {% else %}
116 {% url "index" page=current_page.next_page_number %}
117 {% endif %}
118 ">{% trans "Next page" %}</a>
119 </div>
95 </div>
120 {% endif %}
96 {% endif %}
121 {% else %}
97 {% else %}
@@ -1,3 +1,4 b''
1 from django.core.urlresolvers import reverse
1 from django.core.files import File
2 from django.core.files import File
2 from django.core.files.temp import NamedTemporaryFile
3 from django.core.files.temp import NamedTemporaryFile
3 from django.core.paginator import EmptyPage
4 from django.core.paginator import EmptyPage
@@ -28,6 +29,9 b" PARAMETER_CURRENT_PAGE = 'current_page'"
28 PARAMETER_PAGINATOR = 'paginator'
29 PARAMETER_PAGINATOR = 'paginator'
29 PARAMETER_THREADS = 'threads'
30 PARAMETER_THREADS = 'threads'
30
31
32 PARAMETER_PREV_LINK = 'prev_page_link'
33 PARAMETER_NEXT_LINK = 'next_page_link'
34
31 TEMPLATE = 'boards/posting_general.html'
35 TEMPLATE = 'boards/posting_general.html'
32 DEFAULT_PAGE = 1
36 DEFAULT_PAGE = 1
33
37
@@ -57,7 +61,7 b' class AllThreadsView(PostMixin, BaseBoar'
57 params[PARAMETER_THREADS] = threads
61 params[PARAMETER_THREADS] = threads
58 params[CONTEXT_FORM] = form
62 params[CONTEXT_FORM] = form
59
63
60 self._get_page_context(paginator, params, page)
64 self.get_page_context(paginator, params, page)
61
65
62 return render(request, TEMPLATE, params)
66 return render(request, TEMPLATE, params)
63
67
@@ -74,13 +78,29 b' class AllThreadsView(PostMixin, BaseBoar'
74
78
75 return self.get(request, page, form)
79 return self.get(request, page, form)
76
80
77 def _get_page_context(self, paginator, params, page):
81 def get_page_context(self, paginator, params, page):
78 """
82 """
79 Get pagination context variables
83 Get pagination context variables
80 """
84 """
81
85
82 params[PARAMETER_PAGINATOR] = paginator
86 params[PARAMETER_PAGINATOR] = paginator
83 params[PARAMETER_CURRENT_PAGE] = paginator.page(int(page))
87 current_page = paginator.page(int(page))
88 params[PARAMETER_CURRENT_PAGE] = current_page
89 if current_page.has_previous():
90 params[PARAMETER_PREV_LINK] = self.get_previous_page_link(
91 current_page)
92 if current_page.has_next():
93 params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
94
95 def get_previous_page_link(self, current_page):
96 return reverse('index', kwargs={
97 'page': current_page.previous_page_number(),
98 })
99
100 def get_next_page_link(self, current_page):
101 return reverse('index', kwargs={
102 'page': current_page.next_page_number(),
103 })
84
104
85 @staticmethod
105 @staticmethod
86 def parse_tags_string(tag_strings):
106 def parse_tags_string(tag_strings):
@@ -1,4 +1,5 b''
1 from django.shortcuts import get_object_or_404, redirect
1 from django.shortcuts import get_object_or_404, redirect
2 from django.core.urlresolvers import reverse
2
3
3 from boards.abstracts.settingsmanager import get_settings_manager, \
4 from boards.abstracts.settingsmanager import get_settings_manager, \
4 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
5 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
@@ -48,6 +49,18 b' class TagView(AllThreadsView, Dispatcher'
48
49
49 return params
50 return params
50
51
52 def get_previous_page_link(self, current_page):
53 return reverse('tag', kwargs={
54 'tag_name': self.tag_name,
55 'page': current_page.previous_page_number(),
56 })
57
58 def get_next_page_link(self, current_page):
59 return reverse('tag', kwargs={
60 'tag_name': self.tag_name,
61 'page': current_page.next_page_number(),
62 })
63
51 def get(self, request, tag_name, page=DEFAULT_PAGE, form=None):
64 def get(self, request, tag_name, page=DEFAULT_PAGE, form=None):
52 self.tag_name = tag_name
65 self.tag_name = tag_name
53
66
General Comments 0
You need to be logged in to leave comments. Login now