|
@@ -9,53 +9,10 @@ from misago.forums.lists import get_forums_list, get_forum_path
|
|
from misago.threads.posting import (PostingInterrupt, EditorFormset,
|
|
from misago.threads.posting import (PostingInterrupt, EditorFormset,
|
|
START, REPLY, EDIT)
|
|
START, REPLY, EDIT)
|
|
from misago.threads.models import ANNOUNCEMENT, Thread
|
|
from misago.threads.models import ANNOUNCEMENT, Thread
|
|
-from misago.threads.views.generic.base import ViewBase
|
|
|
|
|
|
+from misago.threads.views.generic.threads import OrderThreadsMixin, ThreadsView
|
|
|
|
|
|
|
|
|
|
-__all__ = ['OrderThreadsMixin', 'ThreadsView', 'ForumView']
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-class OrderThreadsMixin(object):
|
|
|
|
- order_by = (
|
|
|
|
- ('recently-replied', ugettext_lazy("Recently replied")),
|
|
|
|
- ('last-replied', ugettext_lazy("Last replied")),
|
|
|
|
- ('most-replied', ugettext_lazy("Most replied")),
|
|
|
|
- ('least-replied', ugettext_lazy("Least replied")),
|
|
|
|
- ('newest', ugettext_lazy("Newest")),
|
|
|
|
- ('oldest', ugettext_lazy("Oldest")),
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- def get_ordering(self, kwargs):
|
|
|
|
- if kwargs.get('sort') in [o[0] for o in self.order_by]:
|
|
|
|
- return kwargs.get('sort')
|
|
|
|
- else:
|
|
|
|
- return self.order_by[0][0]
|
|
|
|
-
|
|
|
|
- def is_ordering_default(self, order_by):
|
|
|
|
- return self.order_by[0][0] == order_by
|
|
|
|
-
|
|
|
|
- def get_ordering_name(self, order_by):
|
|
|
|
- for ordering in self.order_by:
|
|
|
|
- if ordering[0] == order_by:
|
|
|
|
- return ordering[1]
|
|
|
|
-
|
|
|
|
- def get_orderings_dicts(self, exclude_ordering, links_params):
|
|
|
|
- url_kwargs = links_params.copy()
|
|
|
|
- dicts = []
|
|
|
|
-
|
|
|
|
- for ordering in self.order_by:
|
|
|
|
- if not dicts:
|
|
|
|
- url_kwargs.pop('sort', None)
|
|
|
|
- else:
|
|
|
|
- url_kwargs['sort'] = ordering[0]
|
|
|
|
-
|
|
|
|
- if ordering[0] != exclude_ordering:
|
|
|
|
- dicts.append({
|
|
|
|
- 'url': reverse(self.link_name, kwargs=url_kwargs),
|
|
|
|
- 'name': ordering[1],
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- return dicts
|
|
|
|
|
|
+__all__ = ['FilterThreadsMixin', 'ForumView']
|
|
|
|
|
|
|
|
|
|
class FilterThreadsMixin(object):
|
|
class FilterThreadsMixin(object):
|
|
@@ -92,43 +49,11 @@ class FilterThreadsMixin(object):
|
|
return dicts
|
|
return dicts
|
|
|
|
|
|
|
|
|
|
-class ThreadsView(ViewBase):
|
|
|
|
- def get_threads(self, request, kwargs):
|
|
|
|
- queryset = self.get_threads_queryset(request, forum)
|
|
|
|
-
|
|
|
|
- threads_qs = queryset.filter(weight__lt=ANNOUNCEMENT)
|
|
|
|
- threads_qs = threads_qs.order_by('-weight', '-last_post_id')
|
|
|
|
-
|
|
|
|
- page = paginate(threads_qs, kwargs.get('page', 0), 30, 10)
|
|
|
|
- threads = []
|
|
|
|
-
|
|
|
|
- for announcement in queryset.filter(weight=ANNOUNCEMENT):
|
|
|
|
- threads.append(announcement)
|
|
|
|
- for thread in page.object_list:
|
|
|
|
- threads.append(thread)
|
|
|
|
-
|
|
|
|
- for thread in threads:
|
|
|
|
- thread.forum = forum
|
|
|
|
-
|
|
|
|
- return page, threads
|
|
|
|
-
|
|
|
|
- def get_threads_queryset(self, request):
|
|
|
|
- return forum.thread_set.all().order_by('-last_post_id')
|
|
|
|
-
|
|
|
|
- def add_threads_reads(self, request, threads):
|
|
|
|
- for thread in threads:
|
|
|
|
- thread.is_new = False
|
|
|
|
-
|
|
|
|
- import random
|
|
|
|
- for thread in threads:
|
|
|
|
- thread.is_new = random.choice((True, False))
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class ForumView(FilterThreadsMixin, OrderThreadsMixin, ThreadsView):
|
|
class ForumView(FilterThreadsMixin, OrderThreadsMixin, ThreadsView):
|
|
"""
|
|
"""
|
|
Basic view for threads lists
|
|
Basic view for threads lists
|
|
"""
|
|
"""
|
|
- template = 'misago/threads/list.html'
|
|
|
|
|
|
+ template = 'misago/threads/forum.html'
|
|
|
|
|
|
def get_threads(self, request, forum, kwargs,
|
|
def get_threads(self, request, forum, kwargs,
|
|
order_by=None, filter_by=None):
|
|
order_by=None, filter_by=None):
|