示例#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
def Alinea_addArticle(title, format, data, published, alineaSectionID,
                      alineaUser):
    from Alinea.Sections.AlineaSection import Alinea_getSectionWithID
    from Alinea.AlineaLib import Tools, ReST
    
    section = Alinea_getSectionWithID(alineaSectionID)
    warnings = ""
    publisher = ReST.Publisher()
    
    if format == 'Raw':
        # cosmetic processings on raw data
        html  = Tools.beautyfullText(data)
    elif format == 'ReST':
        # ReST publishing
        html  = publisher.publish(data)
        warnings = publisher.getWarnings()
    else:
        # HTML data
        html = data

    if warnings:
        raise ValueError(warnings)
    
    article = AlineaArticle(title=title, format=format, data=data,
                            html=html, #alineaSection=section,
                            alineaUser=alineaUser)
    rgt = AlineaNode.openHole(section)
    article.set(lft=rgt, rgt=rgt+1)

    
    userRoles = [ r.label for r in alineaUser.roles ]
    if 'publisher' in userRoles and published:
        article.published = True
    return article
示例#3
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])
示例#4
0
 def _create(self, id, **kw):
     publicIds = [c.publicID for c in AlineaComment.select()]
     if publicIds:
         if not kw.has_key('publicID') or not kw['publicID']:
             publicID = max(publicIds)
             kw['publicID'] = publicID + 1
     else:
         kw['publicID'] = 1
     return AlineaNode._create(self, id, **kw)
示例#5
0
 def title_or_id(self):
     from Alinea.Articles.AlineaArticle import AlineaArticle
     parent = self.getParent()
     parentTitle = parent.title_or_id()
     title = AlineaNode.title_or_id(self)
     
     try:
         parentParent = parent.getParent()
         match = re.match("(.*)\son\s(.*)", parentParent.title_or_id())
     except AttributeError:
         parentParent = None
         match = None
     
     if isinstance(parent, AlineaComment):
         if isinstance(parentParent, AlineaComment) and match:
             author = match.groups()[0]
             title = "%s replies to %s" % (self.author, author)
         else:
             title = "%s replies to %s" % (self.author, parentTitle)
     elif isinstance(parent, AlineaArticle):
         title = "%s on %s" % (self.author, parentTitle)
     return title
示例#6
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()
示例#7
0
文件: install.py 项目: philn/alinea
def setup(connection=None):
    if connection:
        AlineaNode._connection = connection
    AlineaNode.dropTable(ifExists=True,cascade=True)
    AlineaNode.createTable()
示例#8
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