def get(self,slug,key,p="1"): dis = get_or_404(Discussion.get_discussion_by_key,slug,key) p = int(p) #check ACL check_roles(self,dis.role) #handler visit log if not self.user is None: key = "%s%s" %(self.user.name_lower,self.p) logs = memcache.get(":visitlogs:") if logs is None: logs = set([]) logs.add(key) memcache.set(":visitlogs:",logs,3600) self.template_value['f_tag']={'key':dis.tag_slug,'title':dis.tag_title,'show':'G' in dis.role,'post':True} self.template_value['disviews']=ShardCount.get_increment_count("disviews:"+key,"disviews") self.template_value['dis']=dis bookmark = Bookmark.get_bookmark(self.user,dis) if self.user else None self.template_value['bookmark'] = bookmark #comment page comments = PagedQuery(Comment.get_by_dis(dis),self.setting.comment_pagesize) temp = comments.fetch_page(p) self.template_value['prev']= p-1 if p>1 else None self.template_value['next']= p+1 if len(temp) == self.setting.comment_pagesize else None self.template_value['comments'] = temp self.template_value['p']=p self.render("dis.html")
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")})
def get(self, slug, key, p="1"): dis = get_or_404(Discussion.get_discussion_by_key, slug, key) p = int(p) # check ACL check_roles(self, dis.role) # handler visit log if not self.user is None: key = "%s%s" % (self.user.name_lower, self.p) logs = memcache.get(":visitlogs:") if logs is None: logs = set([]) logs.add(key) memcache.set(":visitlogs:", logs, 3600) self.template_value["f_tag"] = { "key": dis.tag_slug, "title": dis.tag_title, "show": "G" in dis.role, "post": True, } # self.template_value['disviews']= dis.count_view = ShardCount.get_increment_count("disviews:" + key, "disviews") dis.put() self.template_value["dis"] = dis bookmark = Bookmark.get_bookmark(self.user, dis) if self.user else None self.template_value["bookmark"] = bookmark # comment page comments = PagedQuery(Comment.get_by_dis(dis), self.setting.comment_pagesize) temp = comments.fetch_page(p) self.template_value["prev"] = p - 1 if p > 1 else None self.template_value["next"] = p + 1 if len(temp) == self.setting.comment_pagesize else None self.template_value["comments"] = temp self.template_value["p"] = p self.render("dis.html")
def post(self, request, pk): t = get_object_or_404(Thread, id=pk) comment = Comment(text=request.POST['text'], thread=t) # comment.save() return redirect(reverse_lazy('discussion:detail', args=[pk]))
def post(self): key = self.request.get("key") content = self.request.get("content") dis = get_or_404(Discussion.get_by_key_name,key) comment =Comment.new(self.user,dis,content) self.redirect(comment.url)