board.py
70 lines
| 1.6 KiB
| text/x-python
|
PythonLexer
|
r320 | from django.core.urlresolvers import reverse | |
from django.shortcuts import get_object_or_404 | |||
from boards.models import Post | |||
|
r537 | from boards.views import thread, api | |
|
r320 | from django import template | |
register = template.Library() | |||
|
r460 | actions = [ | |
{ | |||
'name': 'google', | |||
'link': 'http://google.com/searchbyimage?image_url=%s', | |||
}, | |||
{ | |||
'name': 'iqdb', | |||
'link': 'http://iqdb.org/?url=%s', | |||
}, | |||
] | |||
|
r320 | ||
@register.simple_tag(name='post_url') | |||
def post_url(*args, **kwargs): | |||
post_id = args[0] | |||
post = get_object_or_404(Post, id=post_id) | |||
|
r400 | if not post.is_opening(): | |
link = reverse(thread, kwargs={ | |||
'post_id': post.thread_new.get_opening_post().id}) + '#' + str( | |||
post_id) | |||
|
r320 | else: | |
|
r322 | link = reverse(thread, kwargs={'post_id': post_id}) | |
|
r320 | ||
return link | |||
|
r460 | ||
@register.simple_tag(name='image_actions') | |||
def image_actions(*args, **kwargs): | |||
image_link = args[0] | |||
if len(args) > 1: | |||
image_link = 'http://' + args[1] + image_link # TODO https? | |||
result = '' | |||
for action in actions: | |||
result += '[<a href="' + action['link'] % image_link + '">' + \ | |||
action['name'] + '</a>]' | |||
return result | |||
|
r537 | ||
@register.inclusion_tag('boards/post.html', name='post_view') | |||
def post_view(*args, **kwargs): | |||
post = args[0] | |||
return { 'post': post } | |||
@register.inclusion_tag('boards/post.html', name='post_view_truncated') | |||
def post_view_truncated(*args, **kwargs): | |||
post = args[0] | |||
if len(args) > 1: | |||
need_open_link = args[1] | |||
else: | |||
need_open_link = False | |||
return { | |||
'post': post, | |||
'truncated': True, | |||
'need_open_link': need_open_link | |||
} |