Exemple #1
0
	def get_response_article_by_id(self, post_id):
		global PIC_URL
		# 从数据库查询得到若干文章
		article = Article.get_article_by_id_detail(post_id)
		# postId为文章id
		if article:
			title = article.slug
			description = article.description
			picUrl = PIC_URL
			url = article.absolute_url
			count = 1
			# 这里实现相关逻辑,从数据库中获取内容
			
			# 构造图文消息
			articles_msg = {'articles':[]}
			for i in range(0,count):
				article = {
						'title':title,
						'description':description,
						'picUrl':picUrl,
						'url':url
					}
				# 插入文章
				articles_msg['articles'].append(article)
				article = {}
			# 返回文章
			return articles_msg
		else:
			return
Exemple #2
0
    def get_response_article_by_id(self, post_id):
        global PIC_URL
        # 从数据库查询得到若干文章
        article = Article.get_article_by_id_detail(post_id)
        # postId为文章id
        if article:
            title = article.slug
            description = article.description
            picUrl = PIC_URL
            url = article.absolute_url
            count = 1
            # 这里实现相关逻辑,从数据库中获取内容

            # 构造图文消息
            articles_msg = {'articles': []}
            for i in range(0, count):
                article = {
                    'title': title,
                    'description': description,
                    'picUrl': picUrl,
                    'url': url
                }
                # 插入文章
                articles_msg['articles'].append(article)
                article = {}
            # 返回文章
            return articles_msg
        else:
            return
Exemple #3
0
    def wx_get_article_by_id(self, post_id):
        k = 'wx_post_%s' % (str(post_id))
        v = getMc(k)
        if v:
            return v

        article = Article.get_article_by_id_detail(post_id)
        if article:
            if MYSQL_TO_KVDB_SUPPORT:
                title = article['slug']
                description = article['description']
                url = article['absolute_url']
            else:
                title = article.slug
                description = article.description
                url = article.absolute_url
            picUrl = WX_DEFAULT_PIC
            count = 1

            articles_msg = {'articles':[]}
            for i in range(0,count):
                article = {
                        'title':title,
                        'description':description,
                        'picUrl':picUrl,
                        'url':url
                    }
                articles_msg['articles'].append(article)
                article = {}
            setMc(k,articles_msg)
            return articles_msg
        return ''
Exemple #4
0
    def wx_get_article_by_id(self, post_id):
        k = 'wx_post_%s' % (str(post_id))
        v = getMc(k)
        if v:
            return v

        article = Article.get_article_by_id_detail(post_id)
        if article:
            if MYSQL_TO_KVDB_SUPPORT:
                title = article['slug']
                description = article['description']
                url = article['absolute_url']
            else:
                title = article.slug
                description = article.description
                url = article.absolute_url
            picUrl = WX_DEFAULT_PIC
            count = 1

            articles_msg = {'articles': []}
            for i in range(0, count):
                article = {
                    'title': title,
                    'description': description,
                    'picUrl': picUrl,
                    'url': url
                }
                articles_msg['articles'].append(article)
                article = {}
            setMc(k, articles_msg)
            return articles_msg
        return ''
Exemple #5
0
    def get(self, id = '', title = ''):
        tmpl = ''
        obj = Article.get_article_by_id_detail(id)
        if not obj:
            self.redirect(BASE_URL)
            return
        #redirect to right title
        try:
            title = unquote(title).decode('utf-8')
        except:
            pass
        if title != obj.slug:
            self.redirect(obj.absolute_url, 301)
            return
        #
        if obj.password and THEME == 'default':
            rp = self.get_cookie("rp%s" % id, '')
            if rp != obj.password:
                tmpl = '_pw'
        elif obj.password and BLOG_PSW_SUPPORT:
            rp = self.get_cookie("rp%s" % id, '')
            print 'rp===%s' % (str(rp))
            if rp != obj.password:
                tmpl = '_pw'

        keyname = 'pv_%s' % (str(id))
        increment(keyname)#yobin 20120701
        self.set_cookie(keyname, '1', path = "/", expires_days =1)
        self.set_header("Last-Modified", obj.last_modified)
        output = self.render('page%s.html'%tmpl, {
            'title': "%s - %s"%(obj.title, getAttr('SITE_TITLE')),
            'keywords':obj.keywords,
            'description':obj.description,
            'obj': obj,
            'cobjs': obj.coms,
            'postdetail': 'postdetail',
            'cats': Category.get_all_cat_name(),
            'tags': Tag.get_hot_tag_name(),
            'archives': Archive.get_all_archive_name(),
            'page': 1,
            'allpage': 10,
            'comments': Comment.get_recent_comments(),
            'links':Link.get_all_links(),
            'isauthor':self.isAuthor(),
            'hits':get_count(keyname),
            'Totalblog':get_count('Totalblog',NUM_SHARDS,0),
            'listtype': '',
        },layout='_layout.html')
        self.write(output)

        if obj.password and BLOG_PSW_SUPPORT:
            return output
        elif obj.password and THEME == 'default':
            return
        else:
            return output
Exemple #6
0
 def get(self, id = '', title = ''):
     tmpl = ''
     obj = Article.get_article_by_id_detail(id)
     if not obj:
         self.redirect(BASE_URL)
         return
     #redirect to right title
     try:
         title = unquote(title).decode('utf-8')
     except Exception , e:
         print 'PostDetail()',e
Exemple #7
0
 def get(self, id='', title=''):
     tmpl = ''
     obj = Article.get_article_by_id_detail(id)
     if not obj:
         self.redirect(BASE_URL)
         return
     #redirect to right title
     try:
         title = unquote(title).decode('utf-8')
     except Exception, e:
         print 'PostDetail()', e
Exemple #8
0
    def get(self, id='', title=''):
        tmpl = ''
        obj = Article.get_article_by_id_detail(id)
        if not obj:
            self.redirect(BASE_URL)
            return
        #redirect to right title
        try:
            title = unquote(title).decode('utf-8')
        except:
            pass
        if title != obj.slug:
            self.redirect(obj.absolute_url, 301)
            return
        #
        if obj.password and THEME == 'default':
            rp = self.get_cookie("rp%s" % id, '')
            if rp != obj.password:
                tmpl = '_pw'

        self.set_header("Last-Modified", obj.last_modified)

        output = self.render('page%s.html' % tmpl, {
            'title': "%s - %s" % (obj.title, SITE_TITLE),
            'keywords': obj.keywords,
            'description': obj.description,
            'obj': obj,
            'cobjs': obj.coms,
            'postdetail': 'postdetail',
            'cats': Category.get_all_cat_name(),
            'tags': Tag.get_hot_tag_name(),
            'page': 1,
            'allpage': 10,
            'comments': Comment.get_recent_comments(),
            'links': Link.get_all_links(),
        },
                             layout='_layout.html')
        self.write(output)

        if obj.password and THEME == 'default':
            return
        else:
            return output
Exemple #9
0
 def get(self, id = '', title = ''):
     tmpl = ''
     obj = Article.get_article_by_id_detail(id)
     if not obj:
         self.redirect(BASE_URL)
         return
     #redirect to right title
     try:
         title = unquote(title).decode('utf-8')
     except:
         pass
     if title != obj.slug:
         self.redirect(obj.absolute_url, 301)
         return        
     #
     if obj.password and THEME == 'default':
         rp = self.get_cookie("rp%s" % id, '')
         if rp != obj.password:
             tmpl = '_pw'
     
     self.set_header("Last-Modified", obj.last_modified)
         
     output = self.render('page%s.html'%tmpl, {
         'title': "%s - %s"%(obj.title, SITE_TITLE),
         'keywords':obj.keywords,
         'description':obj.description,
         'obj': obj,
         'cobjs': obj.coms,
         'postdetail': 'postdetail',
         'cats': Category.get_all_cat_name(),
         'tags': Tag.get_hot_tag_name(),
         'page': 1,
         'allpage': 10,
         'comments': Comment.get_recent_comments(),
         'links':Link.get_all_links(),
     },layout='_layout.html')
     self.write(output)
     
     if obj.password and THEME == 'default':
         return
     else:
         return output