Import für authors.yml; Doku verbessert

This commit is contained in:
2026-02-20 15:25:20 +01:00
committed by Hraban Ramm
parent ecc5e66167
commit b1c572803b
6 changed files with 119 additions and 3 deletions

View File

@@ -17,3 +17,8 @@ und für die öffentliche Rechercheplattform.
- Django 6.0
- django-taggit
- django-taggit-helpers (uralt, funktioniert aber)
- PyYAML
# Installation
Siehe [docs/README.md](src/branch/main/docs/README.md)

View File

@@ -4,7 +4,7 @@
Wir entwickeln auf Python 3.14. Python 3.12+ funktioniert, ältere haben zumindest Probleme mit Frescobaldi, was hiermit nichts zu tun hat…
- Python installieren von [https://www.python.org/downloads/]
- Python installieren von [python.org](https://www.python.org/downloads/)
- `git clone ssh://git@git.notenbund.de:9922/Notenbund/liederquelle.git`
- `cd liederquelle`
- Python virtual environment (Venv) anlegen: `python3.14 -m venv .venv`
@@ -22,7 +22,7 @@ Wir entwickeln auf Python 3.14. Python 3.12+ funktioniert, ältere haben zuminde
- Datenbank (SQLite) anlegen: `python3 manage.py makemigrations quellen; python3 manage.py migrate`
- Admin anlegen: `python3 manage.py createsuperuser`
- Server starten: `python3 manage.py runserver`
- Öffne [http://localhost:8080/admin] im Browser
- Öffne http://localhost:8080/admin im Browser
Statt `python3 manage.py` müsste auch der direkte Aufruf des Skripts funktionieren, also `./manage.py`.
@@ -35,4 +35,9 @@ Statt `python3 manage.py` müsste auch der direkte Aufruf des Skripts funktionie
- `cd liederquelle`
- Datenbankstruktur aktualisieren: `python3 manage.py makemigrations quellen; python3 manage.py migrate`
- Server starten: `python3 manage.py runserver`
- Öffne [http://localhost:8080/admin] im Browser
- Öffne http://localhost:8080/admin im Browser
## Im- und Export
- YAML exportieren: `./manage.py dumpdata --format yaml --indent 2 -o ../fixtures/fixture.yaml`
- `authors.yaml` importieren: `.\manage.py import_authors <Pfad>`

View File

@@ -0,0 +1,103 @@
"""
Import für `authors.yml` aus `lilypond-song-includes`
TODO:
- inherits (sollte 2. Identität für eine Person anlegen)
- details_secret
- aktualisieren statt neu anlegen
- Import direkt aus dem git
- Keine Lösung für trail_name_native_spelling (sehr selten)
"""
import sys
import copy
from pathlib import Path
from django.core.management.base import BaseCommand, CommandError
from quellen.models import Person, Identity, AuthorID #, AuthorURL, Contact, Medium
from yaml import safe_load, dump
class Command(BaseCommand):
help = "Importiere `lilypond-song-includes/data/authors.yml`; anzugeben ist das Verzeichnis, in dem `lilypond-song-includes liegt`"
# TODO: Import aus dem git
default_filename = 'authors.yml'
default_subpath = 'lilypond-song-includes/data/'
default_author = {
'name': '',
'full_name': '',
'name_native_spelling': '',
'birth_name': '',
'birth_year': '',
'death_year': '',
'comment': '',
'trail_name': '',
'organization': '',
}
def add_arguments(self, parser):
parser.add_argument("source", nargs="?", type=str, help='Quelle der Importdatei')
def handle(self, *args, **options):
authors = Path(options['source']).resolve()
if authors.is_dir:
a = Path(authors / self.default_filename)
self.stdout.write("Suche %s" % a)
if not a.is_file:
a = Path(authors / Path(self.default_subpath) / self.default_filename)
self.stdout.write("Suche %s" % a)
if not a.is_file:
self.stderr.write('Keine Autoren gefunden in "%s"' % authors)
sys.exit(1)
authors = a
with open(authors, mode='r') as inputfile:
data = safe_load(inputfile)
for key in data:
self.stdout.write(key)
author = copy.copy(self.default_author)
author.update(data[key])
if not author['name'] and author['trail_name']:
author['name'] = author['trail_name']
p = Person(
name = author['name'],
full_name = author['full_name'],
name_native = author['name_native_spelling'],
birth_name = author['birth_name'],
details_secret = False,
birth_year = author['birth_year'],
death_year = author['death_year'],
remarks = author['comment'],
)
p.save()
pi = Identity(
person = p,
author_id = key,
alias = author['trail_name'],
organization = author['organization'],
)
pi.save()
for service in 'gnd isni orcid viaf wiki discogs lied brainz'.split():
dbkey = service
if service=='wiki':
dbkey = 'wikidata'
if dbkey in author and author[dbkey]:
pai = AuthorID(
person = p,
key = AuthorID.IDs.__dict__[service.upper()],
value = author[dbkey],
)
pai.save()
# for poll_id in options["poll_ids"]:
# try:
# poll = Poll.objects.get(pk=poll_id)
# except Poll.DoesNotExist:
# raise CommandError('Poll "%s" does not exist' % poll_id)
#
# poll.opened = False
# poll.save()
#
# self.stdout.write(
# self.style.SUCCESS('Successfully closed poll "%s"' % poll_id)
# )

View File

@@ -1,3 +1,6 @@
pip
pyyaml
django>6,<7
django-dotenv
django-taggit