##// END OF EJS Templates
Use GET parameter to specify a page instead of different url reversers
neko259 -
r1204:8aa0d86b default
parent child Browse files
Show More
@@ -153,9 +153,9 b''
153 {% endifequal %}
153 {% endifequal %}
154 href="
154 href="
155 {% if tag %}
155 {% if tag %}
156 {% url "tag" tag_name=tag.name page=page %}
156 {% url "tag" tag_name=tag.name %}?page={{ page }}
157 {% else %}
157 {% else %}
158 {% url "index" page=page %}
158 {% url "index" %}?page={{ page }}
159 {% endif %}
159 {% endif %}
160 ">{{ page }}</a>
160 ">{{ page }}</a>
161 {% if not forloop.last %},{% endif %}
161 {% if not forloop.last %},{% endif %}
@@ -61,9 +61,7 b''
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="
64 href="{% url "feed" %}?page={{ page }}">{{ page }}</a>
65 {% url "feed" page=page %}
66 ">{{ page }}</a>
67 {% if not forloop.last %},{% endif %}
65 {% if not forloop.last %},{% endif %}
68 {% endfor %}
66 {% endfor %}
69 {% endwith %}
67 {% endwith %}
@@ -19,16 +19,10 b' js_info_dict = {'
19 urlpatterns = patterns('',
19 urlpatterns = patterns('',
20 # /boards/
20 # /boards/
21 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
21 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
22 # /boards/page/
23 url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(),
24 name='index'),
25
22
26 # /boards/tag/tag_name/
23 # /boards/tag/tag_name/
27 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
24 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
28 name='tag'),
25 name='tag'),
29 # /boards/tag/tag_id/page/
30 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$',
31 tag_threads.TagView.as_view(), name='tag'),
32
26
33 # /boards/thread/
27 # /boards/thread/
34 url(r'^thread/(?P<post_id>\d+)/$', views.thread.NormalThreadView.as_view(),
28 url(r'^thread/(?P<post_id>\d+)/$', views.thread.NormalThreadView.as_view(),
@@ -39,8 +33,6 b" urlpatterns = patterns('',"
39 name='thread_tree'),
33 name='thread_tree'),
40 # /feed/
34 # /feed/
41 url(r'^feed/$', views.feed.FeedView.as_view(), name='feed'),
35 url(r'^feed/$', views.feed.FeedView.as_view(), name='feed'),
42 url(r'^feed/page/(?P<page>\w+)/$', views.feed.FeedView.as_view(),
43 name='feed'),
44
36
45 url(r'^settings/$', settings.SettingsView.as_view(), name='settings'),
37 url(r'^settings/$', settings.SettingsView.as_view(), name='settings'),
46 url(r'^tags/(?P<query>\w+)?/?$', all_tags.AllTagsView.as_view(), name='tags'),
38 url(r'^tags/(?P<query>\w+)?/?$', all_tags.AllTagsView.as_view(), name='tags'),
@@ -43,7 +43,9 b' class AllThreadsView(PostMixin, BaseBoar'
43 self.settings_manager = None
43 self.settings_manager = None
44 super(AllThreadsView, self).__init__()
44 super(AllThreadsView, self).__init__()
45
45
46 def get(self, request, page=DEFAULT_PAGE, form: ThreadForm=None):
46 def get(self, request, form: ThreadForm=None):
47 page = request.GET.get('page', DEFAULT_PAGE)
48
47 params = self.get_context_data(request=request)
49 params = self.get_context_data(request=request)
48
50
49 if not form:
51 if not form:
@@ -67,7 +69,7 b' class AllThreadsView(PostMixin, BaseBoar'
67
69
68 return render(request, TEMPLATE, params)
70 return render(request, TEMPLATE, params)
69
71
70 def post(self, request, page=DEFAULT_PAGE):
72 def post(self, request):
71 form = ThreadForm(request.POST, request.FILES,
73 form = ThreadForm(request.POST, request.FILES,
72 error_class=PlainErrorList)
74 error_class=PlainErrorList)
73 form.session = request.session
75 form.session = request.session
@@ -78,7 +80,7 b' class AllThreadsView(PostMixin, BaseBoar'
78 # Ban user because he is suspected to be a bot
80 # Ban user because he is suspected to be a bot
79 self._ban_current_user(request)
81 self._ban_current_user(request)
80
82
81 return self.get(request, page, form)
83 return self.get(request, form)
82
84
83 def get_page_context(self, paginator, params, page):
85 def get_page_context(self, paginator, params, page):
84 """
86 """
@@ -95,14 +97,12 b' class AllThreadsView(PostMixin, BaseBoar'
95 params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
97 params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
96
98
97 def get_previous_page_link(self, current_page):
99 def get_previous_page_link(self, current_page):
98 return reverse('index', kwargs={
100 return reverse('index') + '?page=' \
99 'page': current_page.previous_page_number(),
101 + str(current_page.previous_page_number())
100 })
101
102
102 def get_next_page_link(self, current_page):
103 def get_next_page_link(self, current_page):
103 return reverse('index', kwargs={
104 return reverse('index') + '?page=' \
104 'page': current_page.next_page_number(),
105 + str(current_page.next_page_number())
105 })
106
106
107 @staticmethod
107 @staticmethod
108 def parse_tags_string(tag_strings):
108 def parse_tags_string(tag_strings):
@@ -28,7 +28,9 b' DEFAULT_PAGE = 1'
28
28
29 class FeedView(PostMixin, BaseBoardView):
29 class FeedView(PostMixin, BaseBoardView):
30
30
31 def get(self, request, page=DEFAULT_PAGE):
31 def get(self, request):
32 page = request.GET.get('page', DEFAULT_PAGE)
33
32 params = self.get_context_data(request=request)
34 params = self.get_context_data(request=request)
33
35
34 settings_manager = get_settings_manager(request)
36 settings_manager = get_settings_manager(request)
@@ -61,11 +63,9 b' class FeedView(PostMixin, BaseBoardView)'
61 params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
63 params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
62
64
63 def get_previous_page_link(self, current_page):
65 def get_previous_page_link(self, current_page):
64 return reverse('feed', kwargs={
66 return reverse('feed') + '?page={}'.format(
65 'page': current_page.previous_page_number(),
67 current_page.previous_page_number())
66 })
67
68
68 def get_next_page_link(self, current_page):
69 def get_next_page_link(self, current_page):
69 return reverse('feed', kwargs={
70 return reverse('feed') + '?page={}'.format(
70 'page': current_page.next_page_number(),
71 current_page.next_page_number())
71 })
@@ -52,22 +52,20 b' class TagView(AllThreadsView, Dispatcher'
52 def get_previous_page_link(self, current_page):
52 def get_previous_page_link(self, current_page):
53 return reverse('tag', kwargs={
53 return reverse('tag', kwargs={
54 'tag_name': self.tag_name,
54 'tag_name': self.tag_name,
55 'page': current_page.previous_page_number(),
55 }) + '?page=' + str(current_page.previous_page_number())
56 })
57
56
58 def get_next_page_link(self, current_page):
57 def get_next_page_link(self, current_page):
59 return reverse('tag', kwargs={
58 return reverse('tag', kwargs={
60 'tag_name': self.tag_name,
59 'tag_name': self.tag_name,
61 'page': current_page.next_page_number(),
60 }) + '?page=' + str(current_page.next_page_number())
62 })
63
61
64 def get(self, request, tag_name, page=DEFAULT_PAGE, form=None):
62 def get(self, request, tag_name, form=None):
65 self.tag_name = tag_name
63 self.tag_name = tag_name
66
64
67 return super(TagView, self).get(request, page, form)
65 return super(TagView, self).get(request, form)
68
66
69
67
70 def post(self, request, tag_name, page=DEFAULT_PAGE):
68 def post(self, request, tag_name):
71 self.tag_name = tag_name
69 self.tag_name = tag_name
72
70
73 if 'method' in request.POST:
71 if 'method' in request.POST:
General Comments 0
You need to be logged in to leave comments. Login now