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.transmogrify.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: |
---|
40 | yield item; continue |
---|
41 | |
---|
42 | type_ = item.get(self.flagkey, None) |
---|
43 | newtype = item.get('_type', None) |
---|
44 | if type_ != 'Blog' and newtype != 'Large Plone Folder': |
---|
45 | yield item; continue |
---|
46 | |
---|
47 | path = item[pathkey] |
---|
48 | if type_ is None and newtype == 'Large Plone Folder': |
---|
49 | parts = path.rsplit('/', 1) |
---|
50 | if len(parts) == 2: |
---|
51 | parent, id_ = parts |
---|
52 | else: |
---|
53 | yield item; continue |
---|
54 | if id_ != IMAGE_FOLDER: |
---|
55 | yield item; continue |
---|
56 | |
---|
57 | obj = self.context.unrestrictedTraverse(path, None) |
---|
58 | if obj is None: # path doesn't exist |
---|
59 | yield item; continue |
---|
60 | |
---|
61 | if type_ == 'Blog' and newtype == 'Large Plone Folder': |
---|
62 | # mark as blog |
---|
63 | if not IWeblogEnhanced.providedBy(obj) and \ |
---|
64 | IPossibleWeblog.providedBy(obj): |
---|
65 | alsoProvides(obj, IWeblogEnhanced) |
---|
66 | event.notify(WeblogActivationEvent(obj)) |
---|
67 | elif type_ is None and newtype == 'Large Plone Folder': |
---|
68 | # pulish 'images' subfolder |
---|
69 | parent = self.context.unrestrictedTraverse(parent, None) |
---|
70 | if IWeblogEnhanced.providedBy(parent) : |
---|
71 | try: |
---|
72 | self.wftool.doActionFor(obj, 'publish') |
---|
73 | except WorkflowException: |
---|
74 | pass |
---|
75 | |
---|
76 | yield item |
---|
77 | |
---|
78 | # reindex provided interfaces |
---|
79 | catalog = utils.getToolByName(self.context, 'portal_catalog') |
---|
80 | catalog.reindexIndex('object_provides', None) |
---|