Show More
@@ -1,70 +1,70 b'' | |||
|
1 | 1 | from django.core.urlresolvers import reverse |
|
2 | 2 | from django.shortcuts import render |
|
3 | 3 | |
|
4 | 4 | from boards.abstracts.paginator import get_paginator |
|
5 | 5 | from boards.abstracts.settingsmanager import get_settings_manager |
|
6 | 6 | from boards.models import Post |
|
7 | 7 | from boards.views.base import BaseBoardView |
|
8 | 8 | from boards.views.posting_mixin import PostMixin |
|
9 | 9 | |
|
10 | 10 | POSTS_PER_PAGE = 10 |
|
11 | 11 | |
|
12 | 12 | PARAMETER_CURRENT_PAGE = 'current_page' |
|
13 | 13 | PARAMETER_PAGINATOR = 'paginator' |
|
14 | 14 | PARAMETER_POSTS = 'posts' |
|
15 | 15 | |
|
16 | 16 | PARAMETER_PREV_LINK = 'prev_page_link' |
|
17 | 17 | PARAMETER_NEXT_LINK = 'next_page_link' |
|
18 | 18 | |
|
19 | 19 | TEMPLATE = 'boards/feed.html' |
|
20 | 20 | DEFAULT_PAGE = 1 |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | class FeedView(PostMixin, BaseBoardView): |
|
24 | 24 | |
|
25 | 25 | def get(self, request): |
|
26 | 26 | page = request.GET.get('page', DEFAULT_PAGE) |
|
27 | 27 | tripcode = request.GET.get('tripcode', None) |
|
28 | 28 | favorites = 'favorites' in request.GET |
|
29 | 29 | |
|
30 | 30 | params = self.get_context_data(request=request) |
|
31 | 31 | |
|
32 | 32 | settings_manager = get_settings_manager(request) |
|
33 | 33 | |
|
34 | 34 | posts = Post.objects.exclude( |
|
35 | 35 | threads__tags__in=settings_manager.get_hidden_tags()).order_by( |
|
36 |
'-pub_time').prefetch_related(' |
|
|
36 | '-pub_time').prefetch_related('attachments', 'thread', 'threads') | |
|
37 | 37 | if tripcode: |
|
38 | 38 | posts = posts.filter(tripcode=tripcode) |
|
39 | 39 | if favorites: |
|
40 | 40 | fav_thread_ops = Post.objects.filter(id__in=settings_manager.get_fav_threads().keys()) |
|
41 | 41 | fav_threads = [op.get_thread() for op in fav_thread_ops] |
|
42 | 42 | posts = posts.filter(threads__in=fav_threads) |
|
43 | 43 | |
|
44 | 44 | paginator = get_paginator(posts, POSTS_PER_PAGE) |
|
45 | 45 | paginator.current_page = int(page) |
|
46 | 46 | |
|
47 | 47 | params[PARAMETER_POSTS] = paginator.page(page).object_list |
|
48 | 48 | |
|
49 | 49 | paginator.set_url(reverse('feed'), request.GET.dict()) |
|
50 | 50 | |
|
51 | 51 | self.get_page_context(paginator, params, page) |
|
52 | 52 | |
|
53 | 53 | return render(request, TEMPLATE, params) |
|
54 | 54 | |
|
55 | 55 | # TODO Dedup this into PagedMixin |
|
56 | 56 | def get_page_context(self, paginator, params, page): |
|
57 | 57 | """ |
|
58 | 58 | Get pagination context variables |
|
59 | 59 | """ |
|
60 | 60 | |
|
61 | 61 | params[PARAMETER_PAGINATOR] = paginator |
|
62 | 62 | current_page = paginator.page(int(page)) |
|
63 | 63 | params[PARAMETER_CURRENT_PAGE] = current_page |
|
64 | 64 | if current_page.has_previous(): |
|
65 | 65 | params[PARAMETER_PREV_LINK] = paginator.get_page_url( |
|
66 | 66 | current_page.previous_page_number()) |
|
67 | 67 | if current_page.has_next(): |
|
68 | 68 | params[PARAMETER_NEXT_LINK] = paginator.get_page_url( |
|
69 | 69 | current_page.next_page_number()) |
|
70 | 70 |
General Comments 0
You need to be logged in to leave comments.
Login now