From 79820ebd08a04298fa9bffae5c2cb1c337ca7d1f Mon Sep 17 00:00:00 2001 From: Janne Jakob Fleischer Date: Thu, 16 Jan 2025 17:13:59 +0100 Subject: [PATCH] Added a small python script that combines a xml-skeleton and the plain-xml-django-template (with handling < and > replacement) --- .../demo.django | 28 ++++++++++++++++ .../demo.xmlskeleton | 24 ++++++++++++++ tools/templaterenderer.py | 33 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tools/templaterenderer-djangotemplates/demo.django create mode 100644 tools/templaterenderer-djangotemplates/demo.xmlskeleton create mode 100644 tools/templaterenderer.py diff --git a/tools/templaterenderer-djangotemplates/demo.django b/tools/templaterenderer-djangotemplates/demo.django new file mode 100644 index 00000000..eab47c7b --- /dev/null +++ b/tools/templaterenderer-djangotemplates/demo.django @@ -0,0 +1,28 @@ +{% load view_tags %} +{% get_set 'project/dataset' as datasets %} + + +{% get_value 'project/title' as title %} +{{ title.value }} +

{% render_value 'project/title' %}

+ + + +
+ + + + +

Umgang mit Forschungsdaten

+

Datenbeschreibung

+ +{% comment "question" %} +

Auf welche Weise entstehen in Ihrem Projekt neue Daten?

+{% endcomment %} + \ No newline at end of file diff --git a/tools/templaterenderer-djangotemplates/demo.xmlskeleton b/tools/templaterenderer-djangotemplates/demo.xmlskeleton new file mode 100644 index 00000000..423cdb80 --- /dev/null +++ b/tools/templaterenderer-djangotemplates/demo.xmlskeleton @@ -0,0 +1,24 @@ + + + + https://rdmorganiser.github.io/terms + templaterenderer + Entwurf für den DFG-Checkliste-Katalog der RDMO-AG. **Nicht** kompatibel mit dem + DFG-Checkliste-Katalog von Fodako. + 0 + templaterenderer-view + templaterenderer-view + templaterenderer-view + templaterenderer-view + templaterenderer-view + templaterenderer-view + templaterenderer-view + templaterenderer-view + templaterenderer-view + templaterenderer-view + + + + \ No newline at end of file diff --git a/tools/templaterenderer.py b/tools/templaterenderer.py new file mode 100644 index 00000000..3bde295f --- /dev/null +++ b/tools/templaterenderer.py @@ -0,0 +1,33 @@ +import glob +import os + +import xml.etree.ElementTree as ET + +files = list(zip( + glob.glob(os.path.join(os.path.dirname(__file__), 'templaterenderer-djangotemplates', '*.django')), + glob.glob(os.path.join(os.path.dirname(__file__), 'templaterenderer-djangotemplates', '*.xmlskeleton')) +)) +for template, headerfile in files: + print('# Working on file pair:') + print(' ' + os.path.abspath(template)) + print(' ' + os.path.abspath(headerfile)) + with open(template, 'r', encoding='utf-8') as open_template: + escaped_template = open_template.read().replace('<','<').replace('>','>') + with open(headerfile, 'r', encoding='utf-8') as open_header: + header_content = open_header.read() + try: + header_start=header_content.rsplit('',1)[1] + except IndexError: + print('# The files do not hold a template-section. We try the next one.\n') + continue + outfile_path = os.path.join(os.getcwd(), 'rdmorganiser/views', os.path.basename(template).rsplit('.',1)[0] + '.xml') + with open( + outfile_path, + 'w', + encoding='utf-8' + ) as xmloutput: + xmloutput.write( + header_start + '' + header_end + ) + print('# Template-file written: {}\n'.format(outfile_path)) \ No newline at end of file