コード例 #1
0
def update_page_notes():
    PageNote.objects.all().delete()
    legacy_item_image = LegacyItemImage.objects.filter(Q(decorationstyle__isnull=False) | Q(decorationcolour__isnull=False) | Q(initial__isnull=False) | Q(initialcolour__isnull=False))

    for entry in legacy_item_image:
        print("Updating entry {0}".format(entry.pk))

        try:
            page = Page.objects.get(legacy_id="legacy_image.{0}".format(int(entry.imagekey)))
        except Page.DoesNotExist:
            print('page could not be found')
            continue

        note_fields = (
            (PageNote.DECORATION_COLOUR, entry.decorationstyle),
            (PageNote.DECORATION_COLOUR, entry.decorationcolour),
            (PageNote.INITIAL, entry.initial),
            (PageNote.INITIAL_COLOUR, entry.initialcolour)
        )

        for nt in note_fields:
            if not nt[1]:
                continue

            d = {
                'type': nt[0],
                'note': nt[1],
                'page': page
            }
            pgn = PageNote(**d)
            pgn.save()
コード例 #2
0
def attach_item_to_page(entry):
    print(term.green("\tAttaching item {0} to image {1} (relationship {2})".format(entry.itemkey, entry.imagekey, entry.pk)))
    item_pk = int(entry.itemkey)

    # These items have an image attached to it, and they shouldn't really. Skip them.
    if item_pk in (92020, 71686):
        return None

    try:
        item = Item.objects.get(pk=item_pk)
    except Item.DoesNotExist:
        print(term.red("\t\tItem {0} Does not exist".format(item_pk)))
        return None

    image_pk = int(entry.imagekey)
    page = Page.objects.get(legacy_id="legacy_image.{0}".format(image_pk))

    item.pages.add(page)
    item.save()

    note_fields = (
        (PageNote.DECORATION_COLOUR, entry.decorationstyle),
        (PageNote.DECORATION_COLOUR, entry.decorationcolour),
        (PageNote.INITIAL, entry.initial),
        (PageNote.INITIAL_COLOUR, entry.initialcolour)
    )

    for nt in note_fields:
        if not nt[1]:
            continue

        d = {
            'type': nt[0],
            'note': nt[1],
            'page': page
        }
        pgn = PageNote(**d)
        pgn.save()