Exemplo n.º 1
0
Arquivo: migr.py Projeto: 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])
Exemplo n.º 2
0
 def getArticleWithTitle(self,value):
     "return the first article w/ the name in this section"
     articles = AlineaArticle.select( AND (AlineaArticle.q.title == value,
                                           AlineaArticle.q.alinea_sectionID == self.publicID) )
     try:
         return articles[0]
     except IndexError:
         return None
Exemplo n.º 3
0
 def getArticles(self):
     """ Return the list of articles """
     begin = self.getBegin()
     end = begin + self.getRange()
     orderBy = self.getOrderBy()
     reverse = self.getReverse()
     articles = list(AlineaArticle.select(self.getClause(), orderBy=AlineaArticle.q.date,
                                          reversed=reverse)[begin:end] )
     return articles
Exemplo n.º 4
0
Arquivo: Atom.py Projeto: philn/alinea
 def getLastModifiedDate(self):
     try:
         lastArticle = AlineaArticle.select(AlineaArticle.q.published==True,
                                                 orderBy='-date')[:1]
         lastArticle = lastArticle[0]            
     except IndexError:
         return datetime.datetime.now()
     else:
         return lastArticle.lastModified
Exemplo n.º 5
0
def setup(connection=None):
    if connection:
        AlineaArticle._connection = connection
    AlineaArticle.dropTable(ifExists=True)
    AlineaArticle.createTable()
Exemplo n.º 6
0
 def getSize(self):
     query = AlineaArticle.select(self.getClause())
     size = query.count()
     return size
Exemplo n.º 7
0
Arquivo: Atom.py Projeto: philn/alinea
 def getArticles(self,orderBy='date'):
     " return the last 10 articles "
     articles = list(AlineaArticle.select(AlineaArticle.q.published==True,
                                          orderBy=orderBy, reversed=True)[0:10] )
     return articles
Exemplo n.º 8
0
    def getMatchedArticles(self):
        from Alinea.Articles.AlineaArticle import AlineaArticle

        return AlineaArticle.search(self.getQuery())