collective.elephantvocabulary

Type of Zope vocabularies that don't "forget", like elephants
Download

collective.elephantvocabulary Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Publisher Name:
  • Rok Garbas
  • Publisher web site:
  • http://garbas.si

collective.elephantvocabulary Tags


collective.elephantvocabulary Description

Type of Zope vocabularies that don't "forget", like elephants Just like elephants don't forget anything, so doesn't the collective.elephantvocabulary module. 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).Usage:Some example content and vocabularies >>> context = layer.context >>> example_vocab = layer.example_vocab >>> example_source = layer.example_source >>> Bellow is out wraper method we use to make our existing vocab more elephant-like. >>> from collective.elephantvocabulary import wrap_vocabularyIn first exampe we pass to our wrap_vocabulary a vocabulary of 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, ) >>> print wrapped_vocab_factory >>> wrapped_vocab = wrapped_vocab_factory(context) >>> >>> len(wrapped_vocab) == len(example_vocab) True >>> 2 in wrapped_vocab True >>> 5 in wrapped_vocab False >>> wrapped_vocab.getTerm(3).value 3Above 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', )(context) >>> 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 >>> wrapped_vocab3 = wrap_vocabulary(example_vocab, hidden_terms)(context) >>> collective.elephantvocabulary also works with sources. >>> >>> >>> wrapped_source = wrap_vocabulary(example_source, )(context) >>> If vocabulary already provides set of hidden terms they are passed to wrapped vocabulary. >>> example_vocab.hidden_terms = >>> wrapped_vocab4 = wrap_vocabulary(example_vocab)(context) >>> Requirements: · Python What's New in This Release: · support for other type of vocabs (IVocabulary, IIterableSource) · BUG(Fixed): registry should be not be loaded at __init__ time


collective.elephantvocabulary Related Software