Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install horae.groupselect

How to install horae.groupselect

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install horae.groupselect
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0a1 Available View build log
Windows (64-bit)
1.0a1 Available View build log
Mac OS X (10.5+)
1.0a1 Available View build log
Linux (32-bit)
1.0a1 Available View build log
Linux (64-bit)
1.0a1 Available View build log
 
Author
License
GPL
Depended by
Lastest release
version 1.0a1 on Jan 17th, 2012

Introduction

horae.groupselect provides a grouped Dropdown widget for zope.formlib using the default optgroup elements provided by HTML.

Usage

To use a grouped dropdown widget the previously used Choice field of the schema has to be replaced by a GroupedChoice field provided in horae.groupedselect.field. A GroupedChoice field takes the exactly same parameters as the stock Choice field but additionally an instance of a groups provider (implementing horae.groupedselect.interfaces.IGroups) has to be provided over the parameter groups. The mentioned groups provider converts the vocabulary of the field into a list of groups.

Imagine field to select a country and you would like to group them by region:

System Message: WARNING/2 (<string>, line 23)

Literal block expected; none found.

from zope import interface, implements from zope.schema import vocabulary

from horae.groupedselect import field, interfaces

class Country(object): def __init__(self, region, country): self.region = region self.country = country

class CountryGroups(object): implements(interfaces.IGroups)

def groups(self, vocabulary): """ Converts the given vocabulary into a list of groups:

return (('Group 1', (term1, term2, term3)), ('Group 2', (term6, term5, term6)),) """ groups = {} for term in vocabulary: if not term.value.region in groups: groups[term.value.region] = () groups[term.value.region] = groups[term.value.region] + (term,) return groups.items()

class ICountrySelection(interface.Interface):

country = field.GroupedChoice( title = u'Country', vocabulary = vocabulary.SimpleVocabulary(( # ... vocabulary.SimpleTerm( Country(u'Europe', u'Switzerland'), 'ch', u'Switzerland' ), vocabulary.SimpleTerm( Country(u'Europe', u'Germany'), 'de', u'Germany' ), vocabulary.SimpleTerm( Country(u'Europe', u'Austria'), 'at', u'Austria' ), vocabulary.SimpleTerm( Country(u'Europe', u'France'), 'fr', u'France' ), # ... vocabulary.SimpleTerm( Country(u'North America', u'USA'), 'us', u'USA' ), vocabulary.SimpleTerm( Country(u'Europe', u'Canada'), 'ca', u'Canada' ), # ... )), groups = CountryGroups() )

Dependencies

Changelog

1.0a1 (2012-01-16)
  • Initial release

Subscribe to package updates

Last updated Jan 17th, 2012

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.