Esempio n. 1
0
def convert_secondary_image(entry):
    print(term.green("\tMigrating secondary image {0}".format(entry.pk)))
    filename = determine_filename(entry)
    if not filename:
        return None

    orig_image_pk = "legacy_image.{0}".format(int(entry.imagekey))
    try:
        orig_image = Image.objects.get(legacy_id=orig_image_pk)
    except Image.DoesNotExist:
        print(term.red("\t\tImage {0} does not exist. Skipping.".format(orig_image_pk)))
        return None

    page = orig_image.page
    imtype_pk = determine_image_type(entry)
    imtype = ImageType.objects.get(pk=imtype_pk)

    imd = {
        "legacy_id": "legacy_secondary_image.{0}".format(int(entry.pk)),
        "legacy_filename": filename,
        "page": page,
        "type": imtype,
        "public": orig_image.public
    }
    im = Image(**imd)
    im.save()
Esempio n. 2
0
def convert_image(entry):
    print(term.green("\tMigrating image with ID {0} to a Page".format(entry.pk)))
    source = Source.objects.get(pk=int(entry.sourcekey))
    folio = entry.folio if entry.folio else "FIXMEFOLIO"

    d = {
        'numeration': folio,
        'sort_order': entry.orderno,
        'source': source,
        'legacy_id': "legacy_image.{0}".format(entry.pk)
    }

    p = Page(**d)
    p.save()

    filename = determine_filename(entry)

    if filename:
        # create an image record.
        print(term.green("\t\tCreating an Image record for Image {0} ({1})".format(entry.pk, filename)))
        available = convert_yn_to_boolean(entry.availwebsite)
        imtype = ImageType.objects.get(pk=ImageType.PRIMARY)

        imd = {
            'page': p,
            'public': available,
            'type': imtype,
            'legacy_filename': filename,
            'legacy_id': 'legacy_image.{0}'.format(int(entry.pk))
        }

        im = Image(**imd)
        im.save()
    else:
        print(term.yellow("\t\tSkipping {0}".format(filename)))