Ejemplo n.º 1
0
def migrate_country_to_geoarea(legacy_country):
    print(term.green("\tMigrating Country: {0}".format(legacy_country.country)))
    if legacy_country.pk == 27:
        # duplicate for Slovenia / Yugoslavia that is not to be migrated.
        return None
    this_legacy_id = "legacy_country.{0}".format(int(legacy_country.pk))
    d = {"type": GeographicArea.COUNTRY, "name": legacy_country.country, "parent": None}

    c = GeographicArea(**d)
    c.save()
    lid = LegacyId(name=this_legacy_id)
    lid.save()
    c.legacy_id.add(lid)
    c.save()

    print(term.green("\tMigrated {0} to new Geo Area ID {1}".format(legacy_country.country, c.pk)))
Ejemplo n.º 2
0
def migrate_city_to_geoarea(legacy_city):
    print(term.green("\tMigrating City: {0}".format(legacy_city.city)))

    country_legacy_id = "legacy_country.{0}".format(int(legacy_city.country.pk))
    country = GeographicArea.objects.get(legacy_id__name=country_legacy_id)
    this_legacy_id = "legacy_city.{0}".format(int(legacy_city.pk))

    d = {"type": GeographicArea.CITY, "name": legacy_city.city, "parent": country}
    c = GeographicArea(**d)
    c.save()

    lid = LegacyId(name=this_legacy_id)
    lid.save()
    c.legacy_id.add(lid)
    c.save()

    print(term.green("\tMigrated {0} to new Geo Area ID {1}".format(legacy_city.city, c.pk)))
Ejemplo n.º 3
0
def migrate_provenance_to_geoarea(entry):
    print(term.green("\tMigrating provenance ID {0} to geo area {1}".format(entry.pk, entry.country)))
    # This should ensure that we can look up countries by name or by ID later.
    this_legacy_id = "legacy_provenance.{0}".format(int(entry.pk))
    try:
        area = GeographicArea.objects.get(name=entry.country)
        # area.legacy_id = "{0}, legacy_provenance.{1}".format(area.legacy_id, int(entry.pk))
        lid = LegacyId(name=this_legacy_id)
        lid.save()
        area.legacy_id.add(lid)
        area.save()
    except GeographicArea.DoesNotExist:
        print(term.red("\tArea {0} does not exist...".format(entry.country)))
        d = {"type": GeographicArea.REGION, "name": entry.country}
        ga = GeographicArea(**d)
        ga.save()

        lid = LegacyId(name=this_legacy_id)
        lid.save()
        ga.legacy_id.add(lid)
        ga.save()
Ejemplo n.º 4
0
def migrate_source_provenance(entry):
    print(term.green("\tMigrating Source Provenance ID {0}".format(int(entry.pk))))
    note = "Original: "
    source = Source.objects.get(pk=int(entry.sourcekey))
    legacy_id = "legacy_provenance.{0}".format(int(entry.alprovenancekey))

    country = None
    try:
        country = GeographicArea.objects.get(legacy_id__name=legacy_id)
    except GeographicArea.DoesNotExist:
        raise ("Could not determine provenance country with ID {0}. Bailing".format(int(entry.alprovenancekey)))

    note = "{0} {1} ({2})".format(note, country.name, entry.alprovenancekey)

    city = None
    if entry.city:
        cname = entry.city.rstrip("?")
        lid = "legacy_source_provenance_city.{0}_{1}".format(entry.alprovenancekey, cname.lower())

        try:
            city = GeographicArea.objects.get(legacy_id__name=lid)
        except GeographicArea.DoesNotExist:
            try:
                print(term.red("\tCity may not exist. Checking by name {0}, {1}.".format(cname, country.name)))
                city = GeographicArea.objects.get(name=cname, parent=country)
                lgid = LegacyId(name=lid)
                lgid.save()
                city.legacy_id.add(lgid)
                city.save()
            except GeographicArea.DoesNotExist:
                print(term.red("\tCity {0} does not exist. Attempting to create.".format(cname)))
                d = {"type": GeographicArea.CITY, "name": cname, "parent": country}
                city = GeographicArea(**d)
                city.save()
                lgid = LegacyId(name=lid)
                lgid.save()
                city.legacy_id.add(lgid)
                city.save()

        note = note + " " + entry.city

    organization = None
    if entry.institution:
        orgname = entry.institution.strip("? ")
        try:
            organization = Organization.objects.get(name=orgname)
        except Organization.DoesNotExist:
            print(term.red("\tOrganization {0} does not exist. Attempting to create.".format(orgname)))
            location = city if city else country
            d = {
                "name": orgname,
                "location": location,
                "legacy_id": "legacy_source_provenance.{0}".format(int(entry.pk)),
            }
            organization = Organization(**d)
            organization.save()

        note = note + " " + entry.institution

    region = None
    if entry.region:
        regname = entry.region.strip("?")
        legacy_id = "legacy_source_provenance_region.{0}_{1}".format(entry.alprovenancekey, regname.lower())

        try:
            region = GeographicArea.objects.get(legacy_id__name=legacy_id)
        except GeographicArea.DoesNotExist:
            try:
                region = GeographicArea.objects.get(name=regname)
                lgid = LegacyId(name=legacy_id)
                lgid.save()
                region.legacy_id.add(lgid)
            except GeographicArea.DoesNotExist:
                d = {"name": regname, "type": GeographicArea.REGION, "parent": country}
                region = GeographicArea(**d)
                region.save()
                lgid = LegacyId(name=legacy_id)
                lgid.save()
                region.legacy_id.add(lgid)
                region.save()

            note = note + " " + entry.region

    protectorate = None
    if entry.protectorate:
        pname = entry.protectorate.strip("?")
        legacy_id = "legacy_source_provenance_protectorate.{0}_{1}".format(entry.alprovenancekey, pname.lower())

        try:
            protectorate = GeographicArea.objects.get(legacy_id__name=legacy_id)
        except GeographicArea.DoesNotExist:
            try:
                protectorate = GeographicArea.objects.get(name=pname, type=GeographicArea.REGION)
                lgid = LegacyId(name=legacy_id)
                lgid.save()
                protectorate.legacy_id.add(lgid)
                protectorate.save()
            except GeographicArea.DoesNotExist:
                d = {"name": pname, "type": GeographicArea.REGION, "parent": country}
                protectorate = GeographicArea(**d)
                protectorate.save()
                lgid = LegacyId(name=legacy_id)
                lgid.save()
                protectorate.legacy_id.add(lgid)
                protectorate.save()

            note = note + " " + entry.protectorate

    sp = {
        "source": source,
        "country": country,
        "country_uncertain": convert_yn_to_boolean(entry.uncertain),
        "city": city,
        "city_uncertain": convert_yn_to_boolean(entry.city_uncertain),
        "protectorate": protectorate,
        "region": region,
        "region_uncertain": convert_yn_to_boolean(entry.region_uncertain),
        "note": note,
    }

    if organization:
        # Generic Foreign Keys don't like None
        sp.update({"entity": organization, "entity_uncertain": convert_yn_to_boolean(entry.institution_uncertain)})

    spe = SourceProvenance(**sp)
    spe.save()