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


Python Category.get方法代码示例

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


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

示例1: show_by_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def show_by_category(request, key):
    context = base_context()
    rpp = record_per_page()
    cur_page = 1
    try:
        cur_page = int(request.REQUEST["jumpPage"].strip())
    except:
        cur_page = 1

    blogs_count = Blog.all().filter("category", Category.get(key)).count()
    max_page = blogs_count / rpp
    temp2 = blogs_count % rpp
    if temp2 != 0:
        max_page = max_page + 1

    if cur_page > max_page or cur_page <= 0:
        cur_page = max_page

    if cur_page == 0 or cur_page > max_page:
        cur_page = max_page
        blogs = Blog.all().filter("category", Category.get(key)).order("-date").fetch(0)
    else:
        blogs = Blog.all().filter("category", Category.get(key)).order("-date").fetch(rpp, rpp * (cur_page - 1))
    context.cur_page = cur_page
    context.max_page = max_page
    context.action_mode = "/category/" + key + "/show"
    context.range1 = range(1, max_page + 1)
    context.up_page = cur_page - 1
    context.down_page = cur_page + 1
    context.blogs = blogs
    template = loader.get_template("blogs/index.html")
    return HttpResponse(template.render(context))
开发者ID:proming,项目名称:myblogongae,代码行数:34,代码来源:views.py

示例2: test_create_category_duplicate

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
    def test_create_category_duplicate(self):
        """Makes sure categories can't be created with the same name and category id."""
        create_category(category_id="001", description="testing")
        from peewee import IntegrityError

        with self.assertRaises(IntegrityError):
            create_category(category_id="001", description="testing")
        Category.get(Category.category_id == "001").delete_instance()
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:10,代码来源:tests.py

示例3: test_create_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
 def test_create_category(self):
     """Create a category."""
     create_category(category_id="001", description="testing category")
     c = Category.select().where(Category.category_id == "001")
     Category.get(Category.category_id == "001").delete_instance()
     self.assertEqual(
         c,
         "<class 'models.Category'> SELECT `t1`.`id`, "
         "`t1`.`category_id`, `t1`.`description` "
         "FROM `category` AS t1 WHERE (`t1`.`category_id` = %s) ['001']",
     )
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:13,代码来源:tests.py

示例4: test_create_outgoing

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
 def test_create_outgoing(self):
     """Create an outgoing record."""
     Category.create(category_id='001', description='Testing Stock')
     Project.create(project_id='001', project_description="Testing")
     Role.create(role_name='Admin')
     User.create(first_name='Jay', second_name='Palm', phone='9783978223', role='Admin', username='JayPalm',
                 password='jfresh13', email='[email protected]')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     create_outgoing_stock(stock='001', project_id='001', date="2015-07-22", quantity='7', username='JayPalm')
     OutgoingStock.get(OutgoingStock.stock == '001').delete_instance()
     Stock.get(Stock.category == '001').delete_instance()
     User.get(User.username == 'JayPalm').delete_instance()
     Role.get(Role.role_name == 'Admin').delete_instance()
     Project.get(Project.project_id == '001').delete_instance()
     Category.get(Category.category_id == '001').delete_instance()
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:17,代码来源:tests.py

示例5: post_update_post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def post_update_post(id):
    postid = request.forms.get('postid')
    title = request.forms.get('title').decode('utf-8')
    slug = request.forms.get('slug').decode('utf-8')
    post = request.forms.get('post')
    tags = request.forms.get('tags').decode('utf-8')
    category = request.forms.get('category').decode('utf-8')
    post_type = request.forms.get('postype')
    if post_type == 'HTML':
        is_html = 1
        content = post.decode('utf-8')
        markdown = u'html'
    else:
        is_html = 0
        markdown = post.decode('utf-8')
        content = to_markdown(markdown)
    category = Category.get(name=category)
    Post.update(title=title, slug=slug, content=content, markdown=markdown,
                tags=tags, category=category,
                is_html=is_html).where(id=postid).execute()
    tag_list = set(tags.split(","))
    for tag in tag_list:
        try:
            Tag.get(name=tag.strip(), post_id=postid)
        except Post.DoesNotExist:
            Tag.create(name=tag.strip(), post_id=postid)
    redirect("/%s" % slug)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:29,代码来源:blog.py

示例6: save_edited_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def save_edited_category():
    cat_name = request.form.get("category")
    key = request.form.get("key")
    existing = Category.all().filter("owner =", users.get_current_user())
    for e in existing:
        if e.title.lower() == cat_name.lower():
            if not str(e.key()) == key:
                error = "You already have a category with that name. Please choose a different name"
                return Response(status=400)
    category = Category.get(key)
    items_from_form = request.form.get("items").split(",")
    old_items_from_db = Item.all().ancestor(category)
    for item in old_items_from_db:
        if not item.title in items_from_form:
            db.delete(item)
        else:
            items_from_form.remove(item.title)

    for new_item in items_from_form:
        if not new_item == "":
            i = Item(parent=category, title=new_item)
            i.put()
    category.title = request.form.get("category")
    category.put()
    return jsonify(new_items=items_from_form)
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:27,代码来源:views.py

示例7: results

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def results(key, expired=None):
    my_votes = {}
    my_comments = {}
    user_comments = {}
    category = Category.get(key)
    items = Item.all().ancestor(category).order("-wins").order("losses")
    count = 0
    for i in items:
        item = (
            UserVote.all().ancestor(i).order("-wins").order("losses").filter("voter =", users.get_current_user()).get()
        )
        if not item:
            my_votes[count] = [i.title, "-", "-"]
        else:
            my_votes[count] = [i.title, item.wins, item.losses]  # the count helps maintain the order -wins and losses
        count += 1

    for c in items:
        user_comments[c.title] = UserComment.all().ancestor(c)
        my_comment = UserComment.all().ancestor(c).filter("commenter =", users.get_current_user()).get()
        if my_comment:
            my_comments[c.title] = my_comment.comment
    return render_template(
        "results.html",
        items=items,
        key=key,
        title=category.title,
        owner=category.owner.email(),
        my_votes=my_votes,
        my_comments=my_comments,
        user_comments=user_comments,
        expired=expired,
    )
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:35,代码来源:views.py

示例8: category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def category(id=None):
    # Get category #id
    try:
        category = Category.get(Category.id == id)
    except Category.DoesNotExist:
        return jsonify(**CATEGORY_NOT_FOUND)

    # Populate Category tree
    (categories, feeds) = loadTree()

    # Get posts in category in decreasing date order
    posts = Post.select().join(Feed).join(Category).where(Category.id == id).order_by(Post.published.desc()).paginate(1, 50)

    # Create human-readable datestamps for posts
    datestamps = loadDates(posts)

    # Return mode dependent on Content-Type?
    if request.json is None:

        # Render category page template
        return render_template("category.html", 
                               category=category, 
                               categories=categories,
                               feeds=feeds, 
                               posts=posts,
                               datestamps=datestamps)

    else:

        # Return JSON data structure
        return jsonify(response=[dict(categories=categories, feeds=feeds, posts=posts)])
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:33,代码来源:views.py

示例9: post_new_post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def post_new_post():
    title = request.forms.get('title').decode('utf-8')
    slug = request.forms.get('slug').decode('utf-8')
    post = request.forms.get('post')
    tags = request.forms.get('tags').decode('utf-8')
    category = request.forms.get('category').decode('utf-8')
    post_type = request.forms.get('postype')
    set_time = request.forms.get('setime')
    if set_time != '1':
        t = [int(tt) for tt in set_time.split('-')]
        d = datetime.datetime(*t)
        published = d
    else:
        published = datetime.datetime.now()

    if post_type == 'HTML':
        is_html = 1
        content = post.decode('utf-8')
        markdown = u'html'
    else:
        is_html = 0
        markdown = post.decode('utf-8')
        content = to_markdown(markdown)
    category = Category.get(name=category)
    post = Post.create(title=title, slug=slug.strip(), content=content,
                       markdown=markdown, tags=tags, category=category,
                       is_html=is_html, published=published, comm_count=0)
    for tag in post.tags_list():
        Tag.create(name=tag.strip(), post_id=post.id)
    redirect("/%s" % slug)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:32,代码来源:blog.py

示例10: category_archive

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def category_archive(category):
    category = category.decode('utf-8')
    try:
        category = Category.get(slug=category)
    except Category.DoesNotExist:
        abort(404)
    posts = category.posts
    count = posts.count()
    return template('archive.html', posts=posts, name=category.name,
                    type="category", count=count)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:12,代码来源:blog.py

示例11: saveimage

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def saveimage(key):
    category = Category.get(key)
    items = Item.all().ancestor(category)
    item = Item.all().ancestor(category).filter("title =", request.form.get("items")).get()
    if request.method == "POST":
        image_file = request.files["image"]
        headers = image_file.headers["Content-Type"]
        blob_key = parse_options_header(headers)[1]["blob-key"]
        item.blob_key = blob_key
        item.image_url = images.get_serving_url(blob_key)
        item.put()
    return redirect("edit/images/" + key)
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:14,代码来源:views.py

示例12: edit_image

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def edit_image(key):
    category = Category.get(key)
    upload_url = blobstore.create_upload_url("/saveimage/" + key)
    items = Item.all().ancestor(category)
    return render_template(
        "edit_images.html",
        items=items,
        key=key,
        title=category.title,
        owner=category.owner.email(),
        upload_url=upload_url,
    )
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:14,代码来源:views.py

示例13: post_comment

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def post_comment():
    key = request.form.get("key")
    item_name = request.form.get("item")
    user_comment = request.form.get("comment")
    category = Category.get(key)
    item = Item.all().ancestor(category).filter("title =", item_name).get()
    comment = UserComment.all().ancestor(item.key()).filter("commenter =", users.get_current_user()).get()
    if comment:
        return Response(status=400)
    else:
        comment = UserComment(parent=item.key(), comment=user_comment, commenter=users.get_current_user())
        comment.put()
        return Response(status=200)
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:15,代码来源:views.py

示例14: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
	def post(self):
		title = self.get_argument('title',None)
		slug = self.get_argument('slug','')
		category_id = self.get_argument('category',1)
		content = self.get_argument('content','')
		tag = self.get_argument('tag',None)

		category = Category.get(id=int(category_id))
		post = Post.create(title=title,category=category,slug=slug,content=content,tags=tag)
		
		if tag:
			for tag in post.taglist():
				Tag.create(name=tag,post=post.id)
		self.render('admin/post/add.html')
开发者ID:940825,项目名称:logpress-tornado,代码行数:16,代码来源:admin.py

示例15: show_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get [as 别名]
def show_category(key):
    category = Category.get(key)

    if category.expiration and datetime.now() > category.expiration:
        return results(key, "This category has expired. Voting is no longer possible.")

    if not request.form.has_key("item") or request.form.has_key("skip"):
        random_items = get_random_items(category)
        return render_template(
            "category.html", key=key, title=category.title, owner=category.owner.email(), items=random_items
        )

    winner = request.form.get("item")
    loser = request.form.get("2") if winner == request.form.get("1") else request.form.get("1")

    winner_item = get_item(category, winner)
    loser_item = get_item(category, loser)

    winner_item.wins = winner_item.wins + 1
    loser_item.losses = loser_item.losses + 1

    uservote_winner = get_uservote(winner_item)
    uservote_loser = get_uservote(loser_item)

    if not uservote_winner:
        uservote_winner = UserVote(parent=winner_item, voter=users.get_current_user(), wins=1)
    else:
        uservote_winner.wins = uservote_winner.wins + 1

    if not uservote_loser:
        uservote_loser = UserVote(parent=loser_item, voter=users.get_current_user(), losses=1)
    else:
        uservote_loser.losses = uservote_loser.losses + 1

    uservote_winner.put()
    uservote_loser.put()
    winner_item.put()
    loser_item.put()

    random_items = get_random_items(category)
    return render_template(
        "category.html",
        key=key,
        title=category.title,
        owner=category.owner.email(),
        items=random_items,
        winner=winner,
        loser=loser,
    )
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:51,代码来源:views.py


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