##// END OF EJS Templates
Show a list of available hosts
Show a list of available hosts

File last commit:

r1812:f2a9c571 default
r1939:d78c60b2 default
Show More
board.py
100 lines | 2.7 KiB | text/x-python | PythonLexer
neko259
Truncate posts by lines
r1000 import re
neko259
Truncate line breaks
r1786
neko259
Added a template tag to get post link instead of using jumper
r320 from django.shortcuts import get_object_or_404
from django import template
neko259
Truncate line breaks
r1786 from django.utils.text import re_tag
neko259
Fixed image search by google. Added duplicates search for images
r1802 from django.core.urlresolvers import reverse
neko259
Truncate line breaks
r1786
from boards.mdx_neboard import LINE_BREAK_HTML
neko259
Fixed image search by google. Added duplicates search for images
r1802 from boards import settings
neko259
Added a template tag to get post link instead of using jumper
r320
neko259
Truncate posts by lines
r1000
neko259
Refactoring
r1027 IMG_ACTION_URL = '[<a href="{}">{}</a>]'
neko259
Truncate line breaks
r1786 REGEX_NEWLINE = re.compile(LINE_BREAK_HTML)
TRUNCATOR = '...'
HTML4_SINGLETS =(
'br', 'col', 'link', 'base', 'img', 'param', 'area', 'hr', 'input'
)
neko259
Refactoring
r1027
neko259
Added tag search. Refactored search to show any model results in a list.
r692
neko259
Added a template tag to get post link instead of using jumper
r320 register = template.Library()
@register.simple_tag(name='post_url')
def post_url(*args, **kwargs):
post_id = args[0]
neko259
Added tag search. Refactored search to show any model results in a list.
r692 post = get_object_or_404('Post', id=post_id)
neko259
Added a template tag to get post link instead of using jumper
r320
neko259
Use get_absolute_url instead of get_url for post, tag and thread
r1160 return post.get_absolute_url()
neko259
Speed up thread loading
r614
neko259
Use inclusion tag for post_view
r1648 @register.inclusion_tag('boards/post.html', name='post_view', takes_context=True)
neko259
Do not pass over perms variable manually to the post template. Fixed thread...
r1390 def post_view(context, post, *args, **kwargs):
kwargs['perms'] = context['perms']
neko259
Use inclusion tag for post_view
r1648 return post.get_view_params(*args, **kwargs)
neko259
Speed up thread loading
r614
neko259
Fixed issue with newly added posts appearance
r1650
neko259
Added ability to get page urls of paginators
r1377 @register.simple_tag(name='page_url')
def page_url(paginator, page_number, *args, **kwargs):
neko259
Added method to check if the paginator supports new-style page links
r1379 if paginator.supports_urls():
return paginator.get_page_url(page_number)
neko259
Truncate line breaks
r1786
@register.filter(name='truncatenewlines_html')
def truncatenewlines_html(value, arg):
neko259
Line break truncation: Show truncator in the last line, not new one
r1799 end_pos = 0
start_pos = 0
neko259
Truncate line breaks
r1786 match_count = 0
# Collect places for truncation
while match_count <= arg:
neko259
Line break truncation: Show truncator in the last line, not new one
r1799 m = REGEX_NEWLINE.search(value, end_pos)
neko259
Truncate line breaks
r1786 if m is None:
break
else:
match_count += 1
neko259
Line break truncation: Show truncator in the last line, not new one
r1799 end_pos = m.end()
start_pos = m.start()
neko259
Truncate line breaks
r1786
# Find and close open tags
if match_count > arg:
neko259
Line break truncation: Show truncator in the last line, not new one
r1799 truncate_pos = start_pos
neko259
Truncate line breaks
r1786
open_tags = []
text = value[:truncate_pos]
current_pos = 0
while True:
tag = re_tag.search(text, current_pos)
if tag is None:
break
else:
closing_tag, tagname, self_closing = tag.groups()
tagname = tagname.lower()
if self_closing or tagname in HTML4_SINGLETS:
pass
elif closing_tag:
# Check for match in open tags list
try:
i = open_tags.index(tagname)
except ValueError:
pass
else:
# SGML: An end tag closes, back to the matching start tag,
# all unclosed intervening start tags with omitted end tags
open_tags = open_tags[i + 1:]
else:
# Add it to the start of the open tags list
open_tags.insert(0, tagname)
current_pos = tag.end()
neko259
First add the truncator (if there is none in the text itself), then closing tags
r1788 if not text.endswith(TRUNCATOR):
text += TRUNCATOR
neko259
Truncate line breaks
r1786 for tag in open_tags:
neko259
Fixed closing tags in newlines truncator
r1792 text += '</{}>'.format(tag)
neko259
Truncate line breaks
r1786 else:
text = value
return text