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