Esempio n. 1
0
File: migr.py Progetto: philn/alinea
def migrateSections(sections):

    for section in sections:
        parent = section.parent
        if not parent:
            newParent = rootSection
        else:
            newParent = AlineaSection.select(AlineaSection.q.publicID == parent.id)[0]

        newSection = AlineaSection(name=section.name)
        rgt = AlineaNode.openHole(newParent)
        newSection.set(lft=rgt, rgt=rgt + 1)
        newSection.publicID = section.id
        AlineaNode.clearCache()

        print "%s - %s" % (newSection.publicID, newSection.name)

        # Articles of section
        for article in section.alineaArticles:
            print "   - %s : %s" % (article.id, article.title)

            newArticle = AlineaArticle(
                title=article.title,
                data=article.data,
                format=article.format,
                date=article.date,
                lastModified=article.date,
                hits=0,
                published=article.published,
                html=article.html,
                alineaUser=article.alineaUser,
            )
            rgt = AlineaNode.openHole(newSection)
            newArticle.set(lft=rgt, rgt=rgt + 1, publicID=article.id)
            AlineaNode.clearCache()
            assert newArticle.publicID == article.id

            # Comments of the article
            for comment in article.comments:
                newComment = AlineaComment(
                    author=comment.author,
                    email=comment.email,
                    url=comment.url,
                    ip=comment.ip,
                    comment=comment.comment,
                    date=comment.date,
                )

                rgt = AlineaNode.openHole(newArticle)
                newComment.set(lft=rgt, rgt=rgt + 1, publicID=comment.id)
                AlineaNode.clearCache()
                print "      - %s | %s" % (newComment.publicID, newComment.comment[:20])
Esempio n. 2
0
def setup(connection=None):
    if connection:
        AlineaSection._connection = connection
    AlineaSection.dropTable(ifExists=True,cascade=True)
    AlineaSection.createTable()
    rootSection = AlineaSection(lft=1, rgt=2, name='Alinea')
    rootSection.publicID = 0
Esempio n. 3
0
File: migr.py Progetto: philn/alinea
tableCopy(OldAlineaUser, conn1, conn2)


OldAlineaSection._connection = conn1
AlineaSection._connection = conn2

OldAlineaArticle._connection = conn1
AlineaArticle._connection = conn2

OldAlineaComment._connection = conn1
AlineaComment._connection = conn2

AlineaNode._connection = conn2

rootSection = AlineaSection.select(AlineaSection.q.name == "Alinea")[0]


def migrateSections(sections):

    for section in sections:
        parent = section.parent
        if not parent:
            newParent = rootSection
        else:
            newParent = AlineaSection.select(AlineaSection.q.publicID == parent.id)[0]

        newSection = AlineaSection(name=section.name)
        rgt = AlineaNode.openHole(newParent)
        newSection.set(lft=rgt, rgt=rgt + 1)
        newSection.publicID = section.id
Esempio n. 4
0
    def save(self, request, forReal=True):
        """ update the article w/ the current value from the request """
        article = self.getArticle()

        article.title = self.requestValue('title')
        article.data = self.requestValue('data')
        article.format = f = self.requestValue('format')
        article.language = self.requestValue('language')
        
        warnings = ''
        ok = True

        if f == 'Raw':
            # cosmetic processings on raw data
            article.html  = Tools.beautyfullText( article.data )
        elif f == 'ReST':
            # ReST publishing
            article.html  = publisher.publish(article.data)
            warnings = publisher.getWarnings()
        else:
            # HTML data
            # XXX: big security hole here ? Tag Injection
            article.html = article.data

        if warnings != '':
            self.setMessage("Error: %s" % warnings)
            ok = False
        
        if forReal and ok:
            section = None

            # enable section stuff only if saving article for real
            if self.requestValue('section'):
                from Alinea.Sections.AlineaSection import AlineaSection

                sectionId = int(self.requestValue('section'))
                section = AlineaSection.get(sectionId)
                if not isinstance(article, VirtualRow) and article.getParent().publicID != section.publicID:
                    article.moveTo(section)

            if section is None:
                raise ValueError("You need to put the Article in a Section ...")

            if isinstance(article, VirtualRow):
                del article['alineaComments']
                del article['publicID']
                del article['alineaSection']
                del article['alineaSectionID']

                self.delArticleFromSession(article)
                article.alineaUser = self.getLoggedUser()
                article = article.insertAndGetRow()

                rgt = AlineaNode.openHole(section)
                article.set(lft=rgt, rgt=rgt+1)
                AlineaNode.clearCache()

            article.published = False
            article.touch()
            self.setSaved(True)
            self.setMessage("Article '%s' saved" % article.title)
            self.storeArticle(article)
                
        if forReal:
            if ok:
                #self.refreshPageCache('Welcome',
                return request.response.redirect(article.admin_url())
            else:
                return self.render()
        else:
            self.storeArticle(article)
            return ok