source: products/vendor/Products.CacheSetup/current/Products/CacheSetup/vocabulary.py @ 3296

Last change on this file since 3296 was 3296, checked in by fenix, 12 years ago

Load Products.CacheSetup?-1.2.1 into vendor/Products.CacheSetup?/current.

  • Property svn:eol-style set to native
File size: 1.0 KB
Line 
1from zope.app.schema.vocabulary import IVocabularyFactory
2from zope.interface import implements
3from zope.schema.vocabulary import SimpleVocabulary
4from zope.schema.vocabulary import SimpleTerm
5from Products.CMFCore.utils import getToolByName
6from Products.CacheSetup.config import CACHE_TOOL_ID
7from Products.CMFPlone import PloneMessageFactory as _
8
9
10class HeaderSetVocabulary(object):
11    """Vocabulary with all known headers sets.
12    """
13    implements(IVocabularyFactory)
14
15    def __call__(self, context):
16        pcs=getToolByName(context, CACHE_TOOL_ID, None)
17        if pcs is None:
18            return SimpleVocabulary([])
19
20        display_id=pcs.getDisplayPolicy().getId()
21        headers=[(header.getId(), header.Title())
22                for header in pcs.getHeaderSets(display_id)]
23        headers.sort(key=lambda x: x[1])
24        terms=[SimpleTerm(x[0], x[0], x[1]) for x in headers]
25        terms.append(SimpleTerm(None, "none", _(u"No cache headers")))
26
27        return SimpleVocabulary(terms)
28
29
30HeaderSetVocabularyFactory = HeaderSetVocabulary()
31
Note: See TracBrowser for help on using the repository browser.