Show More
@@ -43,3 +43,6 b' ArchiveThreads = true' | |||
|
43 | 43 | |
|
44 | 44 | [RSS] |
|
45 | 45 | MaxItems = 20 |
|
46 | ||
|
47 | [External] | |
|
48 | ImageSearchHost=http://127.0.0.1/ |
@@ -24,7 +24,8 b'' | |||
|
24 | 24 | {{ image.get_view }} |
|
25 | 25 | <div class="gallery_image_metadata"> |
|
26 | 26 | {{ image.get_size.0 }}x{{ image.get_size.1 }} |
|
27 |
{% image_actions image.file.url |
|
|
27 | {% image_actions image.file.url %}, | |
|
28 | [<a href="{% url 'feed' %}?image_hash={{ image.hash }}">{{ site_name }}</a>] | |
|
28 | 29 | <br /> |
|
29 | 30 | <a href="{{ post.get_absolute_url }}">>>{{ post.id }}</a> |
|
30 | 31 | </div> |
@@ -3,8 +3,10 b' import re' | |||
|
3 | 3 | from django.shortcuts import get_object_or_404 |
|
4 | 4 | from django import template |
|
5 | 5 | from django.utils.text import re_tag |
|
6 | from django.core.urlresolvers import reverse | |
|
6 | 7 | |
|
7 | 8 | from boards.mdx_neboard import LINE_BREAK_HTML |
|
9 | from boards import settings | |
|
8 | 10 | |
|
9 | 11 | |
|
10 | 12 | IMG_ACTION_URL = '[<a href="{}">{}</a>]' |
@@ -20,11 +22,11 b' register = template.Library()' | |||
|
20 | 22 | actions = [ |
|
21 | 23 | { |
|
22 | 24 | 'name': 'google', |
|
23 |
'link': 'http://google.com/searchbyimage?image_url= |
|
|
25 | 'link': 'https://www.google.com/searchbyimage?image_url={}', | |
|
24 | 26 | }, |
|
25 | 27 | { |
|
26 | 28 | 'name': 'iqdb', |
|
27 |
'link': 'http://iqdb.org/?url= |
|
|
29 | 'link': 'http://iqdb.org/?url={}', | |
|
28 | 30 | }, |
|
29 | 31 | ] |
|
30 | 32 | |
@@ -41,11 +43,13 b' def post_url(*args, **kwargs):' | |||
|
41 | 43 | @register.simple_tag(name='image_actions') |
|
42 | 44 | def image_actions(*args, **kwargs): |
|
43 | 45 | image_link = args[0] |
|
44 | if len(args) > 1: | |
|
45 | image_link = 'http://' + args[1] + image_link # TODO https? | |
|
46 | host = settings.get('External', 'ImageSearchHost') | |
|
47 | if host.endswith('/'): | |
|
48 | host = host[:-1] | |
|
49 | image_link = settings.get('External', 'ImageSearchHost') + image_link | |
|
46 | 50 | |
|
47 | 51 | return ', '.join([IMG_ACTION_URL.format( |
|
48 |
action['link'] |
|
|
52 | action['link'].format(image_link), action['name']) for action in actions]) | |
|
49 | 53 | |
|
50 | 54 | |
|
51 | 55 | @register.inclusion_tag('boards/post.html', name='post_view', takes_context=True) |
@@ -21,13 +21,68 b" TEMPLATE = 'boards/feed.html'" | |||
|
21 | 21 | DEFAULT_PAGE = 1 |
|
22 | 22 | |
|
23 | 23 | |
|
24 | class FeedFilter: | |
|
25 | @staticmethod | |
|
26 | def get_filtered_posts(request, posts): | |
|
27 | return posts | |
|
28 | ||
|
29 | ||
|
30 | class TripcodeFilter(FeedFilter): | |
|
31 | @staticmethod | |
|
32 | def get_filtered_posts(request, posts): | |
|
33 | filtered_posts = posts | |
|
34 | tripcode = request.GET.get('tripcode', None) | |
|
35 | if tripcode: | |
|
36 | filtered_posts = filtered_posts.filter(tripcode) | |
|
37 | return filtered_posts | |
|
38 | ||
|
39 | ||
|
40 | class FavoritesFilter(FeedFilter): | |
|
41 | @staticmethod | |
|
42 | def get_filtered_posts(request, posts): | |
|
43 | filtered_posts = posts | |
|
44 | ||
|
45 | favorites = 'favorites' in request.GET | |
|
46 | if favorites: | |
|
47 | settings_manager = get_settings_manager(request) | |
|
48 | 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] | |
|
50 | filtered_posts = filtered_posts.filter(thread__in=fav_threads) | |
|
51 | return filtered_posts | |
|
52 | ||
|
53 | ||
|
54 | class IpFilter(FeedFilter): | |
|
55 | @staticmethod | |
|
56 | def get_filtered_posts(request, posts): | |
|
57 | filtered_posts = posts | |
|
58 | ||
|
59 | ip = request.GET.get('ip', None) | |
|
60 | if ip and request.user.has_perm('post_delete'): | |
|
61 | filtered_posts = filtered_posts.filter(poster_ip=ip) | |
|
62 | return filtered_posts | |
|
63 | ||
|
64 | ||
|
65 | class HashFilter(FeedFilter): | |
|
66 | @staticmethod | |
|
67 | def get_filtered_posts(request, posts): | |
|
68 | filtered_posts = posts | |
|
69 | ||
|
70 | image_hash = request.GET.get('image_hash', None) | |
|
71 | if image_hash: | |
|
72 | filtered_posts = filtered_posts.filter(attachments__hash=image_hash) | |
|
73 | return filtered_posts | |
|
74 | ||
|
75 | ||
|
24 | 76 | class FeedView(PostMixin, BaseBoardView): |
|
77 | filters = ( | |
|
78 | TripcodeFilter, | |
|
79 | FavoritesFilter, | |
|
80 | IpFilter, | |
|
81 | HashFilter, | |
|
82 | ) | |
|
25 | 83 | |
|
26 | 84 | def get(self, request): |
|
27 | 85 | page = request.GET.get('page', DEFAULT_PAGE) |
|
28 | tripcode = request.GET.get('tripcode', None) | |
|
29 | favorites = 'favorites' in request.GET | |
|
30 | ip = request.GET.get('ip', None) | |
|
31 | 86 | |
|
32 | 87 | params = self.get_context_data(request=request) |
|
33 | 88 | |
@@ -36,14 +91,8 b' class FeedView(PostMixin, BaseBoardView)' | |||
|
36 | 91 | posts = Post.objects.exclude( |
|
37 | 92 | thread__tags__in=settings_manager.get_hidden_tags()).order_by( |
|
38 | 93 | '-pub_time').prefetch_related('attachments', 'thread') |
|
39 | if tripcode: | |
|
40 | posts = posts.filter(tripcode=tripcode) | |
|
41 | if favorites: | |
|
42 | fav_thread_ops = Post.objects.filter(id__in=settings_manager.get_fav_threads().keys()) | |
|
43 | fav_threads = [op.get_thread() for op in fav_thread_ops] | |
|
44 | posts = posts.filter(thread__in=fav_threads) | |
|
45 | if ip and request.user.has_perm('post_delete'): | |
|
46 | posts = posts.filter(poster_ip=ip) | |
|
94 | for filter in self.filters: | |
|
95 | posts = filter.get_filtered_posts(request, posts) | |
|
47 | 96 | |
|
48 | 97 | paginator = get_paginator(posts, POSTS_PER_PAGE) |
|
49 | 98 | paginator.current_page = int(page) |
General Comments 0
You need to be logged in to leave comments.
Login now