From squishdot to quillsΒΆ

Tags: quills, plone

I copy/pasted an existing piece of migration code out of Quills and modified it for my needs - and stuck it into the the installer for the product I'm using to store my templates and so in:

    def _createWeblogEntry(quills, id, oldid, title, desc, publishDate,
                           urldate, text, topics):
        quills.invokeFactory(id=id,
                             type_name='WeblogEntry',
                             title=title,
                             description=desc,
                             text=text)
        new_obj = getattr(quills, id)
        new_obj.setEffectiveDate(publishDate)
        new_obj.setEntryCategories(topics)
        new_obj.setContentType('text/structured', key='text')
        #wft = getToolByName(self, 'portal_workflow')
        #wft.doActionFor(new_obj, 'publish')
        out.write("Added blog entry %s.\n" % id)
        out.write("apache: %s => archive/%s/%s.\n" % (oldid, urldate, id))

    def migrateSquishdot(portal):
        # These are some values that are used to create
        # the Quills weblog
        quillsBlog = 'weblog'
        quillsTitle = 'Weblog'
        path = quillsBlog + '/drafts/'

        # Create the blog based on the values set above
        if hasattr(portal, quillsBlog):
            out.write("Quills log already exists, deleting it again.\n")
            portal.manage_delObjects(ids=[quillsBlog])
        portal.invokeFactory('Weblog', id=quillsBlog, title=quillsTitle)
        newblog = getattr(portal, quillsBlog)

        target = portal.restrictedTraverse(path)
        try:
            oldblog = portal.oldweblog
        except:
            out.write("Can't find old weblog, quitting.\n")
            return
        qtool = portal.quills_tool

        for entry in oldblog.data.values():
            title = entry.title
            desc = ''
            body1 = '\n'.join(entry.summary)
            body2 = '\n'.join(entry.body)
            body = '\n'.join([body1, body2])
            oldid = entry.id
            id = qtool.idFromTitle(title, 'WeblogEntry', newblog)

            # Using the '%c' stftime was the only way I could
            # successfully migrate the effective time
            ltime = localtime(entry.created)
            date= strftime('%c', ltime)
            urldate = strftime('%Y/%m/%d', ltime)
            # Make sure we don't have the topic already, then add it
            oldBlogCat = entry.subject
            quillsTopic = qtool.idFromTitle(oldBlogCat, 'WeblogTopic', newblog)
            if quillsTopic not in [blogTopic.getId() for blogTopic in
                                   newblog.getTopics() ]:
                newblog.invokeFactory('WeblogTopic',
                                      id=quillsTopic,
                                      title=oldBlogCat)
                out.write("Added topic '%s'.\n" % quillsTopic)
            _createWeblogEntry(target, id, oldid, title, desc, date,
                               urldate, body, [quillsTopic])

Note that I moved the old weblog over to /weblog_old/ for the time being so that I could create the quills weblog directly into a fresh new /weblog.

 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):