コード例 #1
0
ファイル: views.py プロジェクト: CJljfn/miniblog
    def POST(self, id=1):
        pre_articals, pre_links, pre_comments, pre_categories = get_left_objs()
        id = int(id)
        comment_children = []
        
        artical_handler = get_col_handler('artical')
        artical = artical_handler.find_one({'id':id})
        comment_handler = get_col_handler('comment')
        comments = comment_handler.find({'artical_id':id})
        if comments.count():
            for comment in comments:
                children = get_comments_in_comment(comment['id'])
                comment_children.append([comment, children])        
        form = commentf()
        if not form.validates():
            return self.render.artical_detail(pre_articals=pre_articals,
                                              pre_links=pre_links, 
                                              pre_comments=pre_comments,
                                              pre_categories=pre_categories,
                                              artical=artical,
                                              form=form, 
                                              comments=comment_children)
        check = web.input().get('remember_me', 'false')
        artical_id = web.input().get('artical_id', 1)
        name = web.input().get('name', '')
        email = web.input().get('email', '')
        website = web.input().get('website', '')
        content = web.input().get('content', '')
        comment_id = web.input().get('comment_id', 0)
        
        params = dict(name=urllib.quote(smart_str(name)), email=email, website=website)
        cookie_value = pickle.dumps(params)
        if check == 'false':
            pass
        else:
            web.setcookie(COOKIE_NAME, cookie_value, expires=2592000)
        comment = Comment(artical_id,
                          name,
                          email,
                          website,
                          content,
                          comment_id)
        comment.save()
        # TODO:Package this part
        comment_obj = comment_handler.find_one({'id':int(comment_id)})
        if int(comment_id) != 0:
#            comment_obj = comment_handler.find_one({'id':int(comment_id)})
            send_email(comment_obj.get('email', ''), u'来自%s的回复' % name, \
u'%s\n详情请看:http://www.cj53.com/click/%s' % (content, artical_id))
        send_email('*****@*****.**', u'有留言', \
u'%s\n详情请看:http://www.cj53.com/click/%s' % (content, artical_id))        
        if id == 1:
            raise web.seeother("/board")
        return web.seeother("/artical/%s" % id)
コード例 #2
0
ファイル: views.py プロジェクト: CJljfn/miniblog
 def GET(self, id=1):
     pre_articals, pre_links, pre_comments, pre_categories= get_left_objs()
     id = int(id)
     comment_children = []
     
     artical_handler = get_col_handler('artical')
     comment_handler = get_col_handler('comment')
     comments = comment_handler.find({'artical_id':id})
     if comments.count():
         for comment in comments:
             children = get_comments_in_comment(comment['id'])
             comment_children.append([comment, children])
     artical = artical_handler.find_one({'id':id})
     form = commentf()
     
     
     cookie = web.cookies().get(COOKIE_NAME, None)
     name = email = website = ''
     if cookie:
         cookie = pickle.loads(cookie)
         name = urllib.unquote(cookie.get('name', ''))
         email = cookie.get('email', '')
         website = cookie.get('website', '')
     
     form.fill({'artical_id':int(id), 
                'id':0, 
                'comment_id':0,
                'name':name,
                'email':email,
                'website':website})
     if not artical:
         return "<script>alert('别乱点!');window.location.href='/';</script>"
     return self.render.artical_detail(pre_articals=pre_articals,
                                       pre_links=pre_links, 
                                       pre_comments=pre_comments,
                                       pre_categories=pre_categories,
                                       artical=artical,
                                       form=form, 
                                       comments=comment_children)