def get(self): recentComments = Comment.all().order('-commentTime').fetch(10) recentBlogs = Blog.all().order('-createTimeStamp').fetch(5) links = Link.all() template_values = { 'recentComments': recentComments, 'recentBlogs': recentBlogs, 'links': links } blogid = self.param('p') if (blogid): blogid = int(blogid) blogs = Blog.all().filter('blog_id =', blogid).fetch(1) blog = blogs[0] comments = Comment.all().filter("ownerBlog =", blog).order('commentTime') template_values.update({'blog': blog, 'comments': comments}) self.generateBasePage('singleblog.html', template_values) else: pageIndex = self.param('page') if (pageIndex): pageIndex = int(pageIndex) else: pageIndex = 1 blogs = Blog.all().order('-createTimeStamp') pager = PageManager(query=blogs, items_per_page=blogSystem.posts_per_page) blogs, links = pager.fetch(pageIndex) template_values.update({'blogs': blogs, 'pager': links}) self.generateBasePage('main.html', template_values) return
def post(self,page): code=page.param("code") OptionSet.setValue("Akismet_code",code) rm=page.param('autorm') if rm and int(rm)==1: rm=True else: rm=False oldrm = OptionSet.getValue("Akismet_AutoRemove",False) if oldrm!=rm: OptionSet.setValue("Akismet_AutoRemove",rm) spam=page.param("spam") spam = len(spam)>0 and int(spam) or 0 sOther = "" if spam>0: cm = Comment.get_by_id(spam) try: url = Blog.all().fetch(1)[0].baseurl self.SubmitAkismet({ 'user_ip' : cm.ip, 'comment_type' : 'comment', 'comment_author' : cm.author.encode('utf-8'), 'comment_author_email' : cm.email, 'comment_author_url' : cm.weburl, 'comment_content' : cm.content.encode('utf-8') },url,"Spam") sOther = u"<div style='padding:8px;margin:8px;border:1px solid #aaa;color:red;'>评论已删除</div>" cm.delit() except: sOther = u"<div style='padding:8px;margin:8px;border:1px solid #aaa;color:red;'>无法找到对应的评论项</div>" return sOther + self.get(page)
def get(self): blogs = Blog.all().order('-createTimeStamp').fetch(10) template_values = { 'blogs': blogs } self.generateBasePage('manage/blogs.html',template_values) return
def get(self): blogs = Blog.all().order('-createTimeStamp').fetch(10) if blogs and blogs[0]: lastUpdateTime = blogs[0].createTimeStamp lastUpdateTime = lastUpdateTime.strftime("%Y-%m-%dT%H:%M:%SZ") for blog in blogs: blog.formatDate = blog.createTimeStamp.strftime( "%Y-%m-%dT%H:%M:%SZ") self.response.headers['Content-Type'] = 'application/atom+xml' values = {'blogs': blogs, 'lastUpdateTime': lastUpdateTime} self.generateBasePage('atom.xml', values)
def get(self,page): code=OptionSet.getValue("Akismet_code",default="") up=OptionSet.getValue("Akismet_Comments_v0.3",default=[]) if type(up)!=type([]): up=[] delkey = page.param('delkey') rekey = page.param('rekey') if rekey or delkey: newup = [] for i in up: cmtkey = i['key'][0]; enykey = i['key'][1]; if delkey and cmtkey==delkey: cm = Comment.get(cmtkey) db.Model.delete(cm) elif rekey and cmtkey==rekey: cm = Comment.get(cmtkey) eny = Entry.get(enykey) eny.commentcount+=1 eny.put() cm.entry = eny db.Model.put(cm) self.SubmitAkismet({ 'user_agent':i['other']['user_agent'], 'referrer':i['other']['referrer'], 'user_ip' : cm.ip, 'comment_type' : 'comment', 'comment_author' : cm.author.encode('utf-8'), 'comment_author_email' : cm.email, 'comment_author_url' : cm.weburl, 'comment_content' : cm.content.encode('utf-8') },i['other'].get('url',''),"Ham") else: newup.append(i) if not len(up)==len(newup): OptionSet.setValue("Akismet_Comments_v0.3",newup) up = newup cmts = [(Comment.get(i['key'][0]),Entry.get(i['key'][1])) for i in up] comments = [u'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a target="_blank" href="/%s">%s</a></td><td><a href="?delkey=%s" title="删除">删除</a> <a href="?rekey=%s" title="这不是一个垃圾评论">还原</a></td></tr>'%(i[0].date, i[0].author,i[0].content,i[0].email,i[0].ip,i[1].link,i[1].title,str(i[0].key()),str(i[0].key())) for i in cmts] comments = ''.join(comments) apikey = OptionSet.getValue("Akismet_code",default=self.AKISMET_default_Key) if len(apikey)<5: apikey = self.AKISMET_default_Key api = AkismetManager(apikey,Blog.all()[0].baseurl) if not code: status = '' elif api.IsValidKey(): status = 'True' else: status = 'False' return u'''<h3>Akismet</h3> <form action="" method="post"> <p>Akismet Api Key:</p> <input name="code" style="width:400px;" value="%s"> %s <br /> <p>删除一条评论并提交Spam(输入评论的ID):</p> <input name="spam" style="width:400px;" value=""> <br /> <input type="submit" value="submit"> </form> <div> <br /> <h3>被过滤的评论</h3> <table class="widefat"><thead><tr><th>日期</th><th>作者</th><th>内容</th><th>电子邮件</th><th>IP地址</th><th>文章/页面</th><th style="width:15%%;">选择操作</th></tr></thead><tbody>%s </tbody></table> </div>'''%(code,status,comments)
def get(self): blogs = Blog.all().order('-createTimeStamp').fetch(10) template_values = {'blogs': blogs} self.generateBasePage('manage/blogs.html', template_values) return
def get(self, page): code = OptionSet.getValue("Akismet_code", default="") up = OptionSet.getValue("Akismet_Comments_v0.3", default=[]) rm = OptionSet.getValue("Akismet_AutoRemove", False) if type(up) != type([]): up = [] delkey = page.param("delkey") rekey = page.param("rekey") if rekey or delkey: newup = [] for i in up: cmtkey = i["key"][0] enykey = i["key"][1] if delkey and cmtkey == delkey: cm = Comment.get(cmtkey) db.Model.delete(cm) elif rekey and cmtkey == rekey: cm = Comment.get(cmtkey) eny = Entry.get(enykey) eny.commentcount += 1 eny.put() cm.entry = eny db.Model.put(cm) self.SubmitAkismet( { "user_agent": i["other"]["user_agent"], "referrer": i["other"]["referrer"], "user_ip": cm.ip, "comment_type": "comment", "comment_author": cm.author.encode("utf-8"), "comment_author_email": cm.email, "comment_author_url": cm.weburl, "comment_content": cm.content.encode("utf-8"), }, i["other"].get("url", ""), "Ham", ) else: newup.append(i) if not len(up) == len(newup): OptionSet.setValue("Akismet_Comments_v0.3", newup) up = newup cmts = [(Comment.get(i["key"][0]), Entry.get(i["key"][1])) for i in up] comments = [ u'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a target="_blank" href="/%s">%s</a></td><td><a href="?delkey=%s" title="删除">删除</a> <a href="?rekey=%s" title="这不是一个垃圾评论">还原</a></td></tr>' % ( i[0].date, i[0].author, i[0].content, i[0].email, i[0].ip, i[1].link, i[1].title, str(i[0].key()), str(i[0].key()), ) for i in cmts if i is not None and i[0] is not None ] comments = "".join(comments) apikey = OptionSet.getValue("Akismet_code", default=self.AKISMET_default_Key) if len(apikey) < 5: apikey = self.AKISMET_default_Key api = AkismetManager(apikey, Blog.all()[0].baseurl) if not code: status = "" elif api.IsValidKey(): status = "True" else: status = "False" if rm == True: rmchecked = 'checked="checked"' else: rmchecked = "" return u"""<h3>Akismet</h3> <form action="" method="post"> <p>Akismet Api Key:</p> <input name="code" style="width:400px;" value="%s"> %s <br /> <p>自动删除检测到的垃圾评论: <input type="checkbox" name="autorm" value="1" %s></p> <p>删除一条正常的评论并提交Spam(输入评论的ID):</p> <input name="spam" style="width:400px;" value=""> <br /> <input type="submit" value="submit"> </form> <div> <br /> <h3>被过滤的评论</h3> <table class="widefat"><thead><tr><th>日期</th><th>作者</th><th>内容</th><th>电子邮件</th><th>IP地址</th><th>文章/页面</th><th style="width:15%%;">选择操作</th></tr></thead><tbody>%s </tbody></table> </div>""" % ( code, status, rmchecked, comments, )