Example #1
0
 def save(self, id=None):
     if id is None:
         abort(404)
         
     comment_q = meta.Session.query(model.Comment)
     comment = comment_q.filter_by(id=id).first()
     
     if comment is None:
         abort(404)
         
     if not h.auth.authorized(h.auth.is_valid_user) and not h.wurdig_use_akismet():
         if hasattr(self.form_result, 'wurdig_comment_question'):
             del self.form_result['wurdig_comment_question']
         
     for k,v in self.form_result.items():
         if getattr(comment, k) != v:
             setattr(comment, k, v)
     
     comment.content = h.mytidy(comment.content)
     comment.content = h.auto_link(comment.content)
     
     meta.Session.commit()
     session['flash'] = 'Comment successfully updated.'
     session.save()
     return redirect_to(controller='comment', action='list')
Example #2
0
 def _to_python(self, values, state):
     # we're in the administrator
     if request.urlvars['action'] == 'save':
         return values
     
     # this is a known bug.  context object
     # is not being passed properly to the conf_helper method call
     # since I don't use akismet I'm leaving this alone for now
     if h.wurdig_use_akismet():
         from wurdig.lib.akismet import Akismet
         # Thanks for the help from http://soyrex.com/blog/akismet-django-stop-comment-spam/
         a = Akismet(h.wurdig_get_akismet_key(), wurdig_url=request.server_name)
         akismet_data = {}
         akismet_data['user_ip'] = request.remote_addr
         akismet_data['user_agent'] = request.user_agent
         akismet_data['comment_author'] = values['name']
         akismet_data['comment_author_email'] = values['email']
         akismet_data['comment_author_url'] = values['url']
         akismet_data['comment_type'] = 'comment'
         spam = a.comment_check(values['content'], akismet_data)
         if spam:
             raise formencode.Invalid(
                 self.message('invalid-akismet', state),
                 values, state
             )
     return values
Example #3
0
    def create(self, action, post_id=None):
        if post_id is None:
            abort(404)
        post_q = meta.Session.query(model.Post)
        c.post = post_id and post_q.filter_by(id=int(post_id)).first() or None
        if c.post is None:
            abort(404)
            
        if not h.auth.authorized(h.auth.is_valid_user) and not h.wurdig_use_akismet():
            if hasattr(self.form_result, 'wurdig_comment_question'):
                del self.form_result['wurdig_comment_question']
            
        comment = model.Comment()
        for k, v in self.form_result.items():
            setattr(comment, k, v)
        comment.post_id = c.post.id

        comment.created_on = datetime.datetime.now()

        comment.content = h.nl2br(comment.content)
        comment.content = h.mytidy(comment.content)
        comment.content = h.comment_filter(comment.content)
        comment.content = h.auto_link(comment.content)
        
        if h.auth.authorized(h.auth.is_valid_user):
            comment.approved = True
            session['flash'] = 'Your comment has been approved.'
        else:
            session['flash'] = 'Your comment is currently being moderated.'
        # @todo: email administrator w/ each new comment
        session.save()
        
        meta.Session.add(comment)
        meta.Session.commit()
                
        return redirect_to(controller='post', 
                           action='view', 
                           year=c.post.posted_on.strftime('%Y'),
                           month=c.post.posted_on.strftime('%m'),
                           slug=c.post.slug
                           )
Example #4
0
 def _to_python(self, values, state):
     # we're in the administrator
     if request.urlvars['action'] == 'save':
         return values
     
     if h.wurdig_use_akismet():
         from wurdig.lib.akismet import Akismet
         # Thanks for the help from http://soyrex.com/blog/akismet-django-stop-comment-spam/
         a = Akismet(h.wurdig_get_akismet_key(), wurdig_url=request.server_name)
         akismet_data = {}
         akismet_data['user_ip'] = request.remote_addr
         akismet_data['user_agent'] = request.user_agent
         akismet_data['comment_author'] = values['name']
         akismet_data['comment_author_email'] = values['email']
         akismet_data['comment_author_url'] = values['url']
         akismet_data['comment_type'] = 'comment'
         spam = a.comment_check(values['content'], akismet_data)
         if spam:
             raise Invalid(
                 self.message('invalid-akismet', state),
                 values, state
             )
     return values