Import von authors.yml verbessert

- möglichst aktualisieren statt neu anlegen
- "inherits" legt zweite Identität am Original an
This commit is contained in:
2026-04-18 17:03:40 +02:00
committed by Hraban Ramm
parent bf3f17cdd9
commit 0dc8a9add1
2 changed files with 30 additions and 17 deletions

View File

@@ -21,6 +21,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`
- ggf. Liederquelle-Daten laden: `python3 manage.py loaddata ../fixtures/fixture.yaml`
- Server starten: `python3 manage.py runserver`
- Öffne http://localhost:8080/admin im Browser

View File

@@ -2,9 +2,7 @@
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)
- Tags
@@ -59,7 +57,17 @@ class Command(BaseCommand):
author.update(data[key])
if not author['name'] and author['trail_name']:
author['name'] = author['trail_name']
p = Person(
if 'inherits' in author:
self.stdout.write('\terbt von %s' % author['inherits'])
oi = Identity.objects.get(author_id = author['inherits'])
orig = data[author['inherits']]
p = oi.person
for akey in self.default_author.keys():
if not author[akey] and akey in orig:
author[akey] = orig[akey]
else:
try:
p, created = Person.objects.update_or_create(
name = author['name'],
full_name = author['full_name'],
name_native = author['name_native_spelling'],
@@ -69,25 +77,29 @@ class Command(BaseCommand):
death_year = author['death_year'],
remarks = author['comment'],
)
p.save()
pi = Identity(
except Person.MultipleObjectsReturned as e:
ps = Person.objects.filter(name = author['name'])
self.stdout.write("\tist doppelt:")
self.stdout.write(str(author))
self.stdout.write(str(ps))
p = ps[0]
#raise e
pi, created = Identity.objects.update_or_create(
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(
pai, created = AuthorID.objects.update_or_create(
person = p,
key = AuthorID.IDs.__dict__[service.upper()],
value = author[dbkey],
)
pai.save()
# for poll_id in options["poll_ids"]: