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