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

Copyright (c) 2009-2015 gocept gmbh & co. kg All Rights Reserved.

This software is subject to the provisions of the Zope Public License, Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. THIS SOFTWARE IS PROVIDED “AS IS” AND ANY AND ALL EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.

Autocomplete widget

gocept.autocomplete provides an autocomplete widget for z3c.form. The widget is useful if you want to provide the user with a list of suggestions for a field, but still want to accept anything else that is entered, too.

To use the widget, <include package=”gocept.autocomplete”> and provide a source that implements gocept.autocomplete.interfaces.ISearchableSource. This means two things, one, your source must provide a search() method so it can be queried for values (with whatever has been entered so far as the query) and two, you must always return True from the __contains__() method, so that the user is free to enter a value that is not part of the suggestions.

No further configuration is required, the widget is automatically registered for all zope.schema.IChoice fields with an ISearchableSource.

As an example, we exercise the code from gocept.autocomplete.tests.color with the testbrowser:

>>> import zope.app.testing.functional
>>> root = zope.app.testing.functional.getRootFolder()
>>> import gocept.autocomplete.tests.color
>>> house = gocept.autocomplete.tests.color.House()
>>> root['house'] = house
>>> import zope.testbrowser.testing
>>> b = zope.testbrowser.testing.Browser()
>>> b.handleErrors = False

The AutocompleteWidget is an enhanced TextWidget. Thus, in display mode, it behaves just like a TextWidget:

>>> b.open('http://localhost/house')
>>> print b.contents
<?xml...
...<span id="form-widgets-color" class="text-widget autocomplete required choice-field"></span>...

But in edit mode, it generates additional javascript code:

>>> b.addHeader('Authorization', 'Basic mgr:mgrpw')
>>> b.open('http://localhost/house')
>>> print b.contents
<?xml...
...<script src=".../autocomplete-min.js"...
...<input id="form-widgets-color"...
...<div id="form-widgets-color-container"...
...DS_XHR("http://localhost/house/@@index.html/++widget++color/@@autocomplete-search"...
...new YAHOO.widget.AutoComplete( "form-widgets-color", "form-widgets-color-container"...

The autocompletion is populated via a view registered on the widget:

>>> b.open('http://localhost/house/@@index.html/++widget++color/@@autocomplete-search')
>>> print b.contents
>>> b.open('http://localhost/house/@@index.html/++widget++color/@@autocomplete-search?q=r')
>>> print b.contents
red
ruby

But we can still enter any value we want and have it saved (there are two parts to make this work, one is that the source must always return True in its __contains__() method, and the other is that the widget uses a special TitledTokenizedTerm that uses the actual value for everything):

>>> b.open('http://localhost/house')
>>> b.getControl('Color').value = 'foo'
>>> b.getControl(name='form.buttons.apply').click()
>>> print b.contents
<?xml...
...foo...

Grouped Forms

A special case are group forms, who provide the field definitions in their groups. For this particular occasion, we’ve setup an ApartmentGroup and a form:

>>> apartment = gocept.autocomplete.tests.color.Apartment()
>>> root['apartment'] = apartment

The widget traversal for grouped forms returns the correct search results:

>>> b.open('http://localhost/apartment/@@grouped.html/++widget++color/@@autocomplete-search?q=r')
>>> print b.contents
red
ruby
>>> b.open('http://localhost/apartment/@@grouped.html/++widget++number/@@autocomplete-search?q=1')
>>> print b.contents
12A
12

Buildout configuration

This package ships with a minimum buildout config which allows to run the tests:

$ python bootstrap.py
$ bin/buildout
$ bin/test

Changes

0.7 (2015-12-09)

0.6 (2013-04-23)

  • Switch to jQuery UI and Fanstatic instead of YUI and zc.resourcelibrary .

0.5 (2011-01-11)

  • configure.zcml no longer includes zope.app.zcmlfiles, it was moved to ftesting.zcml.
  • Described the dependency on zc.resourcelibrary in README which makes this package incompatible with packages using hurry.resource.

0.4 (2010-06-17)

contributed by Roman Joost <roman@mooball.com>:

  • Added grouped forms support.
  • Added configuration options for delimiter character, minimum query length and the type-ahead feature

0.3 (2010-02-26)

  • Slightly different way to “estimate” the widget URL: use the form’s context, not the getContent() method: if the content is redirected using an adapter then the view might not exist there.

0.2 (2009-02-23)

  • register the widget for IChoice fields with an ISearchableSource. This functionality depends on z3c.form>=r96460 (will be included in z3c.form-2.0).
  • improved documentation.

0.1 (2009-02-06)

  • first release
  • NOTE: still missing security declarations on the autocomplete-search view. This means anyone can query the source for values.
Release History

Release History

0.7

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.6

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.5

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.4

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

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.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.1dev

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
gocept.autocomplete-0.7.tar.gz (15.8 kB) Copy SHA256 Checksum SHA256 Source Dec 9, 2015

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