diff --git a/contrib/frontends/django/nntpchan/nntpchan/frontend/urls.py b/contrib/frontends/django/nntpchan/nntpchan/frontend/urls.py index ea5e5b1..166e0ea 100644 --- a/contrib/frontends/django/nntpchan/nntpchan/frontend/urls.py +++ b/contrib/frontends/django/nntpchan/nntpchan/frontend/urls.py @@ -6,7 +6,7 @@ urlpatterns = [ url(r'^ctl-(?P[0-9]+)\.html$', views.modlog, name='old-modlog'), url(r'^ctl/((?P[0-9]+)/)?$', views.modlog, name='modlog'), url(r'^overchan\.(?P[a-zA-z0-9\.]+)-(?P[0-9]+)\.html$', views.BoardView.as_view(), name='old-board'), - url(r'^overchan\.(?P[a-zA-z0-9\.]+)/((?P[0-9]+)/)?$', views.BoardView.as_view(), name='board'), + url(r'^overchan\.(?P[a-zA-z0-9\.]+)/', views.BoardView.as_view(), name='board'), url(r'^thread-(?P[a-fA-F0-9\.]{40})\.html$', views.ThreadView.as_view(), name='old-thread'), url(r'^t/(?P[a-fA-F0-9\.]{40})/$', views.ThreadView.as_view(), name='thread'), url(r'^$', views.FrontPageView.as_view(), name='index'), diff --git a/contrib/frontends/django/nntpchan/nntpchan/frontend/views.py b/contrib/frontends/django/nntpchan/nntpchan/frontend/views.py index b48f205..52e15d5 100644 --- a/contrib/frontends/django/nntpchan/nntpchan/frontend/views.py +++ b/contrib/frontends/django/nntpchan/nntpchan/frontend/views.py @@ -1,7 +1,9 @@ +from django.core.urlresolvers import reverse from django.http import HttpResponse, Http404 from django.shortcuts import render, get_object_or_404 from django.views import generic + from .models import Post, Newsgroup class BoardView(generic.View): @@ -9,9 +11,17 @@ class BoardView(generic.View): context_object_name = 'threads' model = Post - def get(self, request, name, page): + def get(self, request, name): + page = 0 + if 'p' in request.GET: + page = request.GET['p'] newsgroup = 'overchan.{}'.format(name) - page = int(page or "0") + try: + page = int(page or "0") + except: + page = 0 + if page < 0: + page = 0 try: group = Newsgroup.objects.get(name=newsgroup) except Newsgroup.DoesNotExist: @@ -20,11 +30,11 @@ class BoardView(generic.View): begin = page * group.posts_per_page end = begin + group.posts_per_page - 1 roots = self.model.objects.filter(newsgroup=group, reference='').order_by('-last_bumped')[begin:end] - ctx = {'threads': roots,'page': page, 'name': newsgroup} + ctx = {'threads': roots, 'page': page, 'name': newsgroup} if page < group.max_pages: - ctx['nextpage'] = '/{}/{}/'.format(group.name, page + 1) + ctx['nextpage'] = reverse('board', args=[name]) + '?p={}'.format(page + 1) if page > 0: - ctx['prevpage'] = '/{}/{}/'.format(group.name, page - 1) + ctx['prevpage'] = reverse('board', args=[name]) + '?p={}'.format(page - 1) return render(request, self.template_name, ctx)