Skip to content

Commit

Permalink
Merge branch 'release/2.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Mar 13, 2020
2 parents 0f5e9f7 + 9b2944c commit 560421c
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 30 deletions.
45 changes: 33 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
sudo: false
cache: pip
cache:
directories:
- $HOME/.wheels

language: python
python: 3.6
dist: xenial

env:
- TOX_ENV=pypy-django11
- TOX_ENV=py27-django11
- TOX_ENV=py35-django11
- TOX_ENV=py35-django20
- TOX_ENV=py36-django11
- TOX_ENV=py36-django20
- TOX_ENV=flake8
- TOX_ENV=docs
- TOX_ENV=coveralls
- TOX_ENV=pypy-django11
- TOX_ENV=py27-django11
- TOX_ENV=py35-django11
- TOX_ENV=py35-django22
- TOX_ENV=py36-django11
- TOX_ENV=py36-django22
- TOX_ENV=py37-django11
- TOX_ENV=py37-django22
- TOX_ENV=py37-django30
- TOX_ENV=py38-django11
- TOX_ENV=py38-django22
- TOX_ENV=py38-django30
- TOX_ENV=py39-django11
- TOX_ENV=py39-django22
- TOX_ENV=py39-django30
- TOX_ENV=flake8
- TOX_ENV=docs
- TOX_ENV=coveralls

global:
- PIP_WHEEL_DIR=$HOME/.wheels
- PIP_FIND_LINKS=file://$PIP_WHEEL_DIR

install:
- pip install tox
- pip install tox

script:
tox -e $TOX_ENV
tox -e $TOX_ENV

notifications:
email:
on_success: never
on_failure: change

2 changes: 1 addition & 1 deletion django_utils/__about__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__package_name__ = 'django-utils2'
__version__ = '2.6.0'
__version__ = '2.7.0'
__author__ = 'Rick van Hattem'
__author_email__ = 'Rick.van.Hattem@Fawo.nl'
__description__ = (
Expand Down
44 changes: 36 additions & 8 deletions django_utils/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Gender(choices.Choices):
Female = choices.Choice('f')
Other = choices.Choice('o')
gender = models.CharField(max_length=1, choices=Gender.choices)
gender = models.CharField(max_length=1, choices=Gender)
To reference these properties:
Expand Down Expand Up @@ -70,7 +70,7 @@ class Enum(choices.Choices):
Eggs = choices.Choice()
enum = models.IntegerField(
choices=Enum.choices, default=Enum.Foo)
choices=Enum, default=Enum.Foo)
To reference these properties:
Expand Down Expand Up @@ -109,12 +109,18 @@ def __setitem__(self, key, value):
self._by_value[value.value] = value

def __iter__(self):
for k, v in six.iteritems(self._by_value):
yield k, v
for key, value in six.iteritems(self._by_value):
yield key, value

def items(self):
return list(self)

def values(self):
return list(self._by_key.keys())

def keys(self):
return list(self._by_value.keys())

def __repr__(self):
return repr(self._by_key)

Expand Down Expand Up @@ -220,6 +226,10 @@ def __new__(cls, name, bases, attrs):

return super(ChoicesMeta, cls).__new__(cls, name, bases, attrs)

def __iter__(self):
for item in self.choices:
yield item


class Choices(six.with_metaclass(ChoicesMeta)):
'''The choices class is what you should inherit in your Django models
Expand All @@ -235,17 +245,35 @@ class Choices(six.with_metaclass(ChoicesMeta)):
'OrderedDict()'
>>> choices.choices.items()
[]
>>> choices.choices.keys()
[]
>>> choices.choices.values()
[]
>>> list(choices)
[]
>>> class ChoiceTest(Choices):
... a = Choice()
>>> choices = ChoiceTest()
>>> choices.choices.items()
[(0, <Choice[3]:a>)]
[(0, <Choice[...]:a>)]
>>> choices.a
0
>>> choices.choices['a']
<Choice[3]:a>
<Choice[...]:a>
>>> choices.choices[0]
<Choice[3]:a>
<Choice[...]:a>
>>> choices.choices.keys()
[0]
>>> choices.choices.values()
['a']
>>> list(choices)
[(0, <Choice[...]:a>)]
>>> list(ChoiceTest)
[(0, <Choice[...]:a>)]
'''
pass
choices = ChoicesDict()

def __iter__(self):
for item in self.choices:
yield item
5 changes: 4 additions & 1 deletion django_utils/management/commands/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def json_default(obj):
return str(obj)


EXCLUDED_KEYS = {'FILE_CHARSET', 'DEFAULT_CONTENT_TYPE'}


class Command(base_command.CustomBaseCommand):
help = '''Get a list of the current settings, any arguments given will be
used to match the settings name (case insensitive).
Expand Down Expand Up @@ -79,7 +82,7 @@ def handle(self, *args, **options):
args = list(map(str.upper, options.get('keys', args)))
data = dict()
for key in dir(settings):
if key.isupper():
if key.isupper() and key not in EXCLUDED_KEYS:
value = getattr(settings, key)
found = False
for arg in args:
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[pytest]
markers =
pep8: PEP8

python_files =
django_utils/*.py
tests/*.py
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down
6 changes: 5 additions & 1 deletion tests/test_choices.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from django.db import models
from django_utils import choices
from django.utils.translation import ugettext_lazy as _

try:
from django.utils.translation import gettext_lazy as _
except ImportError:
from django.utils.translation import ugettext_lazy as _


class TranslatedHuman(models.Model):
Expand Down
19 changes: 13 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[tox]
envlist =
py{py,27}-django11,
py35-django{11,20},
py36-django{11,20},
py35-django{11,22},
py36-django{11,22},
py37-django{11,22,30},
py38-django{11,22,30},
py39-django{11,22,30},
flake8,
docs

Expand All @@ -12,13 +15,17 @@ usedevelop = True
[testenv]
deps =
django11: Django<2.0
django20: Django>=2.0,<2.1
django22: Django>=2.2,<2.3
django30: Django>=3.0,<3.1
-r{toxinidir}/tests/requirements.txt

envlist =
py{py,27}-django11,
py35-django{11,20},
py36-django{11,20},
py35-django{11,22,30},
py36-django{11,22,30},
py37-django{11,22,30},
py38-django{11,22,30},
py39-django{11,22,30},

commands =
python setup.py test
Expand Down Expand Up @@ -49,6 +56,6 @@ commands =
coveralls

deps =
Django>=2.0,<2.1
Django>=3.0,<3.1
-r{toxinidir}/tests/requirements.txt
coveralls

0 comments on commit 560421c

Please sign in to comment.