Esempio n. 1
0
 def test_create_new_mapStory(self):
     user = User.objects.create_user(username='******',
                                     email='*****@*****.**',
                                     password='******')
     mapstory = MapStory()
     self.assertIsInstance(mapstory, MapStory)
     mapstory.title = "Test story"
     mapstory.owner = user
     mapstory.save()
    def handle(self, *args, **options):
        # private function to launder story name in case it contains special characters
        def launder(string):

            return re.sub('[^0-9a-zA-Z]+', '_', string.lower())

        old_stories = Map.objects.filter(story__isnull=True)
        stories_updated = 0

        if old_stories.exists():

            for old_story in old_stories.iterator():

                # create the new story model object, populating it with data from old map in some cases.
                new_story = MapStory(owner=old_story.owner,
                                     title=old_story.title,
                                     abstract=old_story.abstract)
                new_story_print = launder(new_story.title)
                if options['dry-run'] is False:
                    new_story.save()
                    new_story.set_default_permissions()
                else:
                    self.stdout.write(
                        'New Mapstory Object: {0}'.format(new_story_print))
                    self.stdout.write('Title: {0}'.format(new_story_print))

                # create the foreign key link to the new story and set it to the first chapter
                old_story.story = new_story
                old_story.chapter_index = 0
                if options['dry-run'] is False:
                    old_story.save()

                stories_updated += 1
                if options['dry-run'] is False:
                    self.stdout.write(
                        'Converted old mapstory: {0}'.format(new_story_print))
                else:
                    self.stdout.write(
                        'Converted old mapstory: {0}, but did not save'.format(
                            new_story_print))

            self.stdout.write(
                '{0} stories converted to new model'.format(stories_updated))

        else:
            self.stdout.write('No Chapters found without a Mapstory')
Esempio n. 3
0
    def test_create_new_mapStory(self):
        user = User.objects.create_user(username='******',
                                        email='*****@*****.**',
                                        password='******')
        """
        Can compose a story

        *  New story form:
            - Title (text)(required)
            - Summary (text)
            - Category (dropdown) 'Health'
            - Tags (text)
            - Location (dropdown) 'Africa'
        """
        # Should create an instance of mapstory
        mapstory = MapStory()
        self.assertIsInstance(mapstory, MapStory)
        mapstory.title = "Test story"
        mapstory.owner = user
        mapstory.save()
Esempio n. 4
0
    def test_save_story_draft(self):
        """
        Can save draft story
        """
        user = User.objects.create_user(username='******',
                                        email='*****@*****.**',
                                        password='******')
        mapstory = MapStory()
        self.assertIsInstance(mapstory, MapStory)
        mapstory.title = "Test story"
        mapstory.owner = user
        mapstory.save()

        testMap = Map()
        testMap.story = mapstory
        testMap.zoom = 3
        testMap.projection = "EPSG:900913"
        testMap.center_x = -7377090.47385893
        testMap.center_y = 3463514.6256579063
        testMap.owner = user
        testMap.save()
Esempio n. 5
0
 def setUp(self):
     self.mapstory = MapStory()
     self.assertIsInstance(self.mapstory, MapStory,
                           "Should be instance of MapStory")
     self.mapstory.title = "Test story"
     self.mapstory.owner = testUser