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