source: products/quintagroup.transmogrifier.simpleblog2quills/branches/without_image_move/quintagroup/transmogrifier/simpleblog2quills/cleaner.py @ 1249

Last change on this file since 1249 was 1249, checked in by koval, 15 years ago

added pipeline section for cleaning of blog entries (doesn't work now)

File size: 1.7 KB
Line 
1import logging
2from zope.interface import classProvides, implements
3
4from collective.transmogrifier.interfaces import ISectionBlueprint
5from collective.transmogrifier.interfaces import ISection
6
7from Acquisition import aq_inner, aq_parent
8from Products.CMFCore import utils
9
10log = logging.getLogger('quintagroup.transmogrifier.simpleblog2quills.blogentrycleaner')
11
12class BlogEntryCleaner(object):
13    classProvides(ISectionBlueprint)
14    implements(ISection)
15
16    def __init__(self, transmogrifier, name, options, previous):
17        self.transmogrifier = transmogrifier
18        self.context = transmogrifier.context
19        self.previous = previous
20
21    def __iter__(self):
22        for entry in self.getNotEmptyEntries():
23            self.moveContainedUp(entry)
24
25        for item in self.previous:
26            yield item
27
28    def moveContainedUp(self, entry):
29        """ Move contained object from blog entry one level up.
30        """
31        entry = aq_inner(entry)
32        ids = entry.contentValues()
33
34        log.info('Moving from %s BlogEntry next object: %s' % (entry.getId(), ids))
35        copy_data = entry.manage_cutObjects(ids)
36        parent = aq_parent(entry)
37        # xxx: next method call raises exception
38        parent.manage_pasteObjects(copy_data)
39
40    def getNotEmptyEntries(self):
41        """ Find all blog entries in the site that have contained objects.
42        """
43        not_empty = []
44        catalog = utils.getToolByName(self.context, 'portal_catalog')
45        for entry in catalog(portal_type='BlogEntry'):
46            entry = entry.getObject()
47            contained = entry.contentIds()
48            if contained:
49                not_empty.append(entry)
50        return not_empty
Note: See TracBrowser for help on using the repository browser.