Пример #1
0
 def post(self):
     key = self.request.get("key")
     logging.info(key)
     content = self.request.get("content")
     ip = self.request.remote_addr
     user_agent =  escape(self.request.headers.get('User-Agent','Firefox'))
     if not content.strip():
         return self.json({'error':u"内容不能为空"})
     dis = Discussion.get_by_key_name(key)
     if dis is None:
         return self.json({'error':u"不要非法提交哦"})
     if dis.is_closed:
         return self.json({'error':u"评论已经关闭"})
     comment = Comment.new(self.user,dis,content,ip=ip,user_agent=user_agent)
     self.template_value['comment']=comment
     return self.json({'success':True,'comment':self.get_render("comment.html")})
Пример #2
0
 def post(request,tag):
    title = request.request.get("title").strip()
    content = request.request.get("content")
    slug = request.request.get("slug","")
    
    kwargs = {
       'ip':request.request.remote_addr,
       'user_agent': escape(request.request.headers.get('User-Agent','Firefox')),
       'f':'M',
       }
    
    #Validate
    if len(title) >0 and len(content)>0:
       dis =Discussion.add(tag,slug,title,content,request.user,**kwargs)
       request.redirect(dis.url)
    request.template_value['error']=u"不要忘记标题或内容哦"
    request.template_value['tag']=tag
    request.template_value['title']=title
    request.template_value['content']=content
    request.render(cls.get_template_name('add'))