from django.http import HttpResponse
from django.shortcuts import render
from django.db import connections

import bbcode


def dictfetchall(cursor):
    "Returns all rows from a cursor as a dict"
    desc = cursor.description
    return [
        dict(zip([col[0] for col in desc], row))
        for row in cursor.fetchall()
    ]


def all_news(request):
    cursor = connections['mybb'].cursor()
    cursor.execute("SELECT * FROM mybb_threads JOIN mybb_posts WHERE firstpost=mybb_posts.pid AND mybb_threads.fid=%s AND mybb_threads.visible=1", [3])
    articles = dictfetchall(cursor)
    for article in articles:
        article['html'] = bbcode.render_html(article['message'])

    return render(request, 'news_listing.html', dict(articles=articles))

@@ -117,16 +117,482 @@
 bcode%0A%0A%0A
+def bbcode_img(tag_name, value, options, parent, context):%0A    if tag_name in options and 'x' in options%5Btag_name%5D:%0A        options%5B'width'%5D, options%5B'height'%5D = options%5Btag_name%5D.split('x', 1)%0A        del options%5Btag_name%5D%0A    attrs = ' '.join(%5Bname+'=%22%7B%7D%22' for name in options.keys()%5D)%0A    return ('%3Cimg src=%22%7B%7D%22 '+attrs+' /%3E').format(value, *options.values())%0A%0Abbcode_parser = bbcode.Parser()%0Abbcode_parser.add_formatter(%22img%22, bbcode_img, replace_links=False)%0A%0A%0A
 def dict
@@ -609,16 +609,16 @@
 ursor):%0A
-
     %22Ret
@@ -1075,16 +1075,17 @@
 ticles:%0A
+%0A
         
@@ -1112,20 +1112,22 @@
 code
-.render_html
+_parser.format
 (art

Add support for the [img] tag.