X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=qcg%2Ftemplatetags%2Fqcg_utils.py;h=e176eb3b2af9ff048ae94250abad295e9f80a051;hb=0b132bbb365d1ad0dcae15113d01c17146ddf19a;hp=a1b6b52698627c2a960f439eeb71a56317dc5d35;hpb=be5935f45ccaa342c5d057768a5374a8e0921bb3;p=qcg-portal.git diff --git a/qcg/templatetags/qcg_utils.py b/qcg/templatetags/qcg_utils.py index a1b6b52..e176eb3 100644 --- a/qcg/templatetags/qcg_utils.py +++ b/qcg/templatetags/qcg_utils.py @@ -1,8 +1,9 @@ from datetime import datetime, timedelta +from xml.dom import minidom from django import template from django.conf import settings -from django.utils.html import format_html, format_html_join +from django.utils.html import format_html, format_html_join, conditional_escape from django.utils.timesince import timesince from django.utils.timezone import now @@ -40,3 +41,9 @@ def get_params_as_hidden(context, *params): def bootstrap_checkbox(field, label_class=settings.BOOTSTRAP3['horizontal_label_class'], field_class=settings.BOOTSTRAP3['horizontal_field_class']): return {'field': field, 'label_class': label_class, 'field_class': field_class} + + +@register.filter(needs_autoescape=True) +def format_xml(string, autoescape=None): + esc = conditional_escape if autoescape else lambda x: x + return esc(minidom.parseString(string).toprettyxml(indent=' '))