source: products/quintagroup.transmogrifier.simpleblog2quills/trunk/quintagroup/transmogrifier/simpleblog2quills/activator.py @ 586

Last change on this file since 586 was 586, checked in by chervol, 18 years ago

showButtons renamed to showByline

File size: 1.8 KB
Line 
1from zope.interface import classProvides, implements
2from zope import event
3
4from collective.transmogrifier.interfaces import ISectionBlueprint
5from collective.transmogrifier.interfaces import ISection
6from collective.transmogrifier.utils import defaultMatcher
7
8try:
9    from zope.interface import alsoProvides
10    from quills.core.interfaces.enabled import IWeblogEnhanced, IPossibleWeblog
11    from Products.QuillsEnabled.activation import WeblogActivationEvent
12except ImportError:
13    # this try: ... except: ... clause is needed for this package to work on
14    # plone 2.1, because zcml:condition attribute in zcml doesn't work
15    pass
16
17class BlogActivatorSection(object):
18    classProvides(ISectionBlueprint)
19    implements(ISection)
20
21    def __init__(self, transmogrifier, name, options, previous):
22        self.transmogrifier = transmogrifier
23        self.context = transmogrifier.context
24
25        self.pathkey = defaultMatcher(options, 'path-key', name, 'path')
26        self.flagkey = options.get('flag-key', '_old_type').strip()
27        self.previous = previous
28
29    def __iter__(self):
30        for item in self.previous:
31            pathkey = self.pathkey(*item.keys())[0]
32
33            if not pathkey or self.flagkey not in item:
34                yield item; continue
35
36            if item[self.flagkey] != 'Blog':
37                yield item; continue
38
39            path = item[pathkey]
40            obj = self.context.unrestrictedTraverse(path, None)
41            if obj is None:         # path doesn't exist
42                yield item; continue
43
44            if not IWeblogEnhanced.providedBy(obj) and \
45                IPossibleWeblog.providedBy(obj):
46                alsoProvides(obj, IWeblogEnhanced)
47                event.notify(WeblogActivationEvent(obj))
48
49            yield item
Note: See TracBrowser for help on using the repository browser.