Example #1
0
    def post(self):
        try:
            act = self.get_argument("act", '').encode('utf-8')
            link_id = self.get_argument("id", '').encode('utf-8')
            link_name = self.get_argument("name", '').encode('utf-8')
            url = self.get_argument("url", '').encode('utf-8')
            display_order = self.get_argument("sort", '0').encode('utf-8')
        except:
            self.write(json.dumps("网站名称、URL均为必填项!"))
            return

        if link_name and url:
            params = {
                'link_id': link_id,
                'link_name': link_name,
                'url': url,
                'display_order': display_order
            }
            if act == 'add':
                Links.create(params)

            if act == 'edit':
                Links.update(params)

            clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
Example #2
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
Example #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
Example #4
0
    def post(self):
        try:
            act = self.get_argument("act", '').encode('utf-8')
            link_id = self.get_argument("id", '').encode('utf-8')
            link_name = self.get_argument("name", '').encode('utf-8')
            url = self.get_argument("url", '').encode('utf-8')
            display_order = self.get_argument("sort", '0').encode('utf-8')
        except:
            self.write(json.dumps("网站名称、URL均为必填项!"))
            return

        if link_name and url:
            params = {'link_id': link_id, 'link_name': link_name, 'url': url, 'display_order': display_order}
            if act == 'add':
                Links.create(params)

            if act == 'edit':
                Links.update(params)

            clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
Example #5
0
    def get(self):
        act = self.get_argument("act", '')
        link_id = self.get_argument("id", '')

        obj = None
        if act == 'del':
            if link_id:
                Links.delete(link_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return
        elif act == 'edit':
            if link_id:
                obj = Links.get(link_id)
                clear_cache_by_pathlist(['/'])

        # 友情链接列表
        page = self.get_argument("page", 1)
        links = Links.get_paged(page, getAttr('ADMIN_LINK_NUM'))
        total = math.ceil(Links.count_all() / float(getAttr('ADMIN_LINK_NUM')))
        if page == 1:
            self.echo('admin_link.html', {
                'title': "友情链接",
                'objs': links,
                'obj': obj,
                'total': total,
            },
                      layout='_layout_admin.html')
        else:
            result = {
                'list': links,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return
Example #6
0
    def get(self):
        act = self.get_argument("act", '')
        link_id = self.get_argument("id", '')

        obj = None
        if act == 'del':
            if link_id:
                Links.delete(link_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return
        elif act == 'edit':
            if link_id:
                obj = Links.get(link_id)
                clear_cache_by_pathlist(['/'])

        # 友情链接列表
        page = self.get_argument("page", 1)
        links = Links.get_paged(page, getAttr('ADMIN_LINK_NUM'))
        total = math.ceil(Links.count_all() / float(getAttr('ADMIN_LINK_NUM')))
        if page == 1:
            self.echo('admin_link.html', {
                'title': "友情链接",
                'objs': links,
                'obj': obj,
                'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
                'list': links,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return
Example #7
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
Example #8
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