##// END OF EJS Templates
Show header in the feed
neko259 -
r1823:ce41b3a5 default
parent child Browse files
Show More
@@ -1,69 +1,73 b''
1 1 {% extends "boards/base.html" %}
2 2
3 3 {% load i18n %}
4 4 {% load board %}
5 5 {% load static %}
6 6 {% load tz %}
7 7
8 8 {% block head %}
9 9 <meta name="robots" content="noindex">
10 10
11 11 <title>{{ site_name }} - {% trans "feed" %}</title>
12 12
13 13 {% if prev_page_link %}
14 14 <link rel="prev" href="{{ prev_page_link }}" />
15 15 {% endif %}
16 16 {% if next_page_link %}
17 17 <link rel="next" href="{{ next_page_link }}" />
18 18 {% endif %}
19 19
20 20 {% endblock %}
21 21
22 22 {% block content %}
23 23
24 24 {% get_current_language as LANGUAGE_CODE %}
25 25 {% get_current_timezone as TIME_ZONE %}
26 26
27 {% for query in queries %}
28 <div class="image-mode-tab">{{ query }}</div>
29 {% endfor %}
30
27 31 {% if posts %}
28 32 {% if prev_page_link %}
29 33 <div class="page_link">
30 34 <a href="{{ prev_page_link }}">&lt;&lt; {% trans "Previous page" %} &lt;&lt;</a>
31 35 </div>
32 36 {% endif %}
33 37
34 38 {% for post in posts %}
35 39 {% post_view post moderator=moderator truncated=True need_op_data=True %}
36 40 {% endfor %}
37 41
38 42 {% if next_page_link %}
39 43 <div class="page_link">
40 44 <a href="{{ next_page_link }}">&gt;&gt; {% trans "Next page" %} &gt;&gt;</a>
41 45 </div>
42 46 {% endif %}
43 47 {% else %}
44 48 <div class="post">
45 49 {% trans 'No posts exist. Create the first one!' %}</div>
46 50 {% endif %}
47 51 {% endblock %}
48 52
49 53 {% block metapanel %}
50 54
51 55 <span class="metapanel">
52 56 {% trans "Pages:" %}
53 57 [
54 58 {% with dividers=paginator.get_dividers %}
55 59 {% for page in paginator.get_divided_range %}
56 60 {% if page in dividers %}
57 61 …,
58 62 {% endif %}
59 63 <a
60 64 {% ifequal page current_page.number %}
61 65 class="current_page"
62 66 {% endifequal %}
63 67 href="{% page_url paginator page %}">{{ page }}</a>{% if not forloop.last %},{% endif %}
64 68 {% endfor %}
65 69 {% endwith %}
66 70 ]
67 71 </span>
68 72
69 73 {% endblock %}
@@ -1,123 +1,151 b''
1 1 from django.core.urlresolvers import reverse
2 2 from django.shortcuts import render
3 3
4 4 from boards import settings
5 5 from boards.abstracts.paginator import get_paginator
6 6 from boards.abstracts.settingsmanager import get_settings_manager
7 7 from boards.models import Post
8 8 from boards.views.base import BaseBoardView
9 9 from boards.views.posting_mixin import PostMixin
10 10
11 11 POSTS_PER_PAGE = settings.get_int('View', 'PostsPerPage')
12 12
13 13 PARAMETER_CURRENT_PAGE = 'current_page'
14 14 PARAMETER_PAGINATOR = 'paginator'
15 15 PARAMETER_POSTS = 'posts'
16 PARAMETER_QUERIES = 'queries'
16 17
17 18 PARAMETER_PREV_LINK = 'prev_page_link'
18 19 PARAMETER_NEXT_LINK = 'next_page_link'
19 20
20 21 TEMPLATE = 'boards/feed.html'
21 22 DEFAULT_PAGE = 1
22 23
23 24
24 25 class FeedFilter:
25 26 @staticmethod
26 27 def get_filtered_posts(request, posts):
27 28 return posts
28 29
30 @staticmethod
31 def get_query(request):
32 return None
33
29 34
30 35 class TripcodeFilter(FeedFilter):
31 36 @staticmethod
32 37 def get_filtered_posts(request, posts):
33 38 filtered_posts = posts
34 39 tripcode = request.GET.get('tripcode', None)
35 40 if tripcode:
36 41 filtered_posts = filtered_posts.filter(tripcode=tripcode)
37 42 return filtered_posts
38 43
44 @staticmethod
45 def get_query(request):
46 tripcode = request.GET.get('tripcode', None)
47 if tripcode:
48 return 'Tripcode: {}'.format(tripcode)
49
39 50
40 51 class FavoritesFilter(FeedFilter):
41 52 @staticmethod
42 53 def get_filtered_posts(request, posts):
43 54 filtered_posts = posts
44 55
45 56 favorites = 'favorites' in request.GET
46 57 if favorites:
47 58 settings_manager = get_settings_manager(request)
48 59 fav_thread_ops = Post.objects.filter(id__in=settings_manager.get_fav_threads().keys())
49 60 fav_threads = [op.get_thread() for op in fav_thread_ops]
50 61 filtered_posts = filtered_posts.filter(thread__in=fav_threads)
51 62 return filtered_posts
52 63
53 64
54 65 class IpFilter(FeedFilter):
55 66 @staticmethod
56 67 def get_filtered_posts(request, posts):
57 68 filtered_posts = posts
58 69
59 70 ip = request.GET.get('ip', None)
60 71 if ip and request.user.has_perm('post_delete'):
61 72 filtered_posts = filtered_posts.filter(poster_ip=ip)
62 73 return filtered_posts
63 74
75 @staticmethod
76 def get_query(request):
77 ip = request.GET.get('ip', None)
78 if ip:
79 return 'IP: {}'.format(ip)
80
64 81
65 82 class HashFilter(FeedFilter):
66 83 @staticmethod
67 84 def get_filtered_posts(request, posts):
68 85 filtered_posts = posts
69 86
70 87 image_hash = request.GET.get('image_hash', None)
71 88 if image_hash:
72 89 filtered_posts = filtered_posts.filter(attachments__hash=image_hash)
73 90 return filtered_posts
74 91
92 @staticmethod
93 def get_query(request):
94 image_hash = request.GET.get('image_hash', None)
95 if image_hash:
96 return 'Hash: {}'.format(image_hash)
97
75 98
76 99 class FeedView(PostMixin, BaseBoardView):
77 100 filters = (
78 101 TripcodeFilter,
79 102 FavoritesFilter,
80 103 IpFilter,
81 104 HashFilter,
82 105 )
83 106
84 107 def get(self, request):
85 108 page = request.GET.get('page', DEFAULT_PAGE)
86 109
87 110 params = self.get_context_data(request=request)
88 111
89 112 settings_manager = get_settings_manager(request)
90 113
91 114 posts = Post.objects.exclude(
92 115 thread__tags__in=settings_manager.get_hidden_tags()).order_by(
93 116 '-pub_time').prefetch_related('attachments', 'thread')
117 queries = []
94 118 for filter in self.filters:
95 119 posts = filter.get_filtered_posts(request, posts)
120 query = filter.get_query(request)
121 if query:
122 queries.append(query)
123 params[PARAMETER_QUERIES] = queries
96 124
97 125 paginator = get_paginator(posts, POSTS_PER_PAGE)
98 126 paginator.current_page = int(page)
99 127
100 128 params[PARAMETER_POSTS] = paginator.page(page).object_list
101 129
102 130 paginator.set_url(reverse('feed'), request.GET.dict())
103 131
104 132 self.get_page_context(paginator, params, page)
105 133
106 134 return render(request, TEMPLATE, params)
107 135
108 136 # TODO Dedup this into PagedMixin
109 137 def get_page_context(self, paginator, params, page):
110 138 """
111 139 Get pagination context variables
112 140 """
113 141
114 142 params[PARAMETER_PAGINATOR] = paginator
115 143 current_page = paginator.page(int(page))
116 144 params[PARAMETER_CURRENT_PAGE] = current_page
117 145 if current_page.has_previous():
118 146 params[PARAMETER_PREV_LINK] = paginator.get_page_url(
119 147 current_page.previous_page_number())
120 148 if current_page.has_next():
121 149 params[PARAMETER_NEXT_LINK] = paginator.get_page_url(
122 150 current_page.next_page_number())
123 151
General Comments 0
You need to be logged in to leave comments. Login now