コード例 #1
0
ファイル: forms.py プロジェクト: MTG/freesound
def validate_file_extension(audiofiles):
    try:
        for file_ in audiofiles:
            content_type = file_.content_type
            if filename_has_valid_extension(str(file_)):
                ext = str(file_).rsplit('.', 1)[-1].lower()
                if ext == 'flac':
                    # At least Safari and Firefox do not set the proper mime type for .flac files
                    # (use 'application/octet-stream' instead of 'audio/flac'). For this reason we also allow
                    # this mime type for flac files.
                    if not content_type.startswith("audio") and not content_type == 'application/octet-stream':
                        raise forms.ValidationError('Uploaded file format not supported or not an audio file.')
                elif ext == 'ogg':
                    # Firefox seems to set wrong mime type for ogg files to video/ogg instead of audio/ogg
                    # For this reason we also allow this mime type for ogg files.
                    if not content_type.startswith("audio") and not content_type == 'video/ogg':
                        raise forms.ValidationError('Uploaded file format not supported or not an audio file.')
                else:
                    if not content_type.startswith("audio"):
                        raise forms.ValidationError('Uploaded file format not supported or not an audio file.')
            else:
                raise forms.ValidationError('Uploaded file format not supported or not an audio file.')

    except AttributeError:
        # Will happen when uploading with the flash uploader
        if not filename_has_valid_extension(str(audiofiles)):
            raise forms.ValidationError('Uploaded file format not supported or not an audio file.')
コード例 #2
0
ファイル: tests.py プロジェクト: MTG/freesound
 def test_filename_has_valid_extension(self):
     cases = [
         ('filaneme.wav', True),
         ('filaneme.aiff', True),
         ('filaneme.aif', True),
         ('filaneme.mp3', True),
         ('filaneme.ogg', True),
         ('filaneme.flac', True),
         ('filaneme.xyz', False),
         ('wav', False),
     ]
     for filename, expected_result in cases:
         self.assertEqual(filename_has_valid_extension(filename), expected_result)
コード例 #3
0
ファイル: forms.py プロジェクト: yash752004/freesound
def validate_file_extension(audiofiles):
    try:
        for file_ in audiofiles:
            content_type = file_.content_type
            if filename_has_valid_extension(str(file_)):
                ext = str(file_).rsplit('.', 1)[-1].lower()
                if ext == 'flac':
                    # At least Safari and Firefox do not set the proper mime type for .flac files
                    # (use 'application/octet-stream' instead of 'audio/flac'). For this reason we also allow
                    # this mime type for flac files.
                    if not content_type.startswith(
                            "audio"
                    ) and not content_type == 'application/octet-stream':
                        raise forms.ValidationError(
                            'Uploaded file format not supported or not an audio file.'
                        )
                elif ext == 'ogg':
                    # Firefox seems to set wrong mime type for ogg files to video/ogg instead of audio/ogg
                    # For this reason we also allow this mime type for ogg files.
                    if not content_type.startswith(
                            "audio") and not content_type == 'video/ogg':
                        raise forms.ValidationError(
                            'Uploaded file format not supported or not an audio file.'
                        )
                else:
                    if not content_type.startswith("audio"):
                        raise forms.ValidationError(
                            'Uploaded file format not supported or not an audio file.'
                        )
            else:
                raise forms.ValidationError(
                    'Uploaded file format not supported or not an audio file.')

    except AttributeError:
        # Will happen when uploading with the flash uploader
        if not filename_has_valid_extension(str(audiofiles)):
            raise forms.ValidationError(
                'Uploaded file format not supported or not an audio file.')
コード例 #4
0
ファイル: tests.py プロジェクト: oriolromani/freesound
 def test_filename_has_valid_extension(self):
     cases = [
         ('filaneme.wav', True),
         ('filaneme.aiff', True),
         ('filaneme.aif', True),
         ('filaneme.mp3', True),
         ('filaneme.ogg', True),
         ('filaneme.flac', True),
         ('filaneme.xyz', False),
         ('wav', False),
     ]
     for filename, expected_result in cases:
         self.assertEqual(filename_has_valid_extension(filename),
                          expected_result)
コード例 #5
0
ファイル: test_forms.py プロジェクト: yash752004/freesound
 def test_filename_has_valid_extension(self):
     cases = [
         ("filaneme.wav", True),
         ("filaneme.aiff", True),
         ("filaneme.aif", True),
         ("filaneme.mp3", True),
         ("filaneme.ogg", True),
         ("filaneme.flac", True),
         ("filaneme.xyz", False),
         ("wav", False),
     ]
     for filename, expected_result in cases:
         self.assertEqual(filename_has_valid_extension(filename),
                          expected_result)
コード例 #6
0
ファイル: serializers.py プロジェクト: oriolromani/freesound
 def validate_audiofile(self, attrs, source):
     value = attrs[source]
     if not filename_has_valid_extension(str(value)):
         serializers.ValidationError(
             'Uploaded file format not supported or not an audio file.')
     return attrs
コード例 #7
0
ファイル: forms.py プロジェクト: oriolromani/freesound
def validate_file_extension(value):
    if not filename_has_valid_extension(str(value)):
        raise forms.ValidationError('Uploaded file format not supported or not an audio file.')
コード例 #8
0
 def validate_audiofile(self, value):
     if not filename_has_valid_extension(str(value)):
         raise serializers.ValidationError('Uploaded file format not supported or not an audio file.')
     return value
コード例 #9
0
ファイル: forms.py プロジェクト: giuband/freesound
def validate_file_extension(audiofiles):
    for file_ in audiofiles:
        content_type = file_.content_type
        if not (content_type.startswith("audio") and filename_has_valid_extension(str(file_))):
            raise forms.ValidationError('Uploaded file format not supported or not an audio file.')
コード例 #10
0
ファイル: serializers.py プロジェクト: giuband/freesound
 def validate_audiofile(self, attrs, source):
     value = attrs[source]
     if not filename_has_valid_extension(str(value)):
         serializers.ValidationError('Uploaded file format not supported or not an audio file.')
     return attrs