• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 31. Vocabularies and Related Fie... > Step 1: The Vocabulary and Its Terms

Step 1: The Vocabulary and Its Terms

A vocabulary has a very simple interface. It is much like a simple collection object with some additional functionality. The main idea is that a vocabulary provides ITerm objects. A term simply has a value attribute that can be any Python object. However, for Web forms (and other user interfaces), this minimalistic interface does not suffice because you have no way of reliably specifying a unique ID (an ASCII string) for a term, which you need to do to create any HTML input element with the terms. To solve this problem, the Zope 3 development team came up with the ITokenizedTerm interface, which provides a token attribute that must be a string that uniquely identifies the term. Another extension to the ITokenizedTerm interface is the ITitledTokenizedTerm interface, which additionally provides a title for the term that is used for representing the term in a user interface.

Because your vocabulary deals with folder item names, your ITerm interface's value attribute can be used to generate the token value. Because the token must be ASCII, you simply encode the value to UTF-8 (because it can be Unicode) and then use base 64 to ensure that it is ASCII. The title is just the same as the value attribute. Therefore, you only need a minimal implementation of ITitledTokenizedTerm, as shown here:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint