• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python model.Category类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: api_getCategory

def api_getCategory(*, request, page):
    r = web.Response()
    if (page is not None and len(page) > 0):
        num = yield from Category.findNumber('count(id)')
        p = Page(num, int(page))
        if num == 0:
            data = dict(page = class_to_dict(p), blogs = ())
        else:
            categorys = yield from Category.findAll(orderBy='create_time desc', limit=(p.offset, p.limit))
            data = dict(page=class_to_dict(p), blogs=categorys)
    else:
        categorys = yield from Category.findAll(orderBy='create_time desc')
        data = categorys
    result = APIResult(1, data)
    return jsonResult(r, result)
开发者ID:hearain528,项目名称:blog,代码行数:15,代码来源:handlers.py


示例17: post

 def post(self, cid):
     try:
         category = Category.get(id = cid)
     except:
         self.flash("此分类不存在")
         self.redirect("/admin/categorys")
         return
     
     name = self.get_argument("name", None)
     dec = self.get_argument("dec", "")
     order = int(self.get_argument("order", 1))
         
     categoryattr = CategoryAttr()
     categoryattr.cid = cid
     categoryattr.name = name
     categoryattr.dec = dec
     categoryattr.order = order
     
     try:
         categoryattr.validate()
         categoryattr.save()
         self.flash("分类属性%s添加成功" % name)
         self.redirect("/admin/categoryattrs/%d" % int(cid))
         return
     except Exception as ex:
         self.flash(str(ex))
     
     self.render('admin/addcategoryattr.html', category = category, maxorder = CategoryAttr.maxorder(cid))
开发者ID:gislite,项目名称:cakeshop,代码行数:28,代码来源:admin.py


示例18: post

    def post(self):
        parent_key = self.request.get("parent_key")
        name = self.request.get("category_name")

        if len(name) < 3:
            pass  # no feedback, as of now
        else:
            try:
                parent = Category.get(db.Key(parent_key))
                Category.new(name, parent)
            except db.BadKeyError:
                pass  # no feedback, as of now
            except:
                pass  # no feedback, as of now

        self.redirect("./?category=" + parent_key)
开发者ID:bgourlie,项目名称:barterhub,代码行数:16,代码来源:admin_request_handler.py


示例19: get

    def get(self):

        urls = []

        def addurl(loc, lastmod=None, changefreq=None, priority=None):
            url_info = {
                'location': loc,
                'lastmod': lastmod,
                'changefreq': changefreq,
                'priority': priority,
            }
            urls.append(url_info)

        addurl(g_blog.baseurl, changefreq='daily', priority=1)

        entries = Entry.all().filter('published =', True).order('-date').fetch(g_blog.sitemap_entries)

        for item in entries:
            loc = '%s/%s' % (g_blog.baseurl, item.link)
            addurl(loc, item.date, 'daily', 0.9)

        if g_blog.sitemap_include_category:
            cats = Category.all()
            for cat in cats:
                loc = '%s/category/%s' % (g_blog.baseurl, cat.slug)
                addurl(loc, None, 'weekly', 0.8)

        if g_blog.sitemap_include_tag:
            tags = Tag.all()
            for tag in tags:
                loc = '%s/tag/%s' % (g_blog.baseurl, urlencode(tag.tag))
                addurl(loc, None, 'weekly', 0.8)

        self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
        self.render2('views/sitemap.xml', {'urlset': urls})
开发者ID:oldhu,项目名称:micolog-oldhu,代码行数:35,代码来源:blog_sitemap.py


示例20: update_basic_info

	def update_basic_info(
		update_categories=False,
		update_tags=False,
		update_links=False,
		update_comments=False,
		update_archives=False,
		update_pages=False):

		from model import Entry,Archive,Comment,Category,Tag,Link
		basic_info = ObjCache.get(is_basicinfo=True)
		if basic_info is not None:
			info = ObjCache.get_cache_value(basic_info.cache_key)
			if update_pages:
				info['menu_pages'] = Entry.all().filter('entrytype =','page')\
							.filter('published =',True)\
							.filter('entry_parent =',0)\
							.order('menu_order').fetch(limit=1000)
			if update_archives:
				info['archives'] = Archive.all().order('-year').order('-month').fetch(12)
			if update_comments:
				info['recent_comments'] = Comment.all().order('-date').fetch(5)
			if update_links:
				info['blogroll'] = Link.all().filter('linktype =','blogroll').fetch(limit=1000)
			if update_tags:
				info['alltags'] = Tag.all().order('-tagcount').fetch(limit=100)
			if update_categories:
				info['categories'] = Category.all().fetch(limit=1000)

			logging.debug('basic_info updated')
			basic_info.update(info)
开发者ID:fly2014,项目名称:XBLOG,代码行数:30,代码来源:cache.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python model.Comment类代码示例发布时间:2022-05-27
下一篇:
Python model.Article类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap