Commits

Anonymous committed 7eac13a Merge

merge backout

Comments (0)

Files changed (2)

model_utils/__init__.py

     >>> 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:

model_utils/tests/tests.py

         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 ChoicesTests(TestCase):
     def setUp(self):
         self.STATUS = Choices('DRAFT', 'PUBLISHED')
     def test_display(self):
         self.assertEquals(self.STATUS.deleted, 'DELETED')
 
+
 class InheritanceCastModelTests(TestCase):
     def setUp(self):
         self.parent = InheritParent.objects.create()