class PostFormatter(object): """ Base post formatting object. If used as a post formatter itself, performs basic formatting, preserving linebreaks and converting URLs to links. """ QUICK_HELP_TEMPLATE = 'forum/help/basic_formatting_quick.html' FULL_HELP_TEMPLATE = 'forum/help/basic_formatting.html' def __init__(self, emoticons=None): if emoticons is None: emoticons = {} self.emoticon_processor = Emoticons(emoticons, base_url='%sforum/img/emoticons/' % settings.STATIC_URL) def format_post(self, body, process_emoticons=True): """ Formats the given post body, replacing emoticon symbols with images if ``emoticons`` is ``True``. """ if process_emoticons: return self.emoticon_processor.process(self.format_post_body(body)) else: return self.format_post_body(body) def format_post_body(self, body): """ Formats the given raw post body as HTML. """ return linebreaks(urlize(escape(body.strip()))) def quote_post(self, post): """ Returns a raw post body which quotes the given Post. """ return u'%s wrote:\n\n%s\n\n' % ( escape(post.user.username), quote_post_re.sub('> ', wrap(normalize_newlines(post.body), 80)), )
class PostFormatter(object): """ Base post formatting object. If used as a post formatter itself, performs basic formatting, preserving linebreaks and converting URLs to links. """ QUICK_HELP_TEMPLATE = 'forum/help/basic_formatting_quick.html' FULL_HELP_TEMPLATE = 'forum/help/basic_formatting.html' def __init__(self, emoticons=None): if emoticons is None: emoticons = {} self.emoticon_processor = Emoticons(emoticons, base_url='%simg/forum/emoticons/' % settings.MEDIA_URL) def format_post(self, body, process_emoticons=True): """ Formats the given post body, replacing emoticon symbols with images if ``emoticons`` is ``True``. """ if process_emoticons: return self.emoticon_processor.process(self.format_post_body(body)) else: return self.format_post_body(body) def format_post_body(self, body): """ Formats the given raw post body as HTML. """ return linebreaks(urlize(escape(body.strip()))) def quote_post(self, post): """ Returns a raw post body which quotes the given Post. """ return u'%s wrote:\n\n%s\n\n' % ( escape(post.user.username), quote_post_re.sub('> ', wrap(normalize_newlines(post.body), 80)), )
def __init__(self, emoticons=None): if emoticons is None: emoticons = {} self.emoticon_processor = Emoticons(emoticons, base_url='%simg/forum/emoticons/' % settings.MEDIA_URL)
def __init__(self, emoticons=None): if emoticons is None: emoticons = {} self.emoticon_processor = Emoticons(emoticons, base_url='%sforum/img/emoticons/' % settings.STATIC_URL)