Exemplo n.º 1
0
    def get(self, list_type='', direction='next', page='1', name=''):
        catobj = None
        if list_type == 'cat':
            #objs = Category.get_posts_by_name(name, page)
            catobj = Categories.get_by_category_name(name)
            show_type = catobj.showtype
        elif list_type == 'tag':
            objs = Tags.get_page_posts_by_tag_name(name, page)
            catobj = Tags.get_tag_by_name(name)
            show_type = "list"
        elif list_type == 'archive':
            objs = Archives.get_page_posts_by_archive_name(name, page)
            catobj = Archives.get_by_name(name)
            show_type = "list"

        if catobj:
            pass
        else:
            self.redirect(BASE_URL)
            return

        each_page_post_num = int(getAttr('EACH_PAGE_POST_NUM'))
        all_post = catobj.id_num
        all_page = all_post / each_page_post_num
        if all_post % each_page_post_num:
            all_page += 1

        output = self.render(show_type + '.html', {
            'title':
            "%s - %s | Part %s" % (catobj.name, getAttr('SITE_TITLE'), page),
            'keywords':
            catobj.name,
            'description':
            getAttr('SITE_DECR'),
            'objs':
            objs,
            'cats':
            Categories.get_all_category_name(),
            'tags':
            Tags.get_hot_tag(),
            'archives':
            Archives.get_by_name(),
            'page':
            int(page),
            'allpage':
            all_page,
            'listtype':
            list_type,
            'name':
            name,
            'namemd5':
            md5(name.encode('utf-8')).hexdigest(),
            'comments':
            Comments.get_recent_comments(),
            'links':
            Links.get_all(),
        },
                             layout='_layout.html')
        self.write(output)
        return output
Exemplo n.º 2
0
    def get(self, name=''):
        if not name:
            print 'ArchiveDetail name null'
            name = Archives.get_latest_archive_name()

        objs = Archives.get_page_posts_by_archive_name(name, 1)

        archiveobj = Archives.get_by_name(name)
        if archiveobj:
            pass
        else:
            self.redirect(BASE_URL)
            return

        each_page_post_num = int(getAttr('EACH_PAGE_POST_NUM'))
        all_post = archiveobj.id_num
        all_page = all_post / each_page_post_num
        if all_post % each_page_post_num:
            all_page += 1

        output = self.render(
            'default.html', {
                'title': "%s - %s" % (archiveobj.name, getAttr('SITE_TITLE')),
                'keywords': archiveobj.name,
                'description': getAttr('SITE_DECR'),
                'objs': objs,
                'cats': Categories.get_all_category_name(),
                'tags': Tags.get_hot_tag(),
                'archives': Archives.get_by_name(),
                'page': 1,
                'allpage': all_page,
                'listtype': 'archive',
                'name': name,
                'namemd5': md5(name.encode('utf-8')).hexdigest(),
                'recent_article': Posts.get_last_post(8),
                'comments': Comments.get_recent_comments(),
                'links': Links.get_all(),
            },
            layout='_layout.html')
        self.write(output)
        return output
Exemplo n.º 3
0
    def get(self, direction='next', page='2', base_id='1'):
        if page == '1':
            self.redirect(BASE_URL)
            return
        objs = Posts.get_paged(direction, page, base_id)
        if objs:
            if direction == 'prev':
                objs.reverse()
            fromid = objs[0].id
            endid = objs[-1].id
        else:
            fromid = endid = ''

        each_page_post_num = int(getAttr('EACH_PAGE_POST_NUM'))
        all_post = Posts.count_all()
        all_page = all_post / each_page_post_num
        if all_post % each_page_post_num:
            all_page += 1
        output = self.render('default.html', {
            'title':
            "%s - %s | Part %s" %
            (getAttr('SITE_TITLE'), getAttr('SITE_SUB_TITLE'), page),
            'keywords':
            getAttr('KEYWORDS'),
            'description':
            getAttr('SITE_DECR'),
            'objs':
            objs,
            'cats':
            Categories.get_all_category_name(),
            'tags':
            Tags.get_hot_tag(),
            'archives':
            Archives.get_by_name(),
            'page':
            int(page),
            'allpage':
            all_page,
            'listtype':
            'index',
            'fromid':
            fromid,
            'endid':
            endid,
            'comments':
            Comments.get_recent_comments(),
            'links':
            Links.get_all(),
        },
                             layout='_layout.html')
        self.write(output)
        return output
Exemplo n.º 4
0
    def get(self):
        try:
            news1 = Categories.get_posts_by_category_id(category_id=7, limit=8)
            news2 = Categories.get_posts_by_category_id(category_id=9, limit=8)
            prods = Categories.get_posts_by_category_id(category_id=3, limit=8)
        except:
            self.redirect('/install')
            return

        each_page_post_num = int(getAttr('EACH_PAGE_POST_NUM'))
        all_post = Posts.count_all()
        all_page = all_post / each_page_post_num
        if all_post % each_page_post_num:
            all_page += 1

        output = self.render('index.html', {
            'title':
            "%s - %s" % (getAttr('SITE_TITLE'), getAttr('SITE_SUB_TITLE')),
            'keywords':
            getAttr('KEYWORDS'),
            'description':
            getAttr('SITE_DECR'),
            'news1':
            news1,
            'news2':
            news2,
            'prods':
            prods,
            'cats':
            Categories.get_all_category_name(),
            'tags':
            Tags.get_hot_tag(),
            'archives':
            Archives.get_top_n(),
        },
                             layout='_layout.html')
        self.write(output)
        return output
Exemplo n.º 5
0
    def get(self, post_id='', title=''):
        tmpl = ''
        obj = Posts.get_post_detail(post_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_secure_cookie("rp%s" % post_id, '')
            if rp != obj.password:
                tmpl = '_pw'
        elif obj.password and getAttr('BLOG_PSW_SUPPORT'):
            rp = self.get_secure_cookie("rp%s" % post_id, '')
            print 'rp===%s' % (str(rp))
            if rp != obj.password:
                tmpl = '_pw'

        keyname = 'pv_%s' % (str(post_id))
        increment(keyname)
        self.set_secure_cookie(keyname, '1', expires_days=1)
        self.set_header("Last-Modified", obj.last_modified)

        template_prefix = 'post'
        if obj.category == '-':
            template_prefix = 'page'

        output = self.render(
            template_prefix + '%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': Categories.get_all_category_name(),
                'tags': Tags.get_hot_tag(),
                'archives': Archives.get_by_name(),
                'page': 1,
                'allpage': 10,
                'comments': Comments.get_recent_comments(),
                'links': Links.get_all(),
                'hits': get_count(keyname),
                'recent_article': Posts.get_last_post(8),
                'listtype': '',
            },
            layout='_layout.html')
        self.write(output)

        if obj.password and getAttr('BLOG_PSW_SUPPORT'):
            return output
        elif obj.password and THEME == 'default':
            return
        else:
            return output
Exemplo n.º 6
0
    def get(self):
        act = self.get_argument("act", '')
        post_id = self.get_argument("post_id", '')

        obj = None
        if act == 'add':
            obj = Posts
            obj.post_id = ''
            obj.category_id = ''
            obj.category_name = ''
            obj.title = ''
            obj.content = ''
            obj.tags = ''
            obj.allow_comment = 1
            obj.top = 0
            obj.password = ''
            self.echo('admin_post_edit.html', {
                'title': "添加文章",
                'method': "/admin/posts?act=add",
                'categories': Categories.get_all_kv(),
                'tags': Tags.get_all_tag_name(),
                'obj': obj,
            },
                      layout='_layout_admin.html')
            return
        elif act == 'edit':
            if post_id:
                obj = Posts.get(post_id)
                self.echo('admin_post_edit.html', {
                    'title': "编辑文章",
                    'method': "/admin/posts?act=edit",
                    'categories': Categories.get_all_kv(),
                    'tags': Tags.get_all_tag_name(),
                    'obj': obj,
                },
                          layout='_layout_admin.html')
                return
        elif act == 'del':
            if post_id:
                oldobj = Posts.get(post_id)
                Archives.remove_post_from_archive(post_id=post_id)
                Posts.delete(post_id)
                cache_key_list = [
                    '/',
                    'post:%s' % post_id,
                    'cat:%s' % quoted_string(oldobj.category)
                ]
                clear_cache_by_pathlist(cache_key_list)
                clear_cache_by_pathlist(['post:%s' % post_id])

                Posts.delete(post_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return

        # 文章列表
        page = self.get_argument("page", 1)
        posts = Posts.get_paged(page, getAttr('ADMIN_POST_NUM'))
        categories = Categories.get_all_kv()
        total = math.ceil(Posts.count_all() / int(getAttr('ADMIN_POST_NUM')))
        if page == 1:
            self.echo('admin_post_list.html', {
                'title': "文章链接",
                'objs': posts,
                'categories': categories,
                'total': total,
            },
                      layout='_layout_admin.html')
        else:
            result = {
                'list': posts,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return
Exemplo n.º 7
0
    def get(self):
        act = self.get_argument("act", '')
        post_id = self.get_argument("post_id", '')

        obj = None
        if act == 'add':
            obj = Posts
            obj.post_id = ''
            obj.category_id = ''
            obj.category_name = ''
            obj.title = ''
            obj.content = ''
            obj.tags = ''
            obj.allow_comment = 1
            obj.top = 0
            obj.password = ''
            self.echo('admin_post_edit.html', {
            'title': "添加文章",
            'method': "/admin/posts?act=add",
            'categories': Categories.get_all_kv(),
            'tags': Tags.get_all_tag_name(),
            'obj': obj,
            }, layout='_layout_admin.html')
            return
        elif act == 'edit':
            if post_id:
                obj = Posts.get(post_id)
                self.echo('admin_post_edit.html', {
                'title': "编辑文章",
                'method': "/admin/posts?act=edit",
                'categories': Categories.get_all_kv(),
                'tags': Tags.get_all_tag_name(),
                'obj': obj,
                }, layout='_layout_admin.html')
                return
        elif act == 'del':
            if post_id:
                oldobj = Posts.get(post_id)
                Archives.remove_post_from_archive(post_id=post_id)
                Posts.delete(post_id)
                cache_key_list = ['/', 'post:%s' % post_id, 'cat:%s' % quoted_string(oldobj.category)]
                clear_cache_by_pathlist(cache_key_list)
                clear_cache_by_pathlist(['post:%s' % post_id])

                Posts.delete(post_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return

        # 文章列表
        page = self.get_argument("page", 1)
        posts = Posts.get_paged(page, getAttr('ADMIN_POST_NUM'))
        categories = Categories.get_all_kv()
        total = math.ceil(Posts.count_all() / int(getAttr('ADMIN_POST_NUM')))
        if page == 1:
            self.echo('admin_post_list.html', {
            'title': "文章链接",
            'objs': posts,
            'categories': categories,
            'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
            'list': posts,
            'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return