X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b2d72160e2a68991c66ea6017b871d7f42c0b29d..409a2386cf6f426d093f1fb5c7c5840d4f39fbb5:/apps/api/views.py?ds=sidebyside diff --git a/apps/api/views.py b/apps/api/views.py index 60f00ef0..b96fc470 100644 --- a/apps/api/views.py +++ b/apps/api/views.py @@ -1 +1,41 @@ # Create your views here. + +from django.http import HttpResponse +from librarian import html +from lxml import etree +from StringIO import StringIO +import re + +LINE_SWAP_EXPR = re.compile(r'/\s', re.MULTILINE | re.UNICODE); + +def render(request): + style_filename = html.get_stylesheet('partial') + + data = request.POST['fragment'] + path = request.POST['part'] + + base, me = path.rsplit('/', 1) + match = re.match(r'([^\[]+)\[(\d+)\]', me) + tag, pos = match.groups() + + print "Redner:", path, base, tag, pos + + style = etree.parse(style_filename) + + data = LINE_SWAP_EXPR.sub(u'
\n', data) + doc = etree.parse( StringIO(data) ) + + opts = { + 'with-paths': 'boolean(1)', + 'base-path': "'%s'" % base, + 'base-offset': pos, + } + + print opts + + result = doc.xslt(style, **opts) + + print result + + return HttpResponse( + etree.tostring(result, encoding=unicode, pretty_print=True) ) \ No newline at end of file