def _importer_prodsak(
        prodsak_id,
        replace_existing=False,
        autocrop=False,
        import_images=True):
    """
    Create a Story with images from a prodsak object in the prodsys database.
    """
    # Check if this story has been imported already.
    exists = Story.objects.filter(prodsak_id=prodsak_id)
    if exists:
        if replace_existing:
            exists.delete()
        else:
            return

    # Create a new Story.
    xtags, status, json, prodsak = _get_xtags_from_prodsys(prodsak_id)
    story_type = _get_story_type(prodsak.mappe)
    new_story = Story(
        prodsak_id=prodsak_id,
        bodytext_markup=xtags,
        story_type=story_type,
        publication_status=status,
        legacy_prodsys_source=json,
    )
    new_story.save()
    logger.debug('story saved: {} {}'.format(new_story, new_story.pk))

    # Import images from prodsys to the new Story.
    if import_images:
        _importer_bilder_fra_prodsys(prodsak, new_story, autocrop)

    new_story.full_clean()
    new_story.save(new=True)
Ejemplo n.º 2
0
def _importer_prodsak(prodsak_id,
                      replace_existing=False,
                      autocrop=False,
                      import_images=True):
    """
    Create a Story with images from a prodsak object in the prodsys database.
    """
    # Check if this story has been imported already.
    exists = Story.objects.filter(prodsak_id=prodsak_id)
    if exists:
        if replace_existing:
            exists.delete()
        else:
            return

    # Create a new Story.
    xtags, status, json, prodsak = _get_xtags_from_prodsys(prodsak_id)
    story_type = _get_story_type(prodsak.mappe)
    new_story = Story(
        prodsak_id=prodsak_id,
        bodytext_markup=xtags,
        story_type=story_type,
        publication_status=status,
        legacy_prodsys_source=json,
    )
    new_story.save()
    logger.debug('story saved: {} {}'.format(new_story, new_story.pk))

    # Import images from prodsys to the new Story.
    if import_images:
        _importer_bilder_fra_prodsys(prodsak, new_story, autocrop)

    new_story.full_clean()
    new_story.save(new=True)
def fake_story():
    photo_by = random_contributor()
    text_by = random_contributor()
    markup = '{}\n@bl: text: {}\n@bl: photo:{}'.format(fake_story_content(),
                                                       text_by, photo_by)
    story = Story(
        story_type=random_storytype(),
        bodytext_markup=markup,
        publication_status=Story.STATUS_PUBLISHED,
        publication_date=timezone.now(),
    )
    story.save()
    numphotos = random.choice([0, 1, 1, 3, 5])
    for _ in range(numphotos):
        fake_story_image(story, photo_by)
    story.refresh_from_db()
    story.full_clean()
    story.frontpagestory_set.all().delete()
    story.save(new=True)
    return story
Ejemplo n.º 4
0
def fake_story():
    photo_by = random_contributor()
    text_by = random_contributor()
    markup = '{}\n@bl: text: {}\n@bl: photo:{}'.format(
        fake_story_content(), text_by, photo_by
    )
    story = Story(
        story_type=random_storytype(),
        bodytext_markup=markup,
        publication_status=Story.STATUS_PUBLISHED,
        publication_date=timezone.now(),
    )
    story.save()
    numphotos = random.choice([0, 1, 1, 3, 5])
    for _ in range(numphotos):
        fake_story_image(story, photo_by)
    story.refresh_from_db()
    story.full_clean()
    story.frontpagestory_set.all().delete()
    story.save()
    return story