Skip to content

Commit 79b6bd0

Browse files
Tested against Django 4.0. Added FileField with restricted size (#16)
* Test against Django 4.0 * Add contrained file field * Add docs * Blackify * Drop DRF 3.9 support * Prepare 0.2.13 * Drop Python 3.6 support * Up reqs
1 parent c927896 commit 79b6bd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+752
-1888
lines changed

.github/workflows/test.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ on: [push, pull_request]
44

55
jobs:
66
test:
7-
8-
runs-on: ubuntu-latest
7+
name: test ${{ matrix.py }} - ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}-latest
99
strategy:
10+
fail-fast: true
1011
max-parallel: 4
1112
matrix:
12-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
13+
os:
14+
- Ubuntu
15+
# - Windows
16+
# - MacOs
17+
py:
18+
- "3.10"
19+
- "3.9"
20+
- "3.8"
21+
- "3.7"
1322

1423
steps:
1524
- uses: actions/checkout@v2
@@ -20,12 +29,14 @@ jobs:
2029
- name: Install Dependencies
2130
run: |
2231
python -m pip install --upgrade pip
23-
- name: Install tox-gh
24-
run: python -m pip install tox-gh
25-
- name: Setup test suite
26-
run: tox4 r -vv --notest
32+
- name: Install tox
33+
run: python -m pip install tox-gh-actions
34+
# - name: Setup test suite
35+
# run: tox r -vv --notest
36+
# - name: Run test suite
37+
# run: tox r --skip-pkg-install
2738
- name: Run test suite
28-
run: tox4 r --skip-pkg-install
39+
run: tox -r
2940
env:
3041
PYTEST_ADDOPTS: "-vv --durations=10"
3142
- name: Coveralls

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ are used for versioning (schema follows below):
1515
0.3.4 to 0.4).
1616
- All backwards incompatible changes are mentioned in this document.
1717

18+
0.2.13
19+
------
20+
2022-11-20
21+
22+
- Tested against Django 4.0.
23+
- Drop Python 3.6 support.
24+
- Drop Django REST Framework 3.9.x support.
25+
- Add `ConstrainedFileField` (for limiting size of file uploads).
26+
1827
0.2.12
1928
------
2029
2021-12-06

README.rst

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Collection of various tricks for
1212
:target: https://pypi.python.org/pypi/django-rest-framework-tricks/
1313
:alt: Supported Python versions
1414

15+
.. image:: https://img.shields.io/pypi/djversions/django-rest-framework-tricks.svg
16+
:target: https://pypi.python.org/pypi/django-rest-framework-tricks/
17+
:alt: Supported Django versions
18+
1519
.. image:: https://github.com/barseghyanartur/django-rest-framework-tricks/workflows/test/badge.svg
1620
:target: https://github.com/barseghyanartur/django-rest-framework-tricks/actions
1721
:alt: Build Status
@@ -193,7 +197,7 @@ Model definition
193197
'state',
194198
)
195199
196-
class Meta(object):
200+
class Meta:
197201
"""Meta options."""
198202
199203
ordering = ["isbn"]
@@ -246,7 +250,7 @@ Defining the serializers
246250
isbn = serializers.CharField(required=False)
247251
pages = serializers.IntegerField(required=False)
248252
249-
class Meta(object):
253+
class Meta:
250254
"""Meta options."""
251255
252256
model = Book
@@ -266,7 +270,7 @@ Defining the serializers
266270
class StockInformationSerializer(serializers.ModelSerializer):
267271
"""Stock information serializer."""
268272
269-
class Meta(object):
273+
class Meta:
270274
"""Meta options."""
271275
272276
model = Book
@@ -293,7 +297,7 @@ Defining the serializers
293297
publishing_information = PublishingInformationSerializer(required=False)
294298
stock_information = StockInformationSerializer(required=False)
295299
296-
class Meta(object):
300+
class Meta:
297301
"""Meta options."""
298302
299303
model = Book
@@ -667,6 +671,68 @@ serializer (JSON response). API becomes easier to use/understand that way.
667671
GET /api/profile/?ordering=full_name
668672
GET /api/profile/?ordering=-full_name
669673
674+
File field with restrictions
675+
----------------------------
676+
677+
Sample model
678+
~~~~~~~~~~~~
679+
680+
Absolutely no variations from standard implementation here.
681+
682+
Required imports
683+
^^^^^^^^^^^^^^^^
684+
685+
.. code-block:: python
686+
687+
from django.db import models
688+
689+
690+
Model definition
691+
^^^^^^^^^^^^^^^^
692+
693+
.. code-block:: python
694+
695+
class Profile(models.Model):
696+
"""Upload."""
697+
698+
username = models.CharField(max_length=255)
699+
resume = models.FileField()
700+
701+
702+
Sample serializer
703+
~~~~~~~~~~~~~~~~~
704+
705+
Required imports
706+
^^^^^^^^^^^^^^^^
707+
708+
.. code-block:: python
709+
710+
from rest_framework import serializers
711+
from rest_framework_tricks.fields import ConstrainedFileField
712+
713+
from .models import Upload
714+
715+
Defining the serializers
716+
^^^^^^^^^^^^^^^^^^^^^^^^
717+
718+
.. code-block:: python
719+
720+
class ProfileSerializer(serializers.ModelSerializer):
721+
"""Profile serializer."""
722+
723+
username = serializers.CharField()
724+
# Restrict resume to 5Mb
725+
resume = ConstrainedFileField(max_upload_size=5_242_880)
726+
727+
class Meta(object):
728+
729+
model = Profile
730+
fields = (
731+
'id',
732+
'username',
733+
'resume',
734+
)
735+
670736
Demo
671737
====
672738
Run demo locally

0 commit comments

Comments
 (0)