-
Notifications
You must be signed in to change notification settings - Fork 39
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
jannefleischer
wants to merge
2
commits into
rdmorganiser:master-rdmo2.x
Choose a base branch
from
jannefleischer:templaterenderer
base: master-rdmo2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('<','<').replace('>','>') | ||
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)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! For the path things I would suggest to use
from pathlib import Path
instead ofos.path
, https://docs.python.org/3.9/library/pathlib.html?highlight=pathlib#module-pathlib