Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrote a small python-script to combine a xml skeleton and a plain-xml-django-template into an rdmo-readable view-template file. #289

Open
wants to merge 2 commits into
base: master-rdmo2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tools/templaterenderer-djangotemplates/README.md
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 28 additions & 0 deletions tools/templaterenderer-djangotemplates/demo.django
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% load view_tags %}
{% get_set 'project/dataset' as datasets %}

<head>
{% get_value 'project/title' as title %}
<title>{{ title.value }}</title>
<h1>{% render_value 'project/title' %}</h1>

<div class="alert alert-info" role="alert">
<p><b>Hinweis</b></p>
<i><p>Im Folgenden haben wir die von Ihnen eingegebenen Informationen über das
Projekt noch einmal zusammengefasst.</p>
<p>Bitte beachten Sie, dass diese Ansicht nochmals überprüft und bei Bedarf
überarbeitet werden sollte.</p></i>
</div>

<hr noshade color=rgb(0, 157, 129) width=100% size=20>
</head>


<body>
<h1>Umgang mit Forschungsdaten</h1>
<h2>Datenbeschreibung</h2>

{% comment "question" %}
<h3>Auf welche Weise entstehen in Ihrem Projekt neue Daten?</h3>
{% endcomment %}
</body>
24 changes: 24 additions & 0 deletions tools/templaterenderer-djangotemplates/demo.xmlskeleton
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<rdmo xmlns:dc="http://purl.org/dc/elements/1.1/" created="2024-03-12T15:06:45.930126+01:00"
version="2.0.0">
<view dc:uri="https://rdmorganiser.github.io/terms/views/templaterenderer">
<uri_prefix>https://rdmorganiser.github.io/terms</uri_prefix>
<uri_path>templaterenderer</uri_path>
<dc:comment>Entwurf für den DFG-Checkliste-Katalog der RDMO-AG. **Nicht** kompatibel mit dem
DFG-Checkliste-Katalog von Fodako.</dc:comment>
<order>0</order>
<title lang="en">templaterenderer-view</title>
<help lang="en">templaterenderer-view</help>
<title lang="de">templaterenderer-view</title>
<help lang="de">templaterenderer-view</help>
<title lang="fr">templaterenderer-view</title>
<help lang="fr">templaterenderer-view</help>
<title lang="it">templaterenderer-view</title>
<help lang="it">templaterenderer-view</help>
<title lang="es">templaterenderer-view</title>
<help lang="es">templaterenderer-view</help>
<catalogs/>
<template>
</template>
</view>
</rdmo>
33 changes: 33 additions & 0 deletions tools/templaterenderer.py
Original file line number Diff line number Diff line change
@@ -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('<','&lt;').replace('>','&gt;')
with open(headerfile, 'r', encoding='utf-8') as open_header:
header_content = open_header.read()
try:
header_start=header_content.rsplit('<template>',1)[0]
header_end=header_content.rsplit('</template>',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 + '<template>\n' + escaped_template + '\n </template>' + header_end
)
print('# Template-file written: {}\n'.format(outfile_path))