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

Last change on this file since 612 was 612, checked in by crchemist, 18 years ago

reverting erroneous commit [368] (svn merge -r 368:367 http://svn/products/qPloneComments/tags/2.0)

File size: 2.3 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
8from Products.CMFCore import utils
9from Products.CMFCore.WorkflowCore import WorkflowException
10
11try:
12    from zope.interface import alsoProvides
13    from quills.core.interfaces.enabled import IWeblogEnhanced, IPossibleWeblog
14    from Products.QuillsEnabled.activation import WeblogActivationEvent
15except ImportError:
16    # this try: ... except: ... clause is needed for this package to work on
17    # plone 2.1, because zcml:condition attribute in zcml doesn't work
18    pass
19
20from quintagroup.transmogrifier.simpleblog2quills.adapters import IMAGE_FOLDER
21
22class BlogActivatorSection(object):
23    classProvides(ISectionBlueprint)
24    implements(ISection)
25
26    def __init__(self, transmogrifier, name, options, previous):
27        self.transmogrifier = transmogrifier
28        self.context = transmogrifier.context
29        self.wftool = utils.getToolByName(self.context, 'portal_workflow')
30
31        self.pathkey = defaultMatcher(options, 'path-key', name, 'path')
32        self.flagkey = options.get('flag-key', '_old_type').strip()
33        self.previous = previous
34
35    def __iter__(self):
36        for item in self.previous:
37            pathkey = self.pathkey(*item.keys())[0]
38
39            if not pathkey or self.flagkey not in item:
40                yield item; continue
41
42            if item[self.flagkey] != 'Blog':
43                yield item; continue
44
45            path = item[pathkey]
46            obj = self.context.unrestrictedTraverse(path, None)
47            if obj is None:         # path doesn't exist
48                yield item; continue
49
50            # pulish 'images' subfolder
51            images = getattr(obj, IMAGE_FOLDER, None)
52            if images is not None:
53                try:
54                    self.wftool.doActionFor(images, 'publish')
55                except WorkflowException:
56                    pass
57
58            if not IWeblogEnhanced.providedBy(obj) and \
59                IPossibleWeblog.providedBy(obj):
60                alsoProvides(obj, IWeblogEnhanced)
61                event.notify(WeblogActivationEvent(obj))
62
63            yield item
Note: See TracBrowser for help on using the repository browser.