##// END OF EJS Templates
Localized a minor sticker message. Refactored sticker factory
Localized a minor sticker message. Refactored sticker factory

File last commit:

r1854:b4c06973 default
r1942:412bb996 default
Show More
feed.py
131 lines | 3.7 KiB | text/x-python | PythonLexer
neko259
Added all posts feed
r1165 from django.core.urlresolvers import reverse
neko259
Get all posts with the same tripcode
r1302 from django.shortcuts import render
neko259
Added all posts feed
r1165
neko259
Added setting for posts per page in feeds
r1681 from boards import settings
neko259
Added all posts feed
r1165 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
Get all posts with the same tripcode
r1302 from boards.models import Post
neko259
Added all posts feed
r1165 from boards.views.base import BaseBoardView
from boards.views.posting_mixin import PostMixin
neko259
Moved pagination related stuff to the mixin
r1854 from boards.views.mixins import PaginatedMixin
neko259
Added all posts feed
r1165
neko259
Added setting for posts per page in feeds
r1681 POSTS_PER_PAGE = settings.get_int('View', 'PostsPerPage')
neko259
Added all posts feed
r1165
PARAMETER_POSTS = 'posts'
neko259
Show header in the feed
r1823 PARAMETER_QUERIES = 'queries'
neko259
Added all posts feed
r1165
TEMPLATE = 'boards/feed.html'
DEFAULT_PAGE = 1
neko259
Fixed image search by google. Added duplicates search for images
r1802 class FeedFilter:
@staticmethod
def get_filtered_posts(request, posts):
return posts
neko259
Show header in the feed
r1823 @staticmethod
def get_query(request):
return None
neko259
Fixed image search by google. Added duplicates search for images
r1802
class TripcodeFilter(FeedFilter):
@staticmethod
def get_filtered_posts(request, posts):
filtered_posts = posts
tripcode = request.GET.get('tripcode', None)
if tripcode:
neko259
Fixed showing posts with tripcode in feed
r1804 filtered_posts = filtered_posts.filter(tripcode=tripcode)
neko259
Fixed image search by google. Added duplicates search for images
r1802 return filtered_posts
neko259
Show header in the feed
r1823 @staticmethod
def get_query(request):
tripcode = request.GET.get('tripcode', None)
if tripcode:
return 'Tripcode: {}'.format(tripcode)
neko259
Fixed image search by google. Added duplicates search for images
r1802
class FavoritesFilter(FeedFilter):
@staticmethod
def get_filtered_posts(request, posts):
filtered_posts = posts
favorites = 'favorites' in request.GET
if favorites:
settings_manager = get_settings_manager(request)
fav_thread_ops = Post.objects.filter(id__in=settings_manager.get_fav_threads().keys())
fav_threads = [op.get_thread() for op in fav_thread_ops]
filtered_posts = filtered_posts.filter(thread__in=fav_threads)
return filtered_posts
class IpFilter(FeedFilter):
@staticmethod
def get_filtered_posts(request, posts):
filtered_posts = posts
ip = request.GET.get('ip', None)
if ip and request.user.has_perm('post_delete'):
filtered_posts = filtered_posts.filter(poster_ip=ip)
return filtered_posts
neko259
Show header in the feed
r1823 @staticmethod
def get_query(request):
ip = request.GET.get('ip', None)
if ip:
return 'IP: {}'.format(ip)
neko259
Fixed image search by google. Added duplicates search for images
r1802
neko259
Search duplicates for file, not hash
r1827 class ImageFilter(FeedFilter):
neko259
Fixed image search by google. Added duplicates search for images
r1802 @staticmethod
def get_filtered_posts(request, posts):
filtered_posts = posts
neko259
Search duplicates for file, not hash
r1827 image = request.GET.get('image', None)
if image:
filtered_posts = filtered_posts.filter(attachments__file=image)
neko259
Fixed image search by google. Added duplicates search for images
r1802 return filtered_posts
neko259
Show header in the feed
r1823 @staticmethod
def get_query(request):
neko259
Search duplicates for file, not hash
r1827 image = request.GET.get('image', None)
if image:
return 'File: {}'.format(image)
neko259
Show header in the feed
r1823
neko259
Fixed image search by google. Added duplicates search for images
r1802
neko259
Moved pagination related stuff to the mixin
r1854 class FeedView(PostMixin, PaginatedMixin, BaseBoardView):
neko259
Fixed image search by google. Added duplicates search for images
r1802 filters = (
TripcodeFilter,
FavoritesFilter,
IpFilter,
neko259
Search duplicates for file, not hash
r1827 ImageFilter,
neko259
Fixed image search by google. Added duplicates search for images
r1802 )
neko259
Added all posts feed
r1165
neko259
Use GET parameter to specify a page instead of different url reversers
r1204 def get(self, request):
page = request.GET.get('page', DEFAULT_PAGE)
neko259
Added all posts feed
r1165 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)
neko259
Get all posts with the same tripcode
r1302 posts = Post.objects.exclude(
neko259
Removed multitread posts 'feature'
r1704 thread__tags__in=settings_manager.get_hidden_tags()).order_by(
'-pub_time').prefetch_related('attachments', 'thread')
neko259
Show header in the feed
r1823 queries = []
neko259
Fixed image search by google. Added duplicates search for images
r1802 for filter in self.filters:
posts = filter.get_filtered_posts(request, posts)
neko259
Show header in the feed
r1823 query = filter.get_query(request)
if query:
queries.append(query)
params[PARAMETER_QUERIES] = queries
neko259
Get all posts with the same tripcode
r1302
paginator = get_paginator(posts, POSTS_PER_PAGE)
neko259
Added all posts feed
r1165 paginator.current_page = int(page)
params[PARAMETER_POSTS] = paginator.page(page).object_list
neko259
Made feed view use the new-style paginator links
r1378 paginator.set_url(reverse('feed'), request.GET.dict())
neko259
Moved pagination related stuff to the mixin
r1854 params.update(self.get_page_context(paginator, page))
neko259
Added all posts feed
r1165
return render(request, TEMPLATE, params)