当前位置: 首页>>代码示例>>Python>>正文


Python model.Category类代码示例

本文整理汇总了Python中model.Category的典型用法代码示例。如果您正苦于以下问题:Python Category类的具体用法?Python Category怎么用?Python Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

 def post(self, secret=""):
     cats = (self.get_argument("cats", ""),)
     if cats and secret:
         if secret == getAttr("MOVE_SECRET"):
             Category.set_cats(encode_special_txt(cats[0]))
             return self.write("1")
     return self.write("0")
开发者ID:yobin,项目名称:saepy-log,代码行数:7,代码来源:admin.py

示例2: get

 def get(self, name = ''):
     objs = Category.get_cat_page_posts(name, 1)
     
     catobj = Category.get_cat_by_name(name)
     if catobj:
         pass
     else:
         self.redirect(BASE_URL)
         return
     
     allpost =  catobj.id_num
     allpage = allpost/EACH_PAGE_POST_NUM
     if allpost%EACH_PAGE_POST_NUM:
         allpage += 1
         
     output = self.render('index.html', {
         'title': "%s - %s"%( catobj.name, SITE_TITLE),
         'keywords':catobj.name,
         'description':SITE_DECR,
         'objs': objs,
         'cats': Category.get_all_cat_name(),
         'tags': Tag.get_hot_tag_name(),
         'page': 1,
         'allpage': allpage,
         'listtype': 'cat',
         'name': name,
         'namemd5': md5(name.encode('utf-8')).hexdigest(),
         'comments': Comment.get_recent_comments(),
         'links':Link.get_all_links(),
     },layout='_layout.html')
     self.write(output)
     return output
开发者ID:bibodeng,项目名称:pyWeiXin_SAElog,代码行数:32,代码来源:blog.py

示例3: getCategory

def getCategory(current_category_key):
    current_category = None
    lineage = []
    
    try:
        current_category = Category.get(db.Key(current_category_key))
        lineage = [Category.get(key) for key in current_category.lineage]
    except db.BadKeyError:
        pass
    except AttributeError:
        pass
    
    #todo - massive oppurtunity for optimization
    retval = current_category.key().__str__() + ',' + current_category.name + ';'
    
    for category in lineage:
        retval += category.key().__str__() + ',' + category.name + ','
    retval += ';'
    
    for category in Category.children(current_category):
        retval += category.key().__str__() + ',' + category.name + ','
    
    print 'Content-Type: text/plain;charset=UTF-8'
    print ''
    print retval
开发者ID:bgourlie,项目名称:barterhub,代码行数:25,代码来源:async_server.py

示例4: get

    def get(self, id=""):
        # try:
        if id:
            oldobj = Article.get_article_by_id_edit(id)
            print "DelPost()", oldobj
            if not oldobj:
                return
            if MYSQL_TO_KVDB_SUPPORT:
                oldobj_category = oldobj["category"]
                oldobj_archive = oldobj["archive"]
                oldobj_tags = oldobj["tags"]
            else:
                oldobj_category = oldobj.category
                oldobj_archive = oldobj.archive
                oldobj_tags = oldobj.tags

            Category.remove_postid_from_cat(oldobj_category, str(id))
            Archive.remove_postid_from_archive(oldobj_archive, str(id))
            Tag.remove_postid_from_tags(set(oldobj_tags.split(",")), str(id))
            Article.del_post_by_id(id)
            increment("Totalblog", NUM_SHARDS, -1)
            cache_key_list = ["/", "post:%s" % id, "cat:%s" % quoted_string(oldobj_category)]
            clear_cache_by_pathlist(cache_key_list)
            clear_cache_by_pathlist(["post:%s" % id])
            self.redirect("%s/admin/edit_post/" % (BASE_URL))
开发者ID:yobin,项目名称:saepy-log,代码行数:25,代码来源:admin.py

示例5: post

    def post(self):
        self.set_header('Content-Type','application/json')
        rspd = {'status': 201, 'msg':'ok'}

        try:
            tf = {'true':1,'false':0}
            timestamp = int(time())
            post_dic = {
                'category': self.get_argument("cat"),
                'title': self.get_argument("tit"),
                'content': self.get_argument("con"),
                'tags': self.get_argument("tag",'').replace(u',',','),
                'closecomment': self.get_argument("clo",'0'),
                'password': self.get_argument("password",''),
                'add_time': timestamp,
                'edit_time': timestamp,
                'archive': genArchive(),
            }
            if post_dic['tags']:
                tagslist = set([x.strip() for x in post_dic['tags'].split(',')])
                try:
                    tagslist.remove('')
                except:
                    pass
                if tagslist:
                    post_dic['tags'] = ','.join(tagslist)
            post_dic['closecomment'] = tf[post_dic['closecomment'].lower()]
        except:
            rspd['status'] = 500
            rspd['msg'] = '错误: 注意必填的三项'
            self.write(json.dumps(rspd))
            return

        postid = Article.add_new_article(post_dic)
        if postid:
            keyname = 'pv_%s' % (str(postid))
            set_count(keyname,0,0)
            
            Category.add_postid_to_cat(post_dic['category'], str(postid))
            Archive.add_postid_to_archive(genArchive(), str(postid))
            increment('Totalblog')
            if post_dic['tags']:
                Tag.add_postid_to_tags(post_dic['tags'].split(','), str(postid))

            rspd['status'] = 200
            rspd['msg'] = '完成: 你已经成功添加了一篇文章 <a href="/t/%s" target="_blank">查看</a>' % str(postid)
            clear_cache_by_pathlist(['/', 'cat:%s' % quoted_string(post_dic['category'])])

            if not debug:
                add_task('default', '/task/pingrpctask')

            self.write(json.dumps(rspd))
            return
        else:
            rspd['status'] = 500
            rspd['msg'] = '错误: 未知错误,请尝试重新提交'
            self.write(json.dumps(rspd))
            return
开发者ID:yangzilong1986,项目名称:saepy-log,代码行数:58,代码来源:admin.py

示例6: api_category_delete

def api_category_delete(*, request, category_id):
    r = web.Response()
    category = Category(id=category_id)
    category_result = yield from category.delete()
    if int(category_id) > 0 and int(category_result) > 0:
        result = APIResult(1, '', '删除成功')
    else:
        result = APIResult(0, '', '删除失败')
    return jsonResult(r, result)
开发者ID:hearain528,项目名称:blog,代码行数:9,代码来源:handlers.py

示例7: api_article_edit

def api_article_edit(*, request, id, title):
    r = web.Response()
    cate = Category(id = id, title = title, create_time = currentTime(), is_delete = 0)
    result = yield from cate.update()
    if result is not None:
        result = APIResult(1, '', '修改成功')
    else:
        result = APIResult(0, '', '修改失败')
    return jsonResult(r, result)
开发者ID:hearain528,项目名称:blog,代码行数:9,代码来源:handlers.py

示例8: create_category

 def create_category(category_name):
     """ Create a category in datastore """
     query = Category.all()
     query.filter("description =", category_name)
     ret = query.get()
     if ret is None:
         ret = Category()
         ret.description = category_name
         ret.put()
     return ret
开发者ID:szilardhuber,项目名称:shopper,代码行数:10,代码来源:adminhandler.py

示例9: _create_structure

def _create_structure():
    category = Category('test category', 'category test', 'test_category')
    category.meta = {'id': 1, 'webtranslateit_ids': {'content': 1}}
    section = Section(category, 'test section', 'section test', 'test_section')
    section.meta = {'id': 2, 'webtranslateit_ids': {'content': 2}}
    category.sections.append(section)
    article = Article(section, 'test article', 'article body', 'test_article')
    article.meta = {'id': 3, 'webtranslateit_ids': {'content': 3, 'body': 4}}
    section.articles.append(article)
    return category, section, article
开发者ID:KeepSafe,项目名称:zendesk-helpcenter-cms,代码行数:10,代码来源:test_cms.py

示例10: createall

def createall():
    "Creates database tables"
    db.create_all()
    "add Category"
    lists=[u'PYTHON',u'编程珠玑',u'数据库',u'操作系统',u"杂项"]
    from model import Category
    for i in range(1, 6):
        item = Category()
        item.id = i
        item.category_name = lists[i-1]
        db.session.add(item)
    db.session.commit()
开发者ID:GJhunter,项目名称:flaskblog,代码行数:12,代码来源:manager.py

示例11: post

    def post(self):
        self.set_header("Content-Type", "application/json")
        rspd = {"status": 201, "msg": "ok"}

        try:
            tf = {"true": 1, "false": 0}
            timestamp = int(time())
            post_dic = {
                "category": self.get_argument("cat"),
                "title": self.get_argument("tit"),
                "content": self.get_argument("con"),
                "tags": self.get_argument("tag", "").replace(u",", ","),
                "closecomment": self.get_argument("clo", "0"),
                "password": self.get_argument("password", ""),
                "add_time": timestamp,
                "edit_time": timestamp,
            }
            if post_dic["tags"]:
                tagslist = set([x.strip() for x in post_dic["tags"].split(",")])
                try:
                    tagslist.remove("")
                except:
                    pass
                if tagslist:
                    post_dic["tags"] = ",".join(tagslist)
            post_dic["closecomment"] = tf[post_dic["closecomment"].lower()]
        except:
            rspd["status"] = 500
            rspd["msg"] = "错误: 注意必填的三项"
            self.write(json.dumps(rspd))
            return

        postid = Article.add_new_article(post_dic)
        if postid:
            Category.add_postid_to_cat(post_dic["category"], str(postid))
            if post_dic["tags"]:
                Tag.add_postid_to_tags(post_dic["tags"].split(","), str(postid))

            rspd["status"] = 200
            rspd["msg"] = '完成: 你已经成功添加了一篇文章 <a href="/t/%s" target="_blank">查看</a>' % str(postid)
            clear_cache_by_pathlist(["/", "cat:%s" % quoted_string(post_dic["category"])])

            if not debug:
                add_task("default", "/task/pingrpctask")

            self.write(json.dumps(rspd))
            return
        else:
            rspd["status"] = 500
            rspd["msg"] = "错误: 未知错误,请尝试重新提交"
            self.write(json.dumps(rspd))
            return
开发者ID:biggtfish,项目名称:pyWeiXin_SAElog,代码行数:52,代码来源:admin.py

示例12: test_encoder

    def test_encoder(self):
        p = Project('test')
        p.id = 1
        c = Category('test')
        c.id = 2
        c.project_id = p.id
        t = Task('test')
        t.id = 3
        t.category_id = c.id

        self.assertIsNotNone(json.dumps(p, cls=ModelEncoder))
        self.assertIsNotNone(json.dumps(c, cls=ModelEncoder))
        self.assertIsNotNone(json.dumps(t, cls=ModelEncoder))
开发者ID:franckv,项目名称:ptime,代码行数:13,代码来源:test_json.py

示例13: api_category_add

def api_category_add(*, request, title):
    r = web.Response()
    category = yield from Category.findAll('title=?', [title])
    if len(category) > 0:
        result = APIResult(0, '', '该分类已存在')
    else:
        cate = Category(title = title)
        cate_id = yield  from cate.save()
        if cate_id > 0:
            result = APIResult(1, '', '分类添加成功')
        else:
            result = APIResult(0, '', '分类添加失败')
    return jsonResult(r, result)
开发者ID:hearain528,项目名称:blog,代码行数:13,代码来源:handlers.py

示例14: post

 def post(self):
     pdict = self.request.POST
     action = pdict.get("action", "")
     
     if action == "new":
         try:
             Category.new(pdict.get("category.url", randstr()),
                          pdict.get("category.title"),
                          pdict.get("category.discription") )
             Category.refresh_total()
         except Rollback, ex:
             self.jsonout(ex)
         else:
             self.jsonout("ok")
开发者ID:dreampuf,项目名称:bana,代码行数:14,代码来源:admin_views.py

示例15: get

 def get(self, id = ''):
     try:
         if id:
             oldobj = Article.get_article_by_id_edit(id)
             Category.remove_postid_from_cat(oldobj.category, str(id))
             Archive.remove_postid_from_archive(oldobj.archive, str(id))
             Tag.remove_postid_from_tags( set(oldobj.tags.split(','))  , str(id))
             Article.del_post_by_id(id)
             increment('Totalblog',NUM_SHARDS,-1)
             cache_key_list = ['/', 'post:%s'% id, 'cat:%s' % quoted_string(oldobj.category)]
             clear_cache_by_pathlist(cache_key_list)
             clear_cache_by_pathlist(['post:%s'%id])
             self.redirect('%s/admin/edit_post/'% (BASE_URL))
     except:
         pass
开发者ID:yangzilong1986,项目名称:saepy-log,代码行数:15,代码来源:admin.py


注:本文中的model.Category类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。