##// END OF EJS Templates
Get all posts with the same tripcode
neko259 -
r1302:57fd9a18 default
parent child Browse files
Show More
@@ -61,7 +61,7 b''
61 {% ifequal page current_page.number %}
61 {% ifequal page current_page.number %}
62 class="current_page"
62 class="current_page"
63 {% endifequal %}
63 {% endifequal %}
64 href="{% url "feed" %}?page={{ page }}">{{ page }}</a>
64 href="{% url "feed" %}?page={{ page }}{{ additional_attrs }}">{{ page }}</a>
65 {% if not forloop.last %},{% endif %}
65 {% if not forloop.last %},{% endif %}
66 {% endfor %}
66 {% endfor %}
67 {% endwith %}
67 {% endwith %}
@@ -9,9 +9,11 b''
9 <span class="title">{{ post.title }}</span>
9 <span class="title">{{ post.title }}</span>
10 <span class="pub_time"><time datetime="{{ post.pub_time|date:'c' }}">{{ post.pub_time }}</time></span>
10 <span class="pub_time"><time datetime="{{ post.pub_time|date:'c' }}">{{ post.pub_time }}</time></span>
11 {% if post.tripcode %}
11 {% if post.tripcode %}
12 {% autoescape off %}
12 {% with tripcode=post.get_tripcode %}
13 {{ post.get_tripcode.get_view }}
13 <a href="{% url 'feed' %}?tripcode={{ tripcode.get_full_text }}"
14 {% endautoescape %}
14 class="tripcode" title="{{ tripcode.get_full_text }}"
15 style="border: solid 2px #{{ tripcode.get_color }}; border-left: solid 1ex #{{ tripcode.get_color }};">{{ tripcode.get_short_text }}</a>
16 {% endwith %}
15 {% endif %}
17 {% endif %}
16 {% comment %}
18 {% comment %}
17 Thread death time needs to be shown only if the thread is alredy archived
19 Thread death time needs to be shown only if the thread is alredy archived
@@ -1,23 +1,18 b''
1 from django.core.urlresolvers import reverse
1 from django.core.urlresolvers import reverse
2 from django.core.files import File
2 from django.shortcuts import render
3 from django.core.files.temp import NamedTemporaryFile
4 from django.core.paginator import EmptyPage
5 from django.db import transaction
6 from django.http import Http404
7 from django.shortcuts import render, redirect
8 import requests
9
3
10 from boards import utils, settings
11 from boards.abstracts.paginator import get_paginator
4 from boards.abstracts.paginator import get_paginator
12 from boards.abstracts.settingsmanager import get_settings_manager
5 from boards.abstracts.settingsmanager import get_settings_manager
13 from boards.models import Post, Thread, Ban, Tag, PostImage, Banner
6 from boards.models import Post
14 from boards.views.base import BaseBoardView
7 from boards.views.base import BaseBoardView
15 from boards.views.posting_mixin import PostMixin
8 from boards.views.posting_mixin import PostMixin
16
9
10 POSTS_PER_PAGE = 10
17
11
18 PARAMETER_CURRENT_PAGE = 'current_page'
12 PARAMETER_CURRENT_PAGE = 'current_page'
19 PARAMETER_PAGINATOR = 'paginator'
13 PARAMETER_PAGINATOR = 'paginator'
20 PARAMETER_POSTS = 'posts'
14 PARAMETER_POSTS = 'posts'
15 PARAMETER_ADDITONAL_ATTRS = 'additional_attrs'
21
16
22 PARAMETER_PREV_LINK = 'prev_page_link'
17 PARAMETER_PREV_LINK = 'prev_page_link'
23 PARAMETER_NEXT_LINK = 'next_page_link'
18 PARAMETER_NEXT_LINK = 'next_page_link'
@@ -30,25 +25,34 b' class FeedView(PostMixin, BaseBoardView)'
30
25
31 def get(self, request):
26 def get(self, request):
32 page = request.GET.get('page', DEFAULT_PAGE)
27 page = request.GET.get('page', DEFAULT_PAGE)
28 tripcode = request.GET.get('tripcode', None)
33
29
34 params = self.get_context_data(request=request)
30 params = self.get_context_data(request=request)
35
31
36 settings_manager = get_settings_manager(request)
32 settings_manager = get_settings_manager(request)
37
33
38 paginator = get_paginator(Post.objects
34 posts = Post.objects.exclude(
39 .exclude(threads__tags__in=settings_manager.get_hidden_tags())
35 threads__tags__in=settings_manager.get_hidden_tags()).order_by(
40 .order_by('-pub_time')
36 '-pub_time').prefetch_related('images', 'thread', 'threads')
41 .prefetch_related('images', 'thread', 'threads'), 10)
37 if tripcode:
38 posts = posts.filter(tripcode=tripcode)
39
40 paginator = get_paginator(posts, POSTS_PER_PAGE)
42 paginator.current_page = int(page)
41 paginator.current_page = int(page)
43
42
44 params[PARAMETER_POSTS] = paginator.page(page).object_list
43 params[PARAMETER_POSTS] = paginator.page(page).object_list
45
44
46 self.get_page_context(paginator, params, page)
45 additional_params = dict()
46 if tripcode:
47 additional_params['tripcode'] = tripcode
48 params[PARAMETER_ADDITONAL_ATTRS] = '&tripcode=' + tripcode
49
50 self.get_page_context(paginator, params, page, additional_params)
47
51
48 return render(request, TEMPLATE, params)
52 return render(request, TEMPLATE, params)
49
53
50 # TODO Dedup this into PagedMixin
54 # TODO Dedup this into PagedMixin
51 def get_page_context(self, paginator, params, page):
55 def get_page_context(self, paginator, params, page, additional_params):
52 """
56 """
53 Get pagination context variables
57 Get pagination context variables
54 """
58 """
@@ -59,8 +63,14 b' class FeedView(PostMixin, BaseBoardView)'
59 if current_page.has_previous():
63 if current_page.has_previous():
60 params[PARAMETER_PREV_LINK] = self.get_previous_page_link(
64 params[PARAMETER_PREV_LINK] = self.get_previous_page_link(
61 current_page)
65 current_page)
66 for param in additional_params.keys():
67 params[PARAMETER_PREV_LINK] += '&{}={}'.format(
68 param, additional_params[param])
62 if current_page.has_next():
69 if current_page.has_next():
63 params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
70 params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
71 for param in additional_params.keys():
72 params[PARAMETER_NEXT_LINK] += '&{}={}'.format(
73 param, additional_params[param])
64
74
65 def get_previous_page_link(self, current_page):
75 def get_previous_page_link(self, current_page):
66 return reverse('feed') + '?page={}'.format(
76 return reverse('feed') + '?page={}'.format(
General Comments 0
You need to be logged in to leave comments. Login now