Ejemplo n.º 1
0
    def create_media_object(self, caption, filename, folder=None):
        """
        Create a new media item object within the media library based on the
        given meta data. This will simply create the meta data but will not
        upload or store any actual image/document data and it is assumed that
        this happens outside of the image media object creation.
        """
        # generate caption based on filename if provided
        if not caption and filename:
            caption = get_caption_from_filename(filename)

        media = Media()
        media.caption = caption
        media.filename = filename

        if folder:
            media.parent = folder

        media.save()

        return media
Ejemplo n.º 2
0
    def create_blank_external_media(self,
                                    url,
                                    filename=None,
                                    caption=None,
                                    folder=None):
        """
        Create a new (blank) media item with the given external url and
        optionally the given parent folder.
        """
        media = Media()
        media.is_blank = True
        media.external_url = url

        # generate filename based on given url
        url_parts = urlparse.urlparse(url)
        path = url_parts.path

        # filename
        if filename:
            media.filename = filename
        else:
            media.filename = os.path.basename(path)

        # generate caption from filename
        if caption:
            media.caption = caption
        else:
            media.caption = get_caption_from_filename(media.filename)

        # folder
        if folder:
            media.folder = folder

        media.save()

        # notify task runner that there is something to do
        TaskRunner.notify()

        return media
Ejemplo n.º 3
0
 def test_should_ignore_long_file_extension(self):
     self.assertEqual('Foo Bar',
                      get_caption_from_filename('foo-bar.filextension'))
Ejemplo n.º 4
0
 def test_should_ignore_only_last_file_extensions(self):
     self.assertEqual('Foo Bar', get_caption_from_filename('foo.bar.txt'))
Ejemplo n.º 5
0
 def test_should_substitute_multiple_spaces(self):
     self.assertEqual('Foo Bar',
                      get_caption_from_filename('Foo     Bar.txt'))
Ejemplo n.º 6
0
 def test_should_replace_invalid_characters_with_space(self):
     self.assertEqual('Test 2',
                      get_caption_from_filename('Test,=+*#£2.txt'))
Ejemplo n.º 7
0
 def test_should_replace_underline_with_spaces(self):
     self.assertEqual('Hello Foo',
                      get_caption_from_filename('hello_foo.txt'))
Ejemplo n.º 8
0
 def test_should_unslugify_name_without_file_extension(self):
     self.assertEqual('Hello Foo',
                      get_caption_from_filename('hello-foo.txt'))
Ejemplo n.º 9
0
 def test_should_return_empty_string_for_none(self):
     self.assertEqual('', get_caption_from_filename(None))