Archived
1
0

update page logic, don't use queries for page numbers

This commit is contained in:
Jeff Becker 2016-11-07 09:03:11 -05:00
parent 84092c979f
commit 670f613596
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
2 changed files with 8 additions and 8 deletions

View File

@ -8,7 +8,8 @@ urlpatterns = [
url(r'^overchan\.(?P<name>[a-zA-Z0-9\.]+)-(?P<page>[0-9]+)\.html$', views.BoardView.as_view(), name='old-board'),
url(r'^overchan\.(?P<name>[a-zA-Z0-9\.]+)/', views.BoardView.as_view(), name='board-alt'),
url(r'^thread-(?P<op>[a-fA-F0-9\.]{40})\.html$', views.ThreadView.as_view(), name='old-thread'),
url(r'^b/(?P<name>[a-zA-Z0-9\.]+[a-zA-Z0-9])/$', views.BoardView.as_view(), name='board'),
url(r'^b/(?P<name>[a-zA-Z0-9\.]+[a-zA-Z0-9])/$', views.BoardView.as_view(), name='board-front'),
url(r'^b/(?P<name>[a-zA-Z0-9\.]+[a-zA-Z0-9])/(?P<page>[0-9]+)/$', views.BoardView.as_view(), name='board'),
url(r'^t/(?P<op>[a-fA-F0-9\.]{40})/$', views.ThreadView.as_view(), name='thread'),
url(r'captcha.png', views.create_captcha, name='captcha'),
url(r'^$', views.FrontPageView.as_view(), name='index'),

View File

@ -62,10 +62,7 @@ class BoardView(generic.View, Postable):
return util.createPost(name, None, request.POST, request.FILES)
def get(self, request, name):
page = 0
if 'p' in request.GET:
page = request.GET['p']
def get(self, request, name, page="0"):
newsgroup = 'overchan.{}'.format(name)
try:
page = int(page or "0")
@ -83,9 +80,11 @@ class BoardView(generic.View, Postable):
roots = self.model.objects.filter(newsgroup=group, reference='').order_by('-last_bumped')[begin:end]
ctx = self.context_for_get(request, {'threads': roots, 'page': page, 'name': newsgroup, 'button': 'new thread'})
if page < group.max_pages:
ctx['nextpage'] = reverse('board', args=[name]) + '?p={}'.format(page + 1)
if page > 0:
ctx['prevpage'] = reverse('board', args=[name]) + '?p={}'.format(page - 1)
ctx['nextpage'] = reverse('board', args=[name, page + 1])
if page == 1:
ctx['prevpage'] = reverse('board-front', args=[name])
if page > 1:
ctx['prevpage'] = reverse('board', args=[name, page - 1])
return render(request, self.template_name, ctx)
class ThreadView(generic.View, Postable):