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 csv
|
||||||
|
import json
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from regluit.core.models import Identifier
|
from regluit.core.models import Identifier
|
||||||
|
@ -6,16 +7,23 @@ from regluit.core.models import Identifier
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "translate doab ids to handles"
|
help = "translate doab ids to handles"
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument('filename', nargs='+', help="filename")
|
parser.add_argument('filename', nargs='?', help="filename")
|
||||||
|
|
||||||
def handle(self, filename, **options):
|
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())
|
newdoab = json.loads(jsonfile.read())
|
||||||
for doab in Identifier.objects.filter(type='doab'):
|
for doab in Identifier.objects.filter(type='doab'):
|
||||||
|
if doab.value.startswith("20.500.12854"):
|
||||||
|
continue
|
||||||
if doab.value in newdoab:
|
if doab.value in newdoab:
|
||||||
|
# already done
|
||||||
|
if Identifier.objects.filter(type='doab', value=newdoab[doab.value]).exists():
|
||||||
|
doab.delete()
|
||||||
|
else:
|
||||||
doab.value = newdoab[doab.value]
|
doab.value = newdoab[doab.value]
|
||||||
doab.save()
|
doab.save()
|
||||||
else:
|
else:
|
||||||
doab.delete()
|
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