About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
See full specifications

linux default iconcollective.elephantvocabulary Publisher's description

Like elephants don't forget anything, so does't collective.elephantvocabulary. It provides a wrapper around for existing zope.schema vocabularies and make them not forget anything.

Like elephants don't forget anything, so does't collective.elephantvocabulary. It provides a wrapper around for existing zope.schema vocabularies and make them not forget anything.

Example usecase would be a vocabulary (source) of users which from certain point in time wants to hide / deactivate some users for form or listing. But at the same time you want keep old references to user term working. This is when collective.elephantvocabulary comes into the picture. With it you wrap existing vocabulary of users and provide set of hidden list of users (term values).


Some example content and vocabularies

>>> context = layer.context
>>> example_vocab = layer.example_vocab
>>> example_source = layer.example_source

>>> [i.value for i in example_vocab]
[1, 2, 3, 4]

Bellow is out wraper method we use to make our existing vocab more elephant-like.

>>> from collective.elephantvocabulary import wrap_vocabulary

In first exampe we pass to our wrap_vocabulary a vocabulary of [1, 2, 3, 4] and we set terms 2 and 3 to hidden. wrap_vocabulary returns VocabularyFactory which needs to be called with context (you could also register it with as utility).

>>> wrapped_vocab_factory = wrap_vocabulary(example_vocab, [2, 3])
>>> print wrapped_vocab_factory
<collective.elephantvocabulary.vocabulary.VocabularyFactory object at ...>

>>> wrapped_vocab = wrapped_vocab_factory(context)
>>> [i.value for i in wrapped_vocab]
[1, 4]

>>> len(wrapped_vocab) == len(example_vocab)

>>> 2 in wrapped_vocab

>>> 5 in wrapped_vocab

>>> wrapped_vocab.getTerm(3).value

Above we see what collective.elephantvocabulary is all about. When listing vocabulary hidden terms are not listed. But when item is requested with its term value then term is also returned. Also length of vocabulary is unchanged. It still shows original lenght of vocabulary.

We can also call vocabulary by name it was register with ZCA machinery..

>>> wrapped_vocab2 = wrap_vocabulary('example-vocab', [2, 3])(context)
>>> [i.value for i in wrapped_vocab2]
[1, 4]

hidden_terms parameter (second argument we pass to wrap_vocabulary) can also be callable which expects 2 parameters, context and original vocabulary.

>>> def hidden_terms(context, vocab):
... return [1, 4]

>>> wrapped_vocab3 = wrap_vocabulary(example_vocab, hidden_terms)(context)
>>> [i.value for i in wrapped_vocab3]
[2, 3]

collective.elephantvocabulary also works with sources.

>>> [i.value for i in example_source]
[1, 2, 3, 4]

>>> [i.value for i in example_source.search()]
[1, 2]

>>> wrapped_source = wrap_vocabulary(example_source, [1, 4])(context)
>>> [i.value for i in wrapped_source.search()]

If vocabulary already provides set of hidden terms they are passed to wrapped vocabulary.

>>> example_vocab.hidden_terms = [1, 2]
>>> wrapped_vocab4 = wrap_vocabulary(example_vocab)(context)
>>> [i.value for i in wrapped_vocab4]
[3, 4]


What's New in This Release:

misspelled dependency, feeling silly [garbas]

System Requirements:

No special requirements.
Program Release Status:
Program Install Support: Install and Uninstall

Is collective.elephantvocabulary your software?

Manage your software

Most Popular

linux default icon GDB 7.4
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it... Read more
linux default icon Coral 0.9.1
Coral is a tool and a development platform to create and transform models and modeling languages.
linux default icon Forum Paid Plus Script 6.1
Forum Paid Pay Per Post Exchange is targeted at forum owners who wish to...
linux default icon sdo 0.6.5
Converts oracle SDO_GEOMETRY objects to WKT and GeoJSON.
linux default icon Get Paid Plus Script 6.1
Get Paid Plus Script

Related Category

» Other (877)
» Tools & Editors (359)
» Web Development (146)