示例#1
0
文件: category.py 项目: dreambt/cms4p
    def post(self):
        try:
            tf = {'true': 1, 'false': 0}
            act = self.get_argument("act", '').encode('utf-8')
            category_id = self.get_argument("id", '').encode('utf-8')
            father_category_id = self.get_argument("father_id", 0).encode('utf-8')
            category_name = self.get_argument("name", '').encode('utf-8')
            show_type = self.get_argument("show_type", '').encode('utf-8')
            display_order = self.get_argument("sort", '0').encode('utf-8')
            allow_comment = tf[self.get_argument("allow_comment", "false").encode('utf-8')]
            allow_publish = tf[self.get_argument("allow_publish", "false").encode('utf-8')]
            description = self.get_argument("description", '').encode('utf-8')
        except:
            self.write(json.dumps("用户名、密码、验证码均为必填项!"))
            return

        if category_name:
            params = {'category_id': category_id, 'father_category_id': father_category_id,
                      'category_name': category_name, 'show_type': show_type, 'display_order': display_order,
                      'allow_comment': allow_comment, 'allow_publish': allow_publish, 'description': description}
            if act == 'add':
                Categories.create(params)

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

            clear_cache_by_pathlist(['/'])

            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
        else:
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("参数异常"))
示例#2
0
文件: blog.py 项目: cash2one/cms4p
    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
示例#3
0
文件: blog.py 项目: cash2one/cms4p
 def get(self, id=''):
     obj = Categories.get(id)
     if obj:
         self.redirect('%s/category/%s' % (BASE_URL, obj.name), 301)
         return
     else:
         self.redirect(BASE_URL)
def categories_list(message):
    categories = Categories().get_all_categories()
    answer_message = "Категории:\n\n* " + \
                     ("\n* ".join([c.name + ' (' + ", ".join(c.aliases) + ')' for c in categories]))

    bot.send_message(message.chat.id,
                     answer_message,
                     reply_markup=cmp.back_to_menu_inline_markup(),
                     parse_mode='HTML')
示例#5
0
    def post(self):
        try:
            tf = {'true': 1, 'false': 0}
            act = self.get_argument("act", '').encode('utf-8')
            category_id = self.get_argument("id", '').encode('utf-8')
            father_category_id = self.get_argument("father_id",
                                                   0).encode('utf-8')
            category_name = self.get_argument("name", '').encode('utf-8')
            show_type = self.get_argument("show_type", '').encode('utf-8')
            display_order = self.get_argument("sort", '0').encode('utf-8')
            allow_comment = tf[self.get_argument("allow_comment",
                                                 "false").encode('utf-8')]
            allow_publish = tf[self.get_argument("allow_publish",
                                                 "false").encode('utf-8')]
            description = self.get_argument("description", '').encode('utf-8')
        except:
            self.write(json.dumps("用户名、密码、验证码均为必填项!"))
            return

        if category_name:
            params = {
                'category_id': category_id,
                'father_category_id': father_category_id,
                'category_name': category_name,
                'show_type': show_type,
                'display_order': display_order,
                'allow_comment': allow_comment,
                'allow_publish': allow_publish,
                'description': description
            }
            if act == 'add':
                Categories.create(params)

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

            clear_cache_by_pathlist(['/'])

            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
        else:
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("参数异常"))
示例#6
0
def add_record(raw_message: str) -> Record:
    parsed_message = _parse_message(raw_message)
    category = Categories().get_category(parsed_message.category_text)

    db.insert(
        "record", {
            "time_count": parsed_message.time_count,
            "created": _get_now_formatted(),
            "category_codename": category.codename,
            "raw_text": raw_message
        })
    return Record(id=None, category_codename=category.codename)
示例#7
0
文件: blog.py 项目: cash2one/cms4p
    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
示例#8
0
文件: blog.py 项目: cash2one/cms4p
    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
示例#9
0
文件: blog.py 项目: cash2one/cms4p
    def get(self, name=''):
        #objs = Category.get_posts_by_name(name, 1)
        catobj = Categories.get_by_category_name(name)

        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(
            catobj.showtype + '.html', {
                'title': "%s - %s" % (catobj.name, getAttr('SITE_TITLE')),
                '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': 1,
                'allpage': all_page,
                'listtype': 'cat',
                '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
示例#10
0
    def get(self):
        act = self.get_argument("act", '').encode('utf-8')
        category_id = self.get_argument("id", '').encode('utf-8')

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

        # 分类列表
        page = self.get_argument("page", 1)
        category = Categories.get_paged(page, getAttr('ADMIN_CATEGORY_NUM'))
        total = int(
            math.ceil(Categories.count_all() /
                      float(getAttr('ADMIN_CATEGORY_NUM'))))
        if page == 1:
            self.echo('admin_category.html', {
                'title': "分类列表",
                'objs': category,
                'obj': obj,
                'category_kv': Categories.get_all_kv(0),
                'show_types': ShowTypes.get_all(),
                'total': total,
            },
                      layout='_layout_admin.html')
        else:
            result = {
                'list': category,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result, default=dthandler))
            return
示例#11
0
文件: category.py 项目: dreambt/cms4p
    def get(self):
        act = self.get_argument("act", '').encode('utf-8')
        category_id = self.get_argument("id", '').encode('utf-8')

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

        # 分类列表
        page = self.get_argument("page", 1)
        category = Categories.get_paged(page, getAttr('ADMIN_CATEGORY_NUM'))
        total = int(math.ceil(Categories.count_all() / float(getAttr('ADMIN_CATEGORY_NUM'))))
        if page == 1:
            self.echo('admin_category.html', {
                'title': "分类列表",
                'objs': category,
                'obj': obj,
                'category_kv': Categories.get_all_kv(0),
                'show_types': ShowTypes.get_all(),
                'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
                'list': category,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result, default=dthandler))
            return
示例#12
0
文件: blog.py 项目: cash2one/cms4p
    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
示例#13
0
文件: blog.py 项目: cash2one/cms4p
 def get(self, id=''):
     self.set_header('Content-Type', 'text/xml')
     self.echo('sitemap.html', {
         'sitemapstr': Categories.get_sitemap_by_category_id(id),
         'id': id
     })
示例#14
0
文件: blog.py 项目: cash2one/cms4p
 def get(self):
     self.echo('robots.txt', {'cats': Categories.get_all()})
示例#15
0
文件: welcome.py 项目: dreambt/cms4p
 def get(self, id=''):
     self.set_header('Content-Type', 'text/xml')
     from model.categories import Categories
     self.echo('sitemap.html', {'sitemapstr': Categories.get_sitemap_by_category_id(id), 'id': id})
示例#16
0
文件: post.py 项目: dreambt/cms4p
    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
示例#17
0
 def get(self):
     from model.categories import Categories
     self.echo('robots.txt', {'cats': Categories.get()})
示例#18
0
文件: post.py 项目: cash2one/cms4p
    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