1 | from Products.AutocompleteWidget.AutocompleteWidget import AutocompleteWidget |
---|
2 | from Products.Archetypes import PloneMessageFactory as _ |
---|
3 | from Products.CMFCore.utils import getToolByName |
---|
4 | from Products.Archetypes.utils import DisplayList |
---|
5 | from Products.ATContentTypes.content import schemata |
---|
6 | from Products.ATContentTypes.content.schemata import marshall_register |
---|
7 | from Products.ATContentTypes.content.schemata import ATContentTypeSchema |
---|
8 | from Products.ATContentTypes.content.base import ATCTMixin |
---|
9 | from Products.ATContentTypes.content.document import ATDocument |
---|
10 | from Products.ATContentTypes.content.folder import ATFolder, ATBTreeFolder |
---|
11 | from Products.ATContentTypes.content.image import ATImage |
---|
12 | from Products.ATContentTypes.content.event import ATEvent |
---|
13 | from Products.ATContentTypes.content.file import ATFile |
---|
14 | from Products.ATContentTypes.content.newsitem import ATNewsItem |
---|
15 | |
---|
16 | new_subject_widget = AutocompleteWidget( |
---|
17 | label=_(u'label_categories', default = u'Categories'), |
---|
18 | description=_(u'help_categories', |
---|
19 | default = u'Also known as keywords, tags or labels, ' |
---|
20 | 'these help you categorize your content.'), |
---|
21 | actb_filter_bogus = 0, |
---|
22 | actb_expand_onfocus = 0, |
---|
23 | maxlength='1024' |
---|
24 | ) |
---|
25 | |
---|
26 | def getKeywords(self): |
---|
27 | portal_catalog = getToolByName(self, 'portal_catalog') |
---|
28 | res = portal_catalog.uniqueValuesFor('Subject') |
---|
29 | return DisplayList(zip(res,res)) |
---|
30 | |
---|
31 | ATCTMixin.getKeywords = getKeywords |
---|
32 | |
---|
33 | for content_type in [ATFolder, ATDocument, ATBTreeFolder, ATImage, ATEvent, ATFile, ATNewsItem]: |
---|
34 | content_type.schema['subject'].widget = new_subject_widget |
---|
35 | content_type.schema['subject'].vocabulary = 'getKeywords' |
---|
36 | |
---|