-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to file upload post processing
- Fixes #355 — Adds standard thumbnails for various file types - Adds `video/mp4` to the list of accepted mime types for file upload - Improves process to create thumbnails. The file is now only downloaded for post processing when the mime-type indicates an image. - Adds a migration to change the mime_type field maximum length to 100, to make sure that users can add Office2007+ documents. - Add MIME_LOOKUPS setting, which provides a list of accepted file types and the corresponding default thumbnail. This setting is also used in resources.validators to validate mime types
- Loading branch information
1 parent
d124c03
commit 6b81c13
Showing
15 changed files
with
197 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.6 on 2016-07-20 12:59 | ||
from __future__ import unicode_literals | ||
|
||
import buckets.fields | ||
from django.db import migrations, models | ||
import resources.validators | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('resources', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='historicalresource', | ||
name='file', | ||
field=buckets.fields.S3FileField(upload_to='resources'), | ||
), | ||
migrations.AlterField( | ||
model_name='historicalresource', | ||
name='mime_type', | ||
field=models.CharField(max_length=100, validators=[resources.validators.validate_file_type]), | ||
), | ||
migrations.AlterField( | ||
model_name='resource', | ||
name='file', | ||
field=buckets.fields.S3FileField(upload_to='resources'), | ||
), | ||
migrations.AlterField( | ||
model_name='resource', | ||
name='mime_type', | ||
field=models.CharField(max_length=100, validators=[resources.validators.validate_file_type]), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,18 @@ | ||
import pytest | ||
import os | ||
from django.test import TestCase | ||
from django.core.exceptions import ValidationError | ||
from django.conf import settings | ||
from buckets.fields import S3File, S3FileField | ||
from buckets.test.utils import ensure_dirs | ||
from buckets.test.storage import FakeS3Storage | ||
|
||
from ..validators import validate_file_type | ||
|
||
path = os.path.dirname(settings.BASE_DIR) | ||
|
||
|
||
class ValidateFileTypeTest(TestCase): | ||
def test_valid_file(self): | ||
ensure_dirs() | ||
storage = FakeS3Storage() | ||
field = S3FileField(storage=storage) | ||
file = open(path + '/resources/tests/files/image.jpg', 'rb').read() | ||
file = storage.save('image.jpg', file) | ||
s3_file = S3File(file, field=field) | ||
|
||
try: | ||
validate_file_type(s3_file) | ||
validate_file_type('image/png') | ||
except ValidationError: | ||
pytest.fail('ValidationError raised unexpectedly') | ||
|
||
def test_invalid_file(self): | ||
ensure_dirs() | ||
storage = FakeS3Storage() | ||
field = S3FileField(storage=storage) | ||
file = open(path + '/resources/tests/files/text.txt', 'rb').read() | ||
file = storage.save('text.txt', file) | ||
s3_file = S3File(file, field=field) | ||
|
||
with pytest.raises(ValidationError) as e: | ||
validate_file_type(s3_file) | ||
validate_file_type('text/plain') | ||
assert e.value.message == "Files of type text/plain are not accepted." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.