##// END OF EJS Templates
Moved pagination related stuff to the mixin
neko259 -
r1854:b4c06973 default
parent child Browse files
Show More
@@ -89,7 +89,7 b' class AllThreadsView(PostMixin, FileUplo'
89 params[PARAMETER_MAX_FILES] = settings.get_int('Forms', 'MaxFileCount')
89 params[PARAMETER_MAX_FILES] = settings.get_int('Forms', 'MaxFileCount')
90
90
91 paginator.set_url(self.get_reverse_url(), request.GET.dict())
91 paginator.set_url(self.get_reverse_url(), request.GET.dict())
92 self.get_page_context(paginator, params, page)
92 params.update(self.get_page_context(paginator, page))
93
93
94 return render(request, TEMPLATE, params)
94 return render(request, TEMPLATE, params)
95
95
@@ -112,16 +112,6 b' class AllThreadsView(PostMixin, FileUplo'
112
112
113 return self.get(request, form)
113 return self.get(request, form)
114
114
115 def get_page_context(self, paginator, params, page):
116 """
117 Get pagination context variables
118 """
119
120 params[PARAMETER_PAGINATOR] = paginator
121 current_page = paginator.page(int(page))
122 params[PARAMETER_CURRENT_PAGE] = current_page
123 self.set_page_urls(paginator, params)
124
125 def get_reverse_url(self):
115 def get_reverse_url(self):
126 return reverse('index')
116 return reverse('index')
127
117
@@ -7,17 +7,13 b' from boards.abstracts.settingsmanager im'
7 from boards.models import Post
7 from boards.models import Post
8 from boards.views.base import BaseBoardView
8 from boards.views.base import BaseBoardView
9 from boards.views.posting_mixin import PostMixin
9 from boards.views.posting_mixin import PostMixin
10 from boards.views.mixins import PaginatedMixin
10
11
11 POSTS_PER_PAGE = settings.get_int('View', 'PostsPerPage')
12 POSTS_PER_PAGE = settings.get_int('View', 'PostsPerPage')
12
13
13 PARAMETER_CURRENT_PAGE = 'current_page'
14 PARAMETER_PAGINATOR = 'paginator'
15 PARAMETER_POSTS = 'posts'
14 PARAMETER_POSTS = 'posts'
16 PARAMETER_QUERIES = 'queries'
15 PARAMETER_QUERIES = 'queries'
17
16
18 PARAMETER_PREV_LINK = 'prev_page_link'
19 PARAMETER_NEXT_LINK = 'next_page_link'
20
21 TEMPLATE = 'boards/feed.html'
17 TEMPLATE = 'boards/feed.html'
22 DEFAULT_PAGE = 1
18 DEFAULT_PAGE = 1
23
19
@@ -96,7 +92,7 b' class ImageFilter(FeedFilter):'
96 return 'File: {}'.format(image)
92 return 'File: {}'.format(image)
97
93
98
94
99 class FeedView(PostMixin, BaseBoardView):
95 class FeedView(PostMixin, PaginatedMixin, BaseBoardView):
100 filters = (
96 filters = (
101 TripcodeFilter,
97 TripcodeFilter,
102 FavoritesFilter,
98 FavoritesFilter,
@@ -129,23 +125,7 b' class FeedView(PostMixin, BaseBoardView)'
129
125
130 paginator.set_url(reverse('feed'), request.GET.dict())
126 paginator.set_url(reverse('feed'), request.GET.dict())
131
127
132 self.get_page_context(paginator, params, page)
128 params.update(self.get_page_context(paginator, page))
133
129
134 return render(request, TEMPLATE, params)
130 return render(request, TEMPLATE, params)
135
131
136 # TODO Dedup this into PagedMixin
137 def get_page_context(self, paginator, params, page):
138 """
139 Get pagination context variables
140 """
141
142 params[PARAMETER_PAGINATOR] = paginator
143 current_page = paginator.page(int(page))
144 params[PARAMETER_CURRENT_PAGE] = current_page
145 if current_page.has_previous():
146 params[PARAMETER_PREV_LINK] = paginator.get_page_url(
147 current_page.previous_page_number())
148 if current_page.has_next():
149 params[PARAMETER_NEXT_LINK] = paginator.get_page_url(
150 current_page.next_page_number())
151
@@ -4,6 +4,11 b' import boards'
4 PARAM_NEXT = 'next'
4 PARAM_NEXT = 'next'
5 PARAMETER_METHOD = 'method'
5 PARAMETER_METHOD = 'method'
6
6
7 PARAMETER_CURRENT_PAGE = 'current_page'
8 PARAMETER_PAGINATOR = 'paginator'
9
10 PARAMETER_PREV_LINK = 'prev_page_link'
11 PARAMETER_NEXT_LINK = 'next_page_link'
7
12
8 class DispatcherMixin:
13 class DispatcherMixin:
9 """
14 """
@@ -35,6 +40,22 b' class FileUploadMixin:'
35
40
36
41
37 class PaginatedMixin:
42 class PaginatedMixin:
38 def set_page_urls(self, paginator, params):
43 def get_page_context(self, paginator, page):
39 params['prev_page_link'] = paginator.get_prev_page_url()
44 """
40 params['next_page_link'] = paginator.get_next_page_url()
45 Get pagination context variables
46 """
47
48 params = {}
49
50 params[PARAMETER_PAGINATOR] = paginator
51 current_page = paginator.page(int(page))
52 params[PARAMETER_CURRENT_PAGE] = current_page
53 if current_page.has_previous():
54 params[PARAMETER_PREV_LINK] = paginator.get_page_url(
55 current_page.previous_page_number())
56 if current_page.has_next():
57 params[PARAMETER_NEXT_LINK] = paginator.get_page_url(
58 current_page.next_page_number())
59
60 return params
61
General Comments 0
You need to be logged in to leave comments. Login now