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

Easily add more Metaesque option classes to your Django forms, models and more.

Installing

Install using pip:

pip install django-easyoptions

It works with Django 1.4 and upwards.

Using

To make use of Options in your class, define an Options class, and use one of the metaclass factories provided.

from django import forms
from django.utils import six
from easyoption.options import OptionsBase, form_option_factory


# Define your ``Option``\s container class
class ExtendedOptions(OptionsBase):
    def __init__(self, options):

        # Collect your options, supplying defaults as appropriate
        self.foo = options.pop('foo', None)
        self.frobnicate = options.pop('frobnicate', True)

        # Call the ``super().__init__()``, which ensures all options are
        # consumed.
        super(ExtraOption, self).__init__(options)


# Define your base class, using the options from ``_extendedoptions``
class ExtendedForm(six.with_metaclass(
        form_option_factory(ExtendedOptions),
        forms.Form)):

    def __init__(self, **kwargs):
        super(ExtendedForm, self).__init__(**kwargs)

        if self._extendedoptions.frobnicate:
            self.bar(self._extendedoptions.foo)


# Extend your base class, and define the ``ExtendedOptions`` for options
# for this specific implementation
class SpecificExtendedForm(ExtendedForm):
    class ExtendedOptions:
        foo = 'quux'

Methods

options.options_factory

The main method that does all of the work is options.options_factory. It generates a new Metaclass that you should apply to your base class, allowing subclasses to define their own options. The method accepts four arguments:

options_processor
A callable that processes options the options dict from the class. This is usually a class subclassing options.OptionsBase, but could be any callable as long as it returns some options structure.
options_class_name

The name of the attribute on the class where the options definition can be found.

Defaults to the options_processor.__name__, which works well with classes.

options_attr_name

The name of the attribute where processed options will be stored.

Defaults to '_' + options_class_name.lower().

metaclass

The base metaclass to extend. Many Django classes have metaclasses already, so if you’re adding options to class that already has a metaclass, you must supply it here for the class to work properly.

Defaults to type.

options.form_options_factory

Calls options.options_factory with the metaclass already set to the metaclass for Django forms.

options.modelform_options_factory

Calls options.options_factory with the metaclass already set to the metaclass for Django model forms.

Release History

Release History

0.1.0

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

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
django-easyoptions-0.1.0.tar.gz (3.8 kB) Copy SHA256 Checksum SHA256 Source Jun 19, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development 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