Show More
@@ -43,3 +43,6 b' ArchiveThreads = true' | |||||
43 |
|
43 | |||
44 | [RSS] |
|
44 | [RSS] | |
45 | MaxItems = 20 |
|
45 | MaxItems = 20 | |
|
46 | ||||
|
47 | [External] | |||
|
48 | ImageSearchHost=http://127.0.0.1/ |
@@ -24,7 +24,8 b'' | |||||
24 | {{ image.get_view }} |
|
24 | {{ image.get_view }} | |
25 | <div class="gallery_image_metadata"> |
|
25 | <div class="gallery_image_metadata"> | |
26 | {{ image.get_size.0 }}x{{ image.get_size.1 }} |
|
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 | <br /> |
|
29 | <br /> | |
29 | <a href="{{ post.get_absolute_url }}">>>{{ post.id }}</a> |
|
30 | <a href="{{ post.get_absolute_url }}">>>{{ post.id }}</a> | |
30 | </div> |
|
31 | </div> |
@@ -3,8 +3,10 b' import re' | |||||
3 | from django.shortcuts import get_object_or_404 |
|
3 | from django.shortcuts import get_object_or_404 | |
4 | from django import template |
|
4 | from django import template | |
5 | from django.utils.text import re_tag |
|
5 | from django.utils.text import re_tag | |
|
6 | from django.core.urlresolvers import reverse | |||
6 |
|
7 | |||
7 | from boards.mdx_neboard import LINE_BREAK_HTML |
|
8 | from boards.mdx_neboard import LINE_BREAK_HTML | |
|
9 | from boards import settings | |||
8 |
|
10 | |||
9 |
|
11 | |||
10 | IMG_ACTION_URL = '[<a href="{}">{}</a>]' |
|
12 | IMG_ACTION_URL = '[<a href="{}">{}</a>]' | |
@@ -20,11 +22,11 b' register = template.Library()' | |||||
20 | actions = [ |
|
22 | actions = [ | |
21 | { |
|
23 | { | |
22 | 'name': 'google', |
|
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 | 'name': 'iqdb', |
|
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 | @register.simple_tag(name='image_actions') |
|
43 | @register.simple_tag(name='image_actions') | |
42 | def image_actions(*args, **kwargs): |
|
44 | def image_actions(*args, **kwargs): | |
43 | image_link = args[0] |
|
45 | image_link = args[0] | |
44 | if len(args) > 1: |
|
46 | host = settings.get('External', 'ImageSearchHost') | |
45 | image_link = 'http://' + args[1] + image_link # TODO https? |
|
47 | if host.endswith('/'): | |
|
48 | host = host[:-1] | |||
|
49 | image_link = settings.get('External', 'ImageSearchHost') + image_link | |||
46 |
|
50 | |||
47 | return ', '.join([IMG_ACTION_URL.format( |
|
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 | @register.inclusion_tag('boards/post.html', name='post_view', takes_context=True) |
|
55 | @register.inclusion_tag('boards/post.html', name='post_view', takes_context=True) |
@@ -21,13 +21,68 b" TEMPLATE = 'boards/feed.html'" | |||||
21 | DEFAULT_PAGE = 1 |
|
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 | class FeedView(PostMixin, BaseBoardView): |
|
76 | class FeedView(PostMixin, BaseBoardView): | |
|
77 | filters = ( | |||
|
78 | TripcodeFilter, | |||
|
79 | FavoritesFilter, | |||
|
80 | IpFilter, | |||
|
81 | HashFilter, | |||
|
82 | ) | |||
25 |
|
83 | |||
26 | def get(self, request): |
|
84 | def get(self, request): | |
27 | page = request.GET.get('page', DEFAULT_PAGE) |
|
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 | params = self.get_context_data(request=request) |
|
87 | params = self.get_context_data(request=request) | |
33 |
|
88 | |||
@@ -36,14 +91,8 b' class FeedView(PostMixin, BaseBoardView)' | |||||
36 | posts = Post.objects.exclude( |
|
91 | posts = Post.objects.exclude( | |
37 | thread__tags__in=settings_manager.get_hidden_tags()).order_by( |
|
92 | thread__tags__in=settings_manager.get_hidden_tags()).order_by( | |
38 | '-pub_time').prefetch_related('attachments', 'thread') |
|
93 | '-pub_time').prefetch_related('attachments', 'thread') | |
39 | if tripcode: |
|
94 | for filter in self.filters: | |
40 | posts = posts.filter(tripcode=tripcode) |
|
95 | posts = filter.get_filtered_posts(request, posts) | |
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) |
|
|||
47 |
|
96 | |||
48 | paginator = get_paginator(posts, POSTS_PER_PAGE) |
|
97 | paginator = get_paginator(posts, POSTS_PER_PAGE) | |
49 | paginator.current_page = int(page) |
|
98 | paginator.current_page = int(page) |
General Comments 0
You need to be logged in to leave comments.
Login now