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()
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
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