Back to index

plone3  3.1.7
terms.py
Go to the documentation of this file.
00001 from zope.interface import implements, alsoProvides
00002 from zope.schema.vocabulary import SimpleTerm
00003 from plone.app.vocabularies.interfaces import IBrowsableTerm
00004 from plone.app.vocabularies.interfaces import ITermWithDescription
00005 
00006 class TermWithDescription(SimpleTerm):
00007     """
00008       >>> term = TermWithDescription('value', 'token', 'title')
00009       >>> term.value, term.token, term.title, term.description
00010       ('value', 'token', 'title', None)
00011 
00012       >>> term = TermWithDescription('value', 'token', 'title',
00013       ...                            description='description')
00014       >>> term.value, term.token, term.title, term.description
00015       ('value', 'token', 'title', 'description')
00016     """
00017     implements(ITermWithDescription)
00018 
00019     def __init__(self, value, token, title, description=None):
00020         super(TermWithDescription, self).__init__(value, token=token, title=title)
00021         self.description = description
00022 
00023 class BrowsableTerm(TermWithDescription):
00024     """
00025       >>> term = BrowsableTerm('value')
00026       >>> term.value, term.token, term.title, term.description
00027       ('value', 'value', None, None)
00028       >>> IBrowsableTerm.providedBy(term)
00029       False
00030 
00031       >>> term = BrowsableTerm('value', 'token', 'title',
00032       ...                      description='description',
00033       ...                      browse_token='browse_token',
00034       ...                      parent_token='parent_token')
00035       >>> term.value, term.token, term.title, term.description
00036       ('value', 'token', 'title', 'description')
00037       >>> term.browse_token, term.parent_token
00038       ('browse_token', 'parent_token')
00039       >>> IBrowsableTerm.providedBy(term)
00040       True
00041     """
00042 
00043     def __init__(self, value, token=None, title=None, description=None,
00044                  browse_token=None, parent_token=None):
00045         super(BrowsableTerm, self).__init__(value, token=token, 
00046                                             title=title, description=description)
00047         self.browse_token = browse_token
00048         self.parent_token = parent_token
00049         if browse_token is not None or parent_token is not None:
00050             alsoProvides(self, IBrowsableTerm)