Exemplo n.º 1
0
def new_story_json(request):
    if not request.user.is_authenticated():
        return HttpResponse(
                'You must be logged in to save new maps',
                mimetype="text/plain",
                status=401
        )

    story_obj = MapStory(owner=request.user)
    story_obj.save()
    story_obj.set_default_permissions()

    # If the body has been read already, use an empty string.
    # See https://github.com/django/django/commit/58d555caf527d6f1bdfeab14527484e4cca68648
    # for a better exception to catch when we move to Django 1.7.
    try:
        body = request.body
    except Exception:
        body = ''

    try:
        story_obj.update_from_viewer(body)
    except ValueError as e:
        return HttpResponse(str(e), status=400)
    else:
        return HttpResponse(
                json.dumps({'id': story_obj.id}),
                status=200,
                mimetype='application/json'
        )
Exemplo n.º 2
0
    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')
Exemplo n.º 3
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()
Exemplo n.º 4
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()
Exemplo n.º 5
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()
Exemplo n.º 6
0
class TestMapstory(TestCase):
    """
    Mapstory Model Tests
    """
    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

    def test_save_and_retrieve(self):
        """
        Should save in database
        """
        self.assertEqual(0, MapStory.objects.all().count())
        self.mapstory.save()
        self.assertEqual(1, MapStory.objects.all().count())
        savedMapStory = MapStory.objects.all()[0]
        self.assertEqual(savedMapStory.title, "Test story",
                         "Should have the same title")
        self.assertEqual(savedMapStory.owner, self.mapstory.owner,
                         "Should have the same owner")

    def test_remove(self):
        self.assertEqual(0, MapStory.objects.all().count())
        self.mapstory.save()
        self.assertEqual(1, MapStory.objects.all().count())
        MapStory.objects.filter(id=self.mapstory.id).delete()
        self.assertEqual(0, MapStory.objects.all().count())

    @skip("TODO: Fix")
    def test_get_abosolute_url(self):
        self.assertIsNotNone(self.mapstory.get_absolute_url())

    @skip("TODO: Fix this test")
    def test_update_from_viewer(self):
        conf = {}
        conf.title = "Test"
        conf.abstract = "Test abstract"
        conf.is_published = True
        self.mapstory.update_from_viewer(conf)
    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')
Exemplo n.º 8
0
class TestMapstoryModel(TestCase):
    """
    Mapstory Model Tests
    """
    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
    
    def test_save_and_retrieve(self):
        """
        Should save in database
        """
        self.assertEqual(0, MapStory.objects.all().count())
        self.mapstory.save()
        self.assertEqual(1, MapStory.objects.all().count())
        savedMapStory = MapStory.objects.all()[0]
        self.assertEqual(savedMapStory.title, "Test story", "Should have the same title")
        self.assertEqual(savedMapStory.owner, self.mapstory.owner, "Should have the same owner")

    def test_remove(self):
        self.assertEqual(0, MapStory.objects.all().count())
        self.mapstory.save()
        self.assertEqual(1, MapStory.objects.all().count())
        MapStory.objects.filter(id=self.mapstory.id).delete()
        self.assertEqual(0, MapStory.objects.all().count())

    @skip("TODO")
    def test_get_abosolute_url(self):
        self.assertIsNotNone(self.mapstory.get_absolute_url())

    @skip("TODO: Fix this test")
    def test_update_from_viewer(self):
        conf = {}
        conf.title = "Test"
        conf.abstract = "Test abstract"
        conf.is_published = True
        self.mapstory.update_from_viewer(conf)
Exemplo n.º 9
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()
Exemplo n.º 10
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()
Exemplo n.º 11
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
Exemplo n.º 12
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