board.py
45 lines
| 969 B
| text/x-python
|
PythonLexer
neko259
|
r1000 | import re | ||
neko259
|
r320 | from django.shortcuts import get_object_or_404 | ||
from django import template | ||||
neko259
|
r1000 | |||
neko259
|
r1027 | IMG_ACTION_URL = '[<a href="{}">{}</a>]' | ||
neko259
|
r692 | |||
neko259
|
r320 | register = template.Library() | ||
neko259
|
r460 | actions = [ | ||
{ | ||||
'name': 'google', | ||||
'link': 'http://google.com/searchbyimage?image_url=%s', | ||||
}, | ||||
{ | ||||
'name': 'iqdb', | ||||
'link': 'http://iqdb.org/?url=%s', | ||||
}, | ||||
] | ||||
neko259
|
r320 | |||
@register.simple_tag(name='post_url') | ||||
def post_url(*args, **kwargs): | ||||
post_id = args[0] | ||||
neko259
|
r692 | post = get_object_or_404('Post', id=post_id) | ||
neko259
|
r320 | |||
neko259
|
r621 | return post.get_url() | ||
neko259
|
r614 | |||
neko259
|
r460 | @register.simple_tag(name='image_actions') | ||
def image_actions(*args, **kwargs): | ||||
image_link = args[0] | ||||
if len(args) > 1: | ||||
neko259
|
r1027 | image_link = 'http://' + args[1] + image_link # TODO https? | ||
neko259
|
r460 | |||
neko259
|
r1027 | return ', '.join([IMG_ACTION_URL.format( | ||
action['link'] % image_link, action['name'])for action in actions]) | ||||
neko259
|
r537 | |||
neko259
|
r1096 | @register.simple_tag(name='post_view') | ||
def post_view(post, *args, **kwargs): | ||||
return post.get_view(*args, **kwargs) | ||||
neko259
|
r614 | |||