fix integrity errors
seems some doab ids merged onto handles. Also account for previously converted idspull/94/head
parent
4a86646644
commit
e75ef1a952
|
@ -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())
|
||||
|
||||
|
|
Loading…
Reference in New Issue