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` - Datenbank (SQLite) anlegen: `python3 manage.py makemigrations quellen; python3 manage.py migrate`
- Admin anlegen: `python3 manage.py createsuperuser` - Admin anlegen: `python3 manage.py createsuperuser`
- ggf. Liederquelle-Daten laden: `python3 manage.py loaddata ../fixtures/fixture.yaml`
- Server starten: `python3 manage.py runserver` - Server starten: `python3 manage.py runserver`
- Öffne http://localhost:8080/admin im Browser - Öffne http://localhost:8080/admin im Browser

View File

@@ -2,9 +2,7 @@
Import für `authors.yml` aus `lilypond-song-includes` Import für `authors.yml` aus `lilypond-song-includes`
TODO: TODO:
- inherits (sollte 2. Identität für eine Person anlegen)
- details_secret - details_secret
- aktualisieren statt neu anlegen
- Import direkt aus dem git - Import direkt aus dem git
- Keine Lösung für trail_name_native_spelling (sehr selten) - Keine Lösung für trail_name_native_spelling (sehr selten)
- Tags - Tags
@@ -59,35 +57,49 @@ class Command(BaseCommand):
author.update(data[key]) author.update(data[key])
if not author['name'] and author['trail_name']: if not author['name'] and author['trail_name']:
author['name'] = author['trail_name'] author['name'] = author['trail_name']
p = Person( if 'inherits' in author:
name = author['name'], self.stdout.write('\terbt von %s' % author['inherits'])
full_name = author['full_name'], oi = Identity.objects.get(author_id = author['inherits'])
name_native = author['name_native_spelling'], orig = data[author['inherits']]
birth_name = author['birth_name'], p = oi.person
details_secret = False, for akey in self.default_author.keys():
birth_year = author['birth_year'], if not author[akey] and akey in orig:
death_year = author['death_year'], author[akey] = orig[akey]
remarks = author['comment'], else:
) try:
p.save() p, created = Person.objects.update_or_create(
pi = Identity( 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'],
)
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, person = p,
author_id = key, author_id = key,
alias = author['trail_name'], alias = author['trail_name'],
organization = author['organization'], organization = author['organization'],
) )
pi.save()
for service in 'gnd isni orcid viaf wiki discogs lied brainz'.split(): for service in 'gnd isni orcid viaf wiki discogs lied brainz'.split():
dbkey = service dbkey = service
if service=='wiki': if service=='wiki':
dbkey = 'wikidata' dbkey = 'wikidata'
if dbkey in author and author[dbkey]: if dbkey in author and author[dbkey]:
pai = AuthorID( pai, created = AuthorID.objects.update_or_create(
person = p, person = p,
key = AuthorID.IDs.__dict__[service.upper()], key = AuthorID.IDs.__dict__[service.upper()],
value = author[dbkey], value = author[dbkey],
) )
pai.save()
# for poll_id in options["poll_ids"]: # for poll_id in options["poll_ids"]: