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])
def getComments(self): """ Return the list of articles """ begin = self.getBegin() end = begin + self.getRange() orderBy = self.getOrderBy() reverse = self.getReverse() comments = list(AlineaComment.select("all", orderBy=AlineaComment.q.date, reversed=reverse)[begin:end]) return comments
def delete(self, request): comments = self.requestValue("comments") if comments is None: comments = [] elif type(comments) != type([]): comments = [comments] deleted = [AlineaComment.delete(int(commentID)) for commentID in comments] self.setMessage("Deleted %d comments" % len(deleted)) begin = self.getBegin() return self.redirect(request)
def setup(connection=None): if connection: AlineaComment._connection = connection AlineaComment.dropTable(ifExists=True) AlineaComment.createTable()
def getAllComments(self): return list(AlineaComment.select("all", orderBy="id"))
def getSize(self): query = AlineaComment.select() size = query.count() return size
def getComments(self, orderBy=AlineaComment.q.date): " return the last 10 comments " comments = list(AlineaComment.select("all", orderBy=orderBy, reversed=True)[0:10]) return comments
def getComments(self, orderBy='date'): " return the last 10 comments " comments = list(AlineaComment.select('all',orderBy=orderBy, reversed=True)[0:10] ) return comments
def getMatchedComments(self): from Alinea.Comments.AlineaComment import AlineaComment return AlineaComment.search(self.getQuery())