This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Wrapper class for defining DRY, encapsulated choice options for CharFields.

ChoiceEnumeration

ChoiceEnumeration class can be declared at the module or class level in the following format:

class ChoiceClass(ChoiceEnumeration):
    ATTR1 = ChoiceEnumeration.Option('db_value1', 'Human readable text 1')
    ATTR2 = ChoiceEnumeration.Option('db_value2', 'Human readable text 2')

The following attributes are generated on the ChoiceEnumeration child class:

  • ALL_OPTIONS - a tuple of the supplied options
  • CHOICES - a Django char field choices-compatible tuple
  • CHOICES_DICT - a dictionary of option:text values
  • DEFAULT - (optional) the item marked as default

A typical Django example would look like:

class SomeModel(models.Model):
    class MetaVar(ChoiceEnumeration):
        FOO  = ChoiceEnumeration.Option('foo',  'Foo Choice', default=True)
        BAR  = ChoiceEnumeration.Option('bar',  'Bar Option')
        BAZ  = ChoiceEnumeration.Option('baz',  'Baz Pick')
        SPAM = ChoiceEnumeration.Option('spam', 'Spam spam spam')
        EGGS = ChoiceEnumeration.Option('eggs', 'Eggs, Spam, and Ham')
Example interactive usage::
>>> class MetaVar(ChoiceEnumeration):
...     FOO  = ChoiceEnumeration.Option('foo',  'Foo Choice', default=True)
...     BAR  = ChoiceEnumeration.Option('bar',  'Bar Option')
...     BAZ  = ChoiceEnumeration.Option('baz',  'Baz Pick')
...     SPAM = ChoiceEnumeration.Option('spam', 'Spam spam spam')
...     EGGS = ChoiceEnumeration.Option('eggs', 'Eggs, Spam, and Ham')
>>> MetaVar.FOO
u'foo'
>>> MetaVar.ALL_OPTIONS
(u'foo', u'bar', u'baz', u'spam', u'eggs')
>>> MetaVar.CHOICES
((u'foo', 'Foo Choice'), (u'bar', 'Bar Option'), (u'baz', 'Baz Pick'), (u'spam', 'Spam spam spam'), (u'eggs', 'Eggs, Spam, and Ham'))
>>> MetaVar.CHOICES_DICT
{u'baz': 'Baz Pick', u'eggs': 'Eggs, Spam, and Ham', u'foo': 'Foo Choice', u'bar': 'Bar Option', u'spam': 'Spam spam spam'}
>>> MetaVar.DEFAULT
u'foo'
>>> MetaVar.CHOICES_DICT[MetaVar.FOO]
'Foo Choice'

make_enum_class

make_enum_class dynamically generates a ChoiceEnumeration derived class.

Example:

from choice_enum import make_enum_class, Option
MetaVar = make_enum_class('MetaVar',
    FOO=Option('foo',  'Foo Choice', default=True),
    BAR=Option('bar',  'Bar Option'),
    BAZ=Option('baz',  'Baz Pick')
)
Release History

Release History

0.9

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
choice_enum-0.9.tar.gz (3.8 kB) Copy SHA256 Checksum SHA256 Source Dec 27, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting