From e75ef1a95205457c5e42c01e4b3023deb69a6c27 Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 28 Feb 2021 18:28:43 -0500 Subject: [PATCH] fix integrity errors seems some doab ids merged onto handles. Also account for previously converted ids --- core/management/commands/translate_doab_ids.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/management/commands/translate_doab_ids.py b/core/management/commands/translate_doab_ids.py index 9a56d00a..baded557 100644 --- a/core/management/commands/translate_doab_ids.py +++ b/core/management/commands/translate_doab_ids.py @@ -1,4 +1,5 @@ import csv +import json from django.core.management.base import BaseCommand from regluit.core.models import Identifier @@ -6,16 +7,23 @@ from regluit.core.models import Identifier class Command(BaseCommand): help = "translate doab ids to handles" def add_arguments(self, parser): - parser.add_argument('filename', nargs='+', help="filename") + parser.add_argument('filename', nargs='?', help="filename") def handle(self, filename, **options): - with open(filename,'r') as jsonfile: + self.stdout.write("doab ids to start: %s" % Identifier.objects.filter(type='doab').count()) + with open(filename, 'r') as jsonfile: newdoab = json.loads(jsonfile.read()) for doab in Identifier.objects.filter(type='doab'): + if doab.value.startswith("20.500.12854"): + continue if doab.value in newdoab: - doab.value = newdoab[doab.value] - doab.save() + # already done + if Identifier.objects.filter(type='doab', value=newdoab[doab.value]).exists(): + doab.delete() + else: + doab.value = newdoab[doab.value] + doab.save() else: doab.delete() - self.stdout.write("new doab ids loaded!") + self.stdout.write("doab ids at end: %s" % Identifier.objects.filter(type='doab').count())