コード例 #1
0
ファイル: tests.py プロジェクト: magnusbraaten/tassen
    def generic_story(
            self,
            header=None,
            body=None,
            postscriptum=None,
            story_type='new story type',
            section='new section'):
        new_section, new = Section.objects.get_or_create(title=section)
        new_story_type, new = StoryType.objects.get_or_create(name=story_type, section=new_section)

        header = header or '''
        @tit: A New Story
        '''
        body = body or '''
        @mt: Pitchfork Schlitz fixie hoodie
        Gastropub YOLO small batch kitsch. Fingerstache direct trade messenger bag, freegan 3 wolf moon squid Truffaut.
        Distillery vinyl, Bushwick vegan deep v street art roof party normcore. Direct trade craft beer banh mi selvage.
        Neutra lo-fi drinking vinegar, cold-pressed selvage Kickstarter Schlitz literally distillery food.
        @mt: Truck vegan meditation farm-to-table authentic.
        @txt:Crucifix beard cred, hoodie ennui sustainable blog before they sold out small batch squid biodiesel.
        Tote bag XOXO Wes Anderson 3 wolf moon. Marfa vegan health goth Neutra drinking vinegar.
        @mt:Fingerstache quinoa High Life
        Put a bird on it PBR&B four loko master cleanse Shoreditch single-origin coffee DIY sriracha.
        Lomo normcore food truck put a bird on it Bushwick Schlitz ugh Brooklyn McSweeney's fashion axe.
        Farm-to-table Tonx banjo, gluten-free leggings master cleanse kogi keytar normcore pour-over tofu sartorial.
        '''
        postscriptum = postscriptum or '''
        @bl:foto:Bob cameraguy; text:  Liza Writer Genious
        '''

        bodytext = '{}\n{}\n{}'.format(header, body, postscriptum)
        bodytext = re.sub(r'\s*\n\s*', '\n', bodytext)
        new_story = Story(bodytext_markup=bodytext, story_type=new_story_type)
        new_story.save()
        return new_story
コード例 #2
0
def test_new_story(news):
    """It's possible to create an empty story"""
    empty_story = Story(story_type=news)
    empty_story.save()
    assert empty_story.id is not None
    html = empty_story.get_html()
    assert len(html) > 0
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
ファイル: test_new_story.py プロジェクト: universitas/tassen
def another_hope():
    story = Story(
        title='Another Hope',
        kicker='Episode IV',
        lede="""
        It is a period of civil war.
        Rebel spaceships, striking
        from a hidden base, have won
        their first victory against
        the evil Galactic Empire.
        """,
        bodytext_markup="""
        @txt:During the battle, Rebel
        spies managed to steal secret
        plans to the Empire's
        ultimate weapon, the DEATH
        STAR, an armored space
        station with enough power
        to destroy an entire planet.

        @txt:Pursued by the Empire's
        sinister agents, Princess
        Leia races home aboard her
        starship, custodian of the
        stolen plans that can save her
        people and restore
        freedom to the galaxy....
        """
    )
    story.save()
    Byline.create('text: George Lucas, film director', story)
    return story
コード例 #6
0
def another_hope():
    story = Story(title='Another Hope',
                  kicker='Episode IV',
                  lede="""
        It is a period of civil war.
        Rebel spaceships, striking
        from a hidden base, have won
        their first victory against
        the evil Galactic Empire.
        """,
                  bodytext_markup="""
        @txt:During the battle, Rebel
        spies managed to steal secret
        plans to the Empire's
        ultimate weapon, the DEATH
        STAR, an armored space
        station with enough power
        to destroy an entire planet.

        @txt:Pursued by the Empire's
        sinister agents, Princess
        Leia races home aboard her
        starship, custodian of the
        stolen plans that can save her
        people and restore
        freedom to the galaxy....
        """)
    story.save()
    Byline.create('text: George Lucas, film director', story)
    return story
コード例 #7
0
ファイル: tests.py プロジェクト: magnusbraaten/tassen
    def generic_story(self,
                      header=None,
                      body=None,
                      postscriptum=None,
                      story_type='new story type',
                      section='new section'):
        new_section, new = Section.objects.get_or_create(title=section)
        new_story_type, new = StoryType.objects.get_or_create(
            name=story_type, section=new_section)

        header = header or '''
        @tit: A New Story
        '''
        body = body or '''
        @mt: Pitchfork Schlitz fixie hoodie
        Gastropub YOLO small batch kitsch. Fingerstache direct trade messenger bag, freegan 3 wolf moon squid Truffaut.
        Distillery vinyl, Bushwick vegan deep v street art roof party normcore. Direct trade craft beer banh mi selvage.
        Neutra lo-fi drinking vinegar, cold-pressed selvage Kickstarter Schlitz literally distillery food.
        @mt: Truck vegan meditation farm-to-table authentic.
        @txt:Crucifix beard cred, hoodie ennui sustainable blog before they sold out small batch squid biodiesel.
        Tote bag XOXO Wes Anderson 3 wolf moon. Marfa vegan health goth Neutra drinking vinegar.
        @mt:Fingerstache quinoa High Life
        Put a bird on it PBR&B four loko master cleanse Shoreditch single-origin coffee DIY sriracha.
        Lomo normcore food truck put a bird on it Bushwick Schlitz ugh Brooklyn McSweeney's fashion axe.
        Farm-to-table Tonx banjo, gluten-free leggings master cleanse kogi keytar normcore pour-over tofu sartorial.
        '''
        postscriptum = postscriptum or '''
        @bl:foto:Bob cameraguy; text:  Liza Writer Genious
        '''

        bodytext = '{}\n{}\n{}'.format(header, body, postscriptum)
        bodytext = re.sub(r'\s*\n\s*', '\n', bodytext)
        new_story = Story(bodytext_markup=bodytext, story_type=new_story_type)
        new_story.save()
        return new_story
コード例 #8
0
def test_new_story(news):
    """It's possible to create an empty story"""
    empty_story = Story(story_type=news)
    empty_story.save()
    assert empty_story.id is not None
    html = empty_story.get_html()
    assert len(html) > 0
コード例 #9
0
def test_create_story_from_xtags(news):
    source = """
    @tit:Hello World!
    @ing:A test story for you
    @txt:This story will rock the world!
    """
    new_story = Story(
        story_type=news,
        bodytext_markup=source,
    )
    tag_count = BlockTag.objects.count()
    assert tag_count == 20
    new_story.clean()
    new_story.save()

    assert new_story.title == 'Hello World!'
    assert new_story.lede == 'A test story for you'
    assert 'bodytext' in new_story.get_html()
コード例 #10
0
def test_create_story_from_xtags(news):
    source = """
    @tit:Hello World!
    @ing:A test story for you
    @txt:This story will rock the world!
    """
    new_story = Story(
        story_type=news,
        bodytext_markup=source,
    )
    tag_count = BlockTag.objects.count()
    assert tag_count == 20
    new_story.clean()
    new_story.save()

    assert new_story.title == 'Hello World!'
    assert new_story.lede == 'A test story for you'
    assert 'bodytext' in new_story.get_html()
コード例 #11
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(new=True)
    return story
コード例 #12
0
ファイル: content_factory.py プロジェクト: universitas/tassen
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
コード例 #13
0
def _importer_websak(websak):
    """ Import a single story from legacy website. """
    global count
    count += 1

    # check if story exists
    try:
        old_story = Story.objects.get(id=websak.id_sak)
        logger.warn(
            '{:>5} story already exists: {} {}'.format(
                count,
                old_story,
                old_story.pk))
        return old_story
    except Story.DoesNotExist:
        pass

    # check whether this story has a parent story
    try:
        new_websak = Sak.objects.get(undersak=websak.pk)
        logger.warn(
            '{:>5} Has parent: {} {}'.format(
                count,
                new_websak.pk,
                websak.pk))
        return _importer_websak(new_websak)
    except Sak.DoesNotExist:
        pass
    except Sak.MultipleObjectsReturned:
        if websak.pk == 0:
            pass

    new_story = Story(
        id=websak.id_sak,
        publication_date=_make_aware(websak.dato),
        story_type=_get_story_type(websak.mappe),
        legacy_html_source=serializers.serialize('json', (websak,)),
        hit_count=websak.lesninger,
    )

    try:
        prodsak_id = int(websak.filnavn)
    # No integer prodsak_id means that this article does not exist in prodsys.
    except (TypeError, ValueError):
        prodsak_id = None

    new_story.prodsak_id = prodsak_id

    try:  # import this story from prodsys
        prodsak = _get_xtags_from_prodsys(
            prodsak_id=prodsak_id,
            status_in=[
                Prodsak.READY_FOR_WEB,
                Prodsak.PUBLISHED_ON_WEB,
                Prodsak.ARCHIVED,
            ])
    except Prodsak.DoesNotExist:  # couldn't find the story in prodsys
        pass
    else:
        new_story.bodytext_markup = prodsak[0]
        new_story.publication_status = prodsak[1]
        new_story.prodsys_json = prodsak[2]

    if new_story.publication_status != Story.STATUS_PUBLISHED:
        # prodsys story cannot be used for import.
        # It was not found, never existed, or is malformed.
        # create xtags from the legacy website story instead.
        new_story.bodytext_markup = _websak_til_xtags(websak)
        new_story.publication_status = Story.STATUS_PUBLISHED
        if websak.undersak:
            try:
                undersak = Sak.objects.get(pk=websak.undersak)
                xtags = _websak_til_xtags(undersak).replace(
                    '@tit:',
                    '@undersaktit:')
                new_story.bodytext_markup += '\n' + xtags
                logger.debug(
                    'undersak: {} len:{}'.format(
                        websak.undersak,
                        len(xtags)))
            except Sak.DoesNotExist:
                # Dangling reference in database.
                pass
    new_story.save()
    new_story.clean()
    new_story.save()
    logger.debug(
        '{:>5} story saved: {} {}'.format(
            count,
            new_story,
            new_story.pk))
    return new_story
コード例 #14
0
def _importer_websak(websak):
    """ Import a single story from legacy website. """
    global count
    count += 1

    # check if story exists
    try:
        old_story = Story.objects.get(id=websak.id_sak)
        logger.warn('{:>5} story already exists: {} {}'.format(
            count, old_story, old_story.pk))
        return old_story
    except Story.DoesNotExist:
        pass

    # check whether this story has a parent story
    try:
        new_websak = Sak.objects.get(undersak=websak.pk)
        logger.warn('{:>5} Has parent: {} {}'.format(count, new_websak.pk,
                                                     websak.pk))
        return _importer_websak(new_websak)
    except Sak.DoesNotExist:
        pass
    except Sak.MultipleObjectsReturned:
        if websak.pk == 0:
            pass

    new_story = Story(
        id=websak.id_sak,
        publication_date=_make_aware(websak.dato),
        story_type=_get_story_type(websak.mappe),
        legacy_html_source=serializers.serialize('json', (websak, )),
        hit_count=websak.lesninger,
    )

    try:
        prodsak_id = int(websak.filnavn)
    # No integer prodsak_id means that this article does not exist in prodsys.
    except (TypeError, ValueError):
        prodsak_id = None

    new_story.prodsak_id = prodsak_id

    try:  # import this story from prodsys
        prodsak = _get_xtags_from_prodsys(prodsak_id=prodsak_id,
                                          status_in=[
                                              Prodsak.READY_FOR_WEB,
                                              Prodsak.PUBLISHED_ON_WEB,
                                              Prodsak.ARCHIVED,
                                          ])
    except Prodsak.DoesNotExist:  # couldn't find the story in prodsys
        pass
    else:
        new_story.bodytext_markup = prodsak[0]
        new_story.publication_status = prodsak[1]
        new_story.prodsys_json = prodsak[2]

    if new_story.publication_status != Story.STATUS_PUBLISHED:
        # prodsys story cannot be used for import.
        # It was not found, never existed, or is malformed.
        # create xtags from the legacy website story instead.
        new_story.bodytext_markup = _websak_til_xtags(websak)
        new_story.publication_status = Story.STATUS_PUBLISHED
        if websak.undersak:
            try:
                undersak = Sak.objects.get(pk=websak.undersak)
                xtags = _websak_til_xtags(undersak).replace(
                    '@tit:', '@undersaktit:')
                new_story.bodytext_markup += '\n' + xtags
                logger.debug('undersak: {} len:{}'.format(
                    websak.undersak, len(xtags)))
            except Sak.DoesNotExist:
                # Dangling reference in database.
                pass
    new_story.save()
    new_story.clean()
    new_story.save()
    logger.debug('{:>5} story saved: {} {}'.format(count, new_story,
                                                   new_story.pk))
    return new_story