mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-28 01:00:23 +00:00
Backed out changeset c05246980ddf
This commit is contained in:
parent
50919b9ff4
commit
8efaf852c8
2 changed files with 2 additions and 32 deletions
|
|
@ -20,32 +20,14 @@ class ChoiceEnum(object):
|
|||
>>> tuple(STATUS)
|
||||
((0, 'DRAFT'), (1, 'PUBLISHED'))
|
||||
|
||||
>>> STATUS = ChoiceEnum(('DRAFT', 'draft'), ('PUBLISHED', 'published'))
|
||||
>>> STATUS.DRAFT
|
||||
0
|
||||
>>> tuple(STATUS)
|
||||
((0, 'draft'), (1, 'published'))
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, *choices):
|
||||
self._choices = tuple()
|
||||
self._iter_choices = tuple()
|
||||
for i, choice in enumerate(self.equalize(choices)):
|
||||
self._choices += ((i, choice[0]),)
|
||||
self._iter_choices += ((i, choice[1]),)
|
||||
self._choices = tuple(enumerate(choices))
|
||||
self._choice_dict = dict(self._choices)
|
||||
self._reverse_dict = dict(((i[1], i[0]) for i in self._choices))
|
||||
|
||||
def equalize(self, choices):
|
||||
for choice in choices:
|
||||
if isinstance(choice, (list, tuple)):
|
||||
yield choice
|
||||
else:
|
||||
yield (choice, choice)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._iter_choices)
|
||||
return iter(self._choices)
|
||||
|
||||
def __getattr__(self, attname):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -88,18 +88,6 @@ class ChoiceEnumTests(TestCase):
|
|||
self.assertEquals(tuple(self.STATUS), ((0, 'DRAFT'), (1, 'PUBLISHED')))
|
||||
|
||||
|
||||
class LabelChoiceEnumTests(ChoiceEnumTests):
|
||||
def setUp(self):
|
||||
self.STATUS = ChoiceEnum(
|
||||
('DRAFT', 'draft'),
|
||||
('PUBLISHED', 'published'),
|
||||
'DELETED',
|
||||
)
|
||||
|
||||
def test_iteration(self):
|
||||
self.assertEquals(tuple(self.STATUS), ((0, 'draft'), (1, 'published'), (2, 'DELETED')))
|
||||
|
||||
|
||||
class InheritanceCastModelTests(TestCase):
|
||||
def setUp(self):
|
||||
self.parent = InheritParent.objects.create()
|
||||
|
|
|
|||
Loading…
Reference in a new issue