예제 #1
0
파일: Section.py 프로젝트: philn/alinea
    def save(self, request):
        """ update the section w/ the current value from the request """
        section = self.getSectionOrError()
        if not section:
            self.renderPage()

        parent = self.requestValue("parent")
        if parent == "" or section.id == int(parent):
            parent = None
        else:
            parent = AlineaSection.Alinea_getSectionWithID(parent)

        if isinstance(section, VirtualRow):
            del section["parentID"]
            section = section.insertAndGetRow()
            rgt = AlineaNode.openHole(parent)
            section.set(lft=rgt, rgt=rgt + 1)
            AlineaNode.clearCache()
            self.delFromSession("editingSections")

        elif section.getParent().publicID != parent.publicID:
            section.moveTo(parent)

        section.name = self.requestValue("name")

        self.setMessage("Section '%s' saved" % section.name)
        return self.back(request)
예제 #2
0
파일: migr.py 프로젝트: 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])
예제 #3
0
파일: Comment.py 프로젝트: philn/alinea
    def postComment(self,request,forReal=True):
        " comment saving for real or not (preview) "

        # spam protection
        if self.requestValue('obscuratedID',0) != self.getObscuratedID() :
            # if the id isn't the same as in session someone try f**k me
            # we should place a better Error message here ?
            print "SPAM Protection:"
            print " request value: %s" % self.requestValue('obscuratedID',0)
            print " cookie  value: %s" % self.getObscuratedID()

            self.setMessage("You are not allowed to post here since you don't seems to try to hack / or don't accept cookies")
            self.delEditingComment()
            return self.redirect()

        comment = self.getEditingComment()
        comment.url = self.requestValue('url')
        comment.author  = self.requestValue('name')
        comment.email = self.requestValue('email')
        comment.format = self.requestValue('format')
        comment.ip = self.request.environ['REMOTE_ADDR']

        data  = self.requestValue('comment')
        comment.comment = data
        date = time.localtime()[0:6]
        comment.date = mx.DateTime.ISO.Date(*date)
        warnings = ''

        if comment.format == 'Raw':
            # cosmetic processings on raw data
            data  = Tools.beautyfullText( data )
        elif comment.format == 'ReST':
            # ReST publishing
            data  = publisher.publish(data)
            warnings = publisher.getWarnings()

        commentable = self.getObject()
        
        if warnings:
            self.setMessage('ReST Error:'+warnings)
            comment.html = ''
        else:
            if not commentable.allowComments():
                return self.redirect()
            
            # XXX: big security hole here ? Tag Injection
            comment.html = data
            if forReal:
                comment.comment = comment.html
                # deletion of non available fields in table schema
                del comment['html']
                del comment['format']
                
                comment = comment.insertAndGetRow()                
                rgt = AlineaNode.openHole(commentable)
                comment.set(lft=rgt, rgt=rgt+1)
                AlineaNode.clearCache()
                
                self.delEditingComment()
            else:
                self.setEditingComment(comment)

        if forReal:
            self.setHtmlPreview('')
            self.delEditingComment()
            
            self.refreshPageCache('Welcome','Welcome_content')
            print '>>> REFRESH <<<'
            articleId = None
            for obj in comment.path():
                objId = obj.publicID
                try:
                    objType = obj.getTypeAsString()
                except:
                    continue
                if objType == 'Article':
                    articleId = objId
                self.refreshPageCache(objType, '%s_content' % objType, objId)

            if articleId:
                # TODO: refresh cache on Feeds
                #pass
                #import pdb; pdb.set_trace()
                self.refreshPageCache('Article','comment_content', articleId)
                
            print '>>> REFRESH <<<'
            
            # TODO: depending on whatever redirect to anywhere else
            return self.redirect()
예제 #4
0
파일: Article.py 프로젝트: philn/alinea
    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