def GET(self,slug=None): try: page_index=int(self.param('page')) except: page_index=1 cq=self.param('cq') cv=self.param('cv') if cq and cv: query=Comment.all().filter(cq+' =',cv).order('-date') else: query=Comment.all().order('-date') comments,pager=Pager(query=query,items_per_page=15).fetch(page_index) self.render2('views/admin/comments.html', { 'current':'comments', 'comments':comments, 'pager':pager, 'cq':cq, 'cv':cv } )
def article(request, article_id): query = db.GqlQuery("SELECT * FROM Article ORDER BY id DESC") latest_articles = query.fetch(8) query= db.GqlQuery("SELECT * FROM Comment ORDER BY comment_id DESC") latest_comments = query.fetch(5) archive_list = gen_archive_list() ar = Article.all() ar.filter("id =", article_id) tags = [] this_article = None for t in ar: this_article = t if this_article: tags = filter(None,this_article.tags.split(' ')) co = Comment.all() co.filter("article_id =", article_id) co.order("comment_id") user = users.get_current_user() is_admin=users.is_current_user_admin() t = loader.get_template('blog/article.html') if this_article: c = Context({ 'article': this_article, 'now_comments':co, 'tags':tags, 'latest_articles': latest_articles, 'latest_comments': latest_comments, 'archive_list' : archive_list, 'user' : user , 'is_admin' : is_admin, }) return HttpResponse(t.render(c)) else: return HttpResponseRedirect("/")
def home( request ): # get ongoing sub events subs = Subevent.all().filter( 'is_done =',False ).filter( 'start_date <=',today() ) se_list = [] for se in subs: item = {'se':se, 'days':( se.end_date - today() ).days} se_list.append( item ) se_list = sorted(se_list,key=lambda x:x['days']) # get recent history operation hi_list = History.all().order('-publish_time').fetch(5) comments = Comment.all().order('-publish_time').fetch(5) # get recent messages mes_li = Mes.all().order('-publish_time').fetch(5) tip = Tip.all().order('-publish_time').get() if tip: tip_content = tip.content else: tip_content = None c = Context({ 'logouturl':users.create_logout_url('/login'), 'loginurl':LOGIN, 'cur_user':CURUSER, 'is_admin':users.is_current_user_admin(), 'se_list':se_list, 'hi_list':hi_list, 'comments':comments, 'mes_li':mes_li, 'tip':tip_content, }) return render_to_response('home.htm',c)
def GET(self,tags=None): comments = Comment.all().order_by('-date').filter(ctype = 0)[0:10]#.fetch(10) if comments and comments[0]: last_updated = comments[0].date last_updated = last_updated.strftime("%a, %d %b %Y %H:%M:%S +0000") for e in comments: e.formatted_date = e.date.strftime("%a, %d %b %Y %H:%M:%S +0000") self.response.headers['Content-Type'] = 'application/rss+xml; charset=UTF-8' self.render2('views/comments.xml',{'comments':comments,'last_updated':last_updated})
def action_init_blog(self,slug=None): for com in Comment.all(): com.delete() for entry in Entry.all(): entry.delete() self.blog.entrycount=0 self.blog.save() self.write(_('"Init has succeed."'))
def initialize(self, request): m_pages=Entry.all().filter('entrytype =','page')\ .filter('published =',True)\ .filter('entry_parent =',0)\ .order('menu_order') blogroll=Link.all().filter('linktype =','blogroll') archives=Archive.all().order('-year').order('-month').fetch(12) alltags=Tag.all() self.template_vals.update({ 'menu_pages':m_pages, 'categories':Category.all(), 'blogroll':blogroll, 'archives':archives, 'alltags':alltags, 'recent_comments':Comment.all().order('-date').fetch(5) })
def initialize(self, request): BaseRequestHandler.initialize(self,request) m_pages=Entry.all().filter(entrytype = 'page') \ .filter(published = True)\ .filter(entry_parent = 0)\ .order_by('menu_order') blogroll=Link.all().filter(linktype = 'blogroll') #archives=Archive.all().order_by('-year').order_by('-month').fetch(12) archives=Archive.all().order_by('-year', '-month')[0:12] alltags=Tag.all() self.template_vals.update({ 'menu_pages':m_pages, 'categories':Category.all(), 'blogroll':blogroll, 'archives':archives, 'alltags':alltags, 'recent_comments':Comment.all().order_by('-date')[0:5]#.fetch(5) })
def action_getcomments(self): key=self.param('key') entry=Entry.get(key) comments=Comment.all().filter(entry = key) commentuser=self.request.cookies.get('comment_user', '') if commentuser: commentuser=commentuser.split('#@#') else: commentuser=['','',''] vals={ 'entry':entry, 'comments':comments, 'user_name':commentuser[0], 'user_email':commentuser[1], 'user_url':commentuser[2], 'checknum1':random.randint(1,10), 'checknum2':random.randint(1,10), } html=self.get_render('comments',vals) self.write(simplejson.dumps(html.decode('utf8')))
def POST(self,slug=None,postid=None): '''handle trackback''' error = '''<?xml version="1.0" encoding="utf-8"?> <response> <error>1</error> <message>%s</message> </response> ''' success = '''<?xml version="1.0" encoding="utf-8"?> <response> <error>0</error> </response> ''' if not self.blog.allow_trackback: self.response.out.write(error % "Trackback denied.") return self.response.headers['Content-Type'] = "text/xml" if postid: entries = Entry.all().filter(published = True).filter(post_id = postid)[0:1]#.fetch(1) else: slug=urldecode(slug) entries = Entry.all().filter(published = True).filter(link = slug)[0:1]#.fetch(1) if not entries or len(entries) == 0 :#or (postid and not entries[0].link.endswith(self.blog.default_link_format%{'post_id':postid})): self.response.out.write(error % "empty slug/postid") return #check code ,rejest spam entry=entries[0] logging.info(self.request.remote_addr+self.request.path+" "+entry.trackbackurl) #key=self.param("code") #if (self.request.uri!=entry.trackbackurl) or entry.is_external_page or not entry.allow_trackback: #import cgi from urlparse import urlparse param=urlparse(self.request.uri) code=param[4] param=cgi.parse_qs(code) if param.has_key('code'): code=param['code'][0] if (not str(entry.key())==code) or entry.is_external_page or not entry.allow_trackback: self.response.out.write(error % "Invalid trackback url.") return coming_url = self.param('url') blog_name = myfilter.do_filter(self.param('blog_name')) excerpt = myfilter.do_filter(self.param('excerpt')) title = myfilter.do_filter(self.param('title')) if not coming_url or not blog_name or not excerpt or not title: self.response.out.write(error % "not enough post info") return import time #wait for half second in case otherside hasn't been published time.sleep(0.5) ## #also checking the coming url is valid and contains our link ## #this is not standard trackback behavior ## try: ## ## result = urlfetch.fetch(coming_url) ## if result.status_code != 200 : ## #or ((self.blog.baseurl + '/' + slug) not in result.content.decode('ascii','ignore')): ## self.response.out.write(error % "probably spam") ## return ## except Exception, e: ## logging.info("urlfetch error") ## self.response.out.write(error % "urlfetch error") ## return comment = Comment.all().filter(entry = entry).filter(weburl = coming_url).get() if comment: self.response.out.write(error % "has pinged before") return comment=Comment(author=blog_name, content="...<strong>"+title[:250]+"</strong> " + excerpt[:250] + '...', weburl=coming_url, entry=entry) comment.ip=self.request.remote_addr comment.ctype=COMMENT_TRACKBACK try: comment.save() memcache.delete("/"+entry.link) self.write(success) self.blog.tigger_action("pingback_post",comment) except: self.response.out.write(error % "unknow error")
def wwb_list_comment(): html = '' for comment in Comment.all()[:10]: html += '<li><a href=\"%s">%s</a></li>' % ( comment.post.get_absolute_url(), comment.content.encode('utf-8')) return html
def wwb_list_comment(): html = '' for comment in Comment.all()[:10]: html += '<li><a href=\"%s">%s</a></li>'%(comment.post.get_absolute_url(), comment.content.encode('utf-8')) return html