##// END OF EJS Templates
Added missing space
Added missing space

File last commit:

r1170:499809d3 default
r1179:eb8f85b0 default
Show More
feed.py
71 lines | 2.3 KiB | text/x-python | PythonLexer
neko259
Added all posts feed
r1165 from django.core.urlresolvers import reverse
from django.core.files import File
from django.core.files.temp import NamedTemporaryFile
from django.core.paginator import EmptyPage
from django.db import transaction
from django.http import Http404
from django.shortcuts import render, redirect
import requests
from boards import utils, settings
from boards.abstracts.paginator import get_paginator
neko259
Don't show posts from ignored tag threads in the feed
r1170 from boards.abstracts.settingsmanager import get_settings_manager
neko259
Added all posts feed
r1165 from boards.models import Post, Thread, Ban, Tag, PostImage, Banner
from boards.views.base import BaseBoardView
from boards.views.posting_mixin import PostMixin
PARAMETER_CURRENT_PAGE = 'current_page'
PARAMETER_PAGINATOR = 'paginator'
PARAMETER_POSTS = 'posts'
PARAMETER_PREV_LINK = 'prev_page_link'
PARAMETER_NEXT_LINK = 'next_page_link'
TEMPLATE = 'boards/feed.html'
DEFAULT_PAGE = 1
class FeedView(PostMixin, BaseBoardView):
def get(self, request, page=DEFAULT_PAGE):
params = self.get_context_data(request=request)
neko259
Don't show posts from ignored tag threads in the feed
r1170 settings_manager = get_settings_manager(request)
paginator = get_paginator(Post.objects
.exclude(threads__tags__in=settings_manager.get_hidden_tags())
.order_by('-pub_time')
neko259
Optimized feed loading, prefetch images and thread
r1167 .prefetch_related('images', 'thread', 'threads'), 10)
neko259
Added all posts feed
r1165 paginator.current_page = int(page)
params[PARAMETER_POSTS] = paginator.page(page).object_list
self.get_page_context(paginator, params, page)
return render(request, TEMPLATE, params)
# TODO Dedup this into PagedMixin
def get_page_context(self, paginator, params, page):
"""
Get pagination context variables
"""
params[PARAMETER_PAGINATOR] = paginator
current_page = paginator.page(int(page))
params[PARAMETER_CURRENT_PAGE] = current_page
if current_page.has_previous():
params[PARAMETER_PREV_LINK] = self.get_previous_page_link(
current_page)
if current_page.has_next():
params[PARAMETER_NEXT_LINK] = self.get_next_page_link(current_page)
def get_previous_page_link(self, current_page):
return reverse('feed', kwargs={
'page': current_page.previous_page_number(),
})
def get_next_page_link(self, current_page):
return reverse('feed', kwargs={
'page': current_page.next_page_number(),
})