1 | from zope.app.schema.vocabulary import IVocabularyFactory |
---|
2 | from zope.interface import implements |
---|
3 | from zope.schema.vocabulary import SimpleVocabulary |
---|
4 | from zope.schema.vocabulary import SimpleTerm |
---|
5 | from Products.CMFCore.utils import getToolByName |
---|
6 | from Products.CacheSetup.config import CACHE_TOOL_ID |
---|
7 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
8 | |
---|
9 | |
---|
10 | class 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 | |
---|
30 | HeaderSetVocabularyFactory = HeaderSetVocabulary() |
---|
31 | |
---|