update page logic, don't use queries for page numbers
This commit is contained in:
parent
84092c979f
commit
670f613596
@ -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\.]+)-(?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'^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'^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'^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'captcha.png', views.create_captcha, name='captcha'),
|
||||||
url(r'^$', views.FrontPageView.as_view(), name='index'),
|
url(r'^$', views.FrontPageView.as_view(), name='index'),
|
||||||
|
@ -62,10 +62,7 @@ class BoardView(generic.View, Postable):
|
|||||||
return util.createPost(name, None, request.POST, request.FILES)
|
return util.createPost(name, None, request.POST, request.FILES)
|
||||||
|
|
||||||
|
|
||||||
def get(self, request, name):
|
def get(self, request, name, page="0"):
|
||||||
page = 0
|
|
||||||
if 'p' in request.GET:
|
|
||||||
page = request.GET['p']
|
|
||||||
newsgroup = 'overchan.{}'.format(name)
|
newsgroup = 'overchan.{}'.format(name)
|
||||||
try:
|
try:
|
||||||
page = int(page or "0")
|
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]
|
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'})
|
ctx = self.context_for_get(request, {'threads': roots, 'page': page, 'name': newsgroup, 'button': 'new thread'})
|
||||||
if page < group.max_pages:
|
if page < group.max_pages:
|
||||||
ctx['nextpage'] = reverse('board', args=[name]) + '?p={}'.format(page + 1)
|
ctx['nextpage'] = reverse('board', args=[name, page + 1])
|
||||||
if page > 0:
|
if page == 1:
|
||||||
ctx['prevpage'] = reverse('board', args=[name]) + '?p={}'.format(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)
|
return render(request, self.template_name, ctx)
|
||||||
|
|
||||||
class ThreadView(generic.View, Postable):
|
class ThreadView(generic.View, Postable):
|
||||||
|
Reference in New Issue
Block a user