Logo Search packages:      
Sourcecode: zope-coreblog version File versions

def zope-coreblog-1.0::Entry::Entry::addComment (   self,
  title,
  author,
  body,
  moderated = 1,
  email = "",
  url = "",
  created = "",
  REQUEST = None 
)

Add a comment 

Definition at line 461 of file Entry.py.

00461                                                                                                 :
        """ Add a comment """
        if self.allow_comment != comment_open:
            #This entry does not allow adding comment
            raise RuntimeError,"This entry is closed for adding comment."
        #COREBlog instanse
        cb = self.blog()

        #Validaters
        v_h = cb.removeHTML
        v_c = cb.validateCommentBody
        comment_id = cb.getNewCommentID()
        title = v_h(title)
        author = v_h(author)
        email = v_h(email)
        url = v_h(url)
        body = v_c(body)

        #moderation
        try:
            if cb.getProperty("moderate_comment"):
                moderated = 0
        except:
            pass

        #check values
        if REQUEST:
            REQUEST_bk = self.checkCommentValues(title,author,body,moderated,email,url,REQUEST)
            if REQUEST_bk.form.has_key("show_worning"):
                return self.previewcomment_html(self,REQUEST_bk)

        #name
        if not author and \
            cb.hasProperty("require_name") and cb.getProperty("require_name") == 0 and \
            cb.hasProperty("anonymous_name"):
            author = cb.getProperty("anonymous_name")

        sec = -1
        if created:
            try:
                dt = DateTime(created)
                sec = int(dt)
            except:
                pass
        obj = Comment(comment_id,self.id,title,author,email,url,body,int(moderated),sec)

        self.comments.insert(comment_id)
        cb.setComment(comment_id,obj)

        if moderated:
            self.moderated_comment_count = self.moderated_comment_count + 1
            #catalogging...
            self.index()


        #set cookie
        if REQUEST and REQUEST.form.has_key('setcookie'):
            resp = REQUEST.RESPONSE
            #path = join(self.aq_parent.getPhysicalPath(),'/');
            path = "/"
            gtime = gmtime(time())
            gtup = (gtime[0] + 1,12,31,23,59,59,0,365,0)
            exp = strftime('%A, %d-%b-%y %H:%M:%S GMT',gtup)

            #exp = (self.ZopeTime() + 365).rfc822()

            resp.setCookie('comment_author',author,expires=exp,path=path)
            resp.setCookie('comment_email',email,expires=exp,path=path)
            resp.setCookie('comment_url',url,expires=exp,path=path)

        #tell ZODB that object has added.
        self._p_changed = 1

        #call the hook method
        call_addcomment_hook(self.aq_parent,comment_id,self.id,v_h(title),v_h(author), \
                                v_c(body),int(moderated),v_h(email),v_h(url))

        if REQUEST:
            return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])


    security.declareProtected(AddCOREBlogComments, 'previewComment')


Generated by  Doxygen 1.6.0   Back to index