Skip to content

Commit

Permalink
content_type in FileField 🌤
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibyx committed Aug 29, 2020
1 parent aecc7d9 commit 499a800
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.15.1 : 29.08.2020

- **Feature**: `FileField.content_type` introduced (contains mime)

## 0.15.0 : 23.08.2020

- **Feature**: `FileField` and `ImageField` introduced
Expand Down
2 changes: 2 additions & 0 deletions django_api_forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ def to_python(self, value: str) -> typing.Optional[File]:
params = {'max': self._max_length, 'length': file.size}
raise ValidationError(self.error_messages['max_length'], code='max_length', params=params)

file.content_type = mime

return file


Expand Down
2 changes: 1 addition & 1 deletion django_api_forms/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.15.0'
__version__ = '0.15.1'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-api-forms"
version = "0.15.0"
version = "0.15.1"
description = "Declarative Django request validation"
authors = ["Jakub Dubec <[email protected]>", "Paul Brown <[email protected]>"]
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions tests/data/valid_pdf.txt

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,16 @@ def test_missing_mime(self):
log_input(kitten)
file_field.clean(kitten)

def test_large_file(self):
file_field = FileField(required=False)

with open(f"{settings.BASE_DIR}/data/valid_pdf.txt") as f:
content = f.read()

result = file_field.clean(content)

self.assertEqual(result.content_type, 'application/pdf')


class ImageFieldTests(SimpleTestCase):
def setUp(self) -> None:
Expand Down

0 comments on commit 499a800

Please sign in to comment.