1 | from zope.interface import classProvides, implements |
---|
2 | from zope import event |
---|
3 | |
---|
4 | from collective.transmogrifier.interfaces import ISectionBlueprint |
---|
5 | from collective.transmogrifier.interfaces import ISection |
---|
6 | from collective.transmogrifier.utils import defaultMatcher |
---|
7 | |
---|
8 | from Products.CMFCore import utils |
---|
9 | from Products.CMFCore.WorkflowCore import WorkflowException |
---|
10 | |
---|
11 | try: |
---|
12 | from zope.interface import alsoProvides |
---|
13 | from quills.core.interfaces.enabled import IWeblogEnhanced, IPossibleWeblog |
---|
14 | from Products.QuillsEnabled.activation import WeblogActivationEvent |
---|
15 | except 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 | |
---|
20 | from quintagroup.transmogrifier.simpleblog2quills.adapters import IMAGE_FOLDER |
---|
21 | |
---|
22 | class 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 |
---|