X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b2d72160e2a68991c66ea6017b871d7f42c0b29d..351730405960130bae699f5459d440a28c072169:/apps/api/views.py?ds=inline
diff --git a/apps/api/views.py b/apps/api/views.py
old mode 100644
new mode 100755
index 60f00ef0..3e9cb015
--- a/apps/api/views.py
+++ b/apps/api/views.py
@@ -1 +1,38 @@
# Create your views here.
+
+import logging
+log = logging.getLogger('platforma.render')
+
+from django.http import HttpResponse
+import librarian
+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['chunk']
+
+ base, me = path.rsplit('/', 1)
+ match = re.match(r'([^\[]+)\[(\d+)\]', me)
+ tag, pos = match.groups()
+
+ style = etree.parse(style_filename)
+
+ data = u'<%s>%s%s>' % (tag, LINE_SWAP_EXPR.sub(u'
\n', data), tag)
+ log.info(data)
+ doc = etree.parse( StringIO(data) )
+
+ opts = {
+ 'with-paths': 'boolean(1)',
+ 'base-path': "'%s'" % base,
+ 'base-offset': pos,
+ }
+
+ result = doc.xslt(style, **opts)
+ return HttpResponse( librarian.serialize_children(result.getroot()[0]) )
\ No newline at end of file