Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #60 from HackSoftware/python38-support
Browse files Browse the repository at this point in the history
Fix: Python3.8 support
  • Loading branch information
slavov-v authored Dec 19, 2020
2 parents f913ad8 + ad2ef09 commit 686a459
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
pyenv install 3.5.7 --skip-existing
pyenv install 3.6.4 --skip-existing
pyenv install 3.7.0 --skip-existing
pyenv install 3.8.6 --skip-existing
- save_cache:
paths:
- /home/circleci/.pyenv/
Expand All @@ -53,8 +54,8 @@ jobs:
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pip install tox tox-pyenv
pyenv local 3.5.7 3.6.4 3.7.0
pyenv local 3.5.7 3.6.4 3.7.0 3.8.6
tox
pyenv local 3.7.0
pyenv local 3.8.6
pip install -e .[dev]
cd django_enum_choices/tests/e2e && python3 tests.py
24 changes: 18 additions & 6 deletions django_enum_choices/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,24 @@ def validate(self, value, *args, **kwargs):
if not self.blank and value in self.empty_values:
raise ValidationError(self.error_messages['blank'], code='blank')

if value not in self.enum_class:
raise ValidationError(
self.error_messages['invalid_choice'],
code='invalid_choice',
params={'value': value}
)
enum_value = value

if not isinstance(enum_value, self.enum_class):
try:
enum_value = self.to_enum_value(value)

if enum_value not in self.enum_class:
raise ValidationError(
self.error_messages['invalid_choice'],
code='invalid_choice',
params={'value': value}
)
except ValidationError:
raise ValidationError(
self.error_messages['invalid_choice'],
code='invalid_choice',
params={'value': value}
)

def value_to_string(self, obj):
value = self.value_from_object(obj)
Expand Down
2 changes: 1 addition & 1 deletion django_enum_choices/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ def prepare_value(self, value):
return value

def valid_value(self, value):
return value in self.enum_class
return isinstance(value, self.enum_class) and value in self.enum_class
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ commit = True

[flake8]
max-line-length = 120
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,*/settings/*,.venv,*/e2e/e2e/*

exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,*/settings/*,.venv,*/e2e/*
31 changes: 24 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[tox]
envlist =
lint-py{37}
django22-py{37,36}
django21-py{37,36,35}
django111-py{37,36,35}
lint-py{37,38}
django31-py{38,37,36}
django30-py{38,37,36}
django22-py{38,37,36}
django21-py{38,37,36,35}
django111-py{38,37,36,35}

[testenv]
deps =
{[base]deps}
django31: {[django]3.1}
django30: {[django]3.0}
django22: {[django]2.2}
django21: {[django]2.1}
django111: {[django]1.11}
Expand All @@ -20,6 +24,11 @@ deps =
flake8
commands = flake8 django_enum_choices/

[testenv:lint-py38]
deps =
flake8
commands = flake8 django_enum_choices/

[base]
deps =
pytest
Expand All @@ -29,8 +38,16 @@ deps =
psycopg2

[django]
3.1 =
Django>=3.1.0,<3.2.0
djangorestframework>=3.7.3
django-filter>=2.2.0
3.0 =
Django>=3.0.0,<3.1.0
djangorestframework>=3.7.3
django-filter>=2.2.0
2.2 =
Django>=2.2.0,<2.3.0
Django>=2.2.0,<2.2.17
djangorestframework>=3.7.3
django-filter>=2.2.0
2.1 =
Expand All @@ -39,5 +56,5 @@ deps =
django-filter>=2.2.0
1.11 =
Django>=1.11.0,<2.0.0
djangorestframework>=3.6.2
django-filter>=2.2.0
djangorestframework>=3.6.2,<3.9.0
django-filter>=2.2.0

0 comments on commit 686a459

Please sign in to comment.