diff --git a/tools/templaterenderer-djangotemplates/README.md b/tools/templaterenderer-djangotemplates/README.md new file mode 100644 index 00000000..a028fe8b --- /dev/null +++ b/tools/templaterenderer-djangotemplates/README.md @@ -0,0 +1,11 @@ +The script `templaterenderer.py' can be used to combine a django-template in plain xml and a xml-skeleton into one view-template that holds the skeleton and the (partially) html-encoded django-template which can be imported into RDMO. + +just start the script from your command line: + +```bash +python templaterenderer.py +``` + +It looks in the directory templaterenderer-djangotemplates for a pair of files. One ending with `.django`, one with `.xmlskeleton`. + +It exports a file into the shared folder. 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..555a1cda --- /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.path.dirname(__file__), '..', 'shared', 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