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 | try: |
---|
9 | from zope.interface import alsoProvides |
---|
10 | from quills.core.interfaces.enabled import IWeblogEnhanced, IPossibleWeblog |
---|
11 | from Products.QuillsEnabled.activation import WeblogActivationEvent |
---|
12 | except 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 | |
---|
17 | class 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 |
---|