codekasten/tycker/helpers.py

32 lines
960 B
Python

import creoleparser
import genshi
import datetime
from settings import DATE_FORMAT_SHORT, DATE_FORMAT_FULL
def formatter(text):
if not text:
return u""
text = text.replace("\\", "\\\\")
html = creoleparser.text2html(text, encoding=None).strip()
if html.startswith("<p>") and html.endswith("</p>"):
html = html[3:-4]
return genshi.Markup(html)
last_day = datetime.datetime.today() - datetime.timedelta(days=1)
def show_timestamp(date):
if date <= last_day:
template = DATE_FORMAT_SHORT
else:
template = DATE_FORMAT_FULL
return date.strftime(template)
def nav_links(prev_link, next_link):
result = []
if prev_link:
result.append('<a href="%s" title="zeige neuere Eintr&auml;ge">aktuellere</a>' % prev_link)
if next_link:
result.append('<a href="%s" title="zeige &auml;ltere Eintr&auml;ge">&auml;ltere</a>' % next_link)
return genshi.Markup(" | ".join(result))