board.py
23 lines
| 610 B
| text/x-python
|
PythonLexer
neko259
|
r320 | from django.core.urlresolvers import reverse | ||
from django.shortcuts import get_object_or_404 | ||||
from boards.models import Post | ||||
from boards.views import thread | ||||
from django import template | ||||
register = template.Library() | ||||
@register.simple_tag(name='post_url') | ||||
def post_url(*args, **kwargs): | ||||
post_id = args[0] | ||||
post = get_object_or_404(Post, id=post_id) | ||||
neko259
|
r400 | if not post.is_opening(): | ||
link = reverse(thread, kwargs={ | ||||
'post_id': post.thread_new.get_opening_post().id}) + '#' + str( | ||||
post_id) | ||||
neko259
|
r320 | else: | ||
neko259
|
r322 | link = reverse(thread, kwargs={'post_id': post_id}) | ||
neko259
|
r320 | |||
return link | ||||