本文整理汇总了Python中models.Category.key方法的典型用法代码示例。如果您正苦于以下问题:Python Category.key方法的具体用法?Python Category.key怎么用?Python Category.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_new_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import key [as 别名]
def save_new_category():
category = request.form.get("category")
existing = Category.all().filter("owner =", users.get_current_user())
for e in existing:
if e.title.lower() == category.lower():
return Response(status=400)
else:
items = request.form.get("items").split(",")
cat = Category(title=category, owner=users.get_current_user())
cat.put()
for i in items:
if not i == "":
item = Item(parent=cat.key(), title=i)
item.put()
return Response(status=200)
示例2: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import key [as 别名]
def post(self):
user = users.get_current_user()
if user == None:
self.redirect("/")
return
content = self.request.get('content')
if content == None or content == "":
self.redirect("/category")
return
xmldoc = minidom.parseString(content)
category = xmldoc.getElementsByTagName('CATEGORY')[0]
categoryName = category.getElementsByTagName('NAME')[0].childNodes[0].nodeValue
itemList = category.getElementsByTagName('ITEM')
cats = Category.all()
cats.filter("category =", str(categoryName))
c = cats.get()
if c == None: # category not exist
newCat = Category() # create a new category
newCat.category = categoryName
newCat.user = user.email()
newCat.username = user.nickname()
newCat.put() # save
for item in itemList:
itemName = item.getElementsByTagName('NAME')[0].childNodes[0].nodeValue
newItem = Item(item = itemName, win = 0, lose = 0, rate = 0, parent = newCat.key())
newItem.put()
importMessage = 'Import new category "%s" successfully.' % categoryName
self.redirect("/category?importMessage=%s" % importMessage)
else: # category exists
items = Item.all()
items.ancestor(c.key())
oldItemNameList = []
for item in items.run():
oldItemNameList.append(item.item)
newItemNameList = []
for item in itemList:
itemName = item.getElementsByTagName('NAME')[0].childNodes[0].nodeValue
newItemNameList.append(itemName)
if itemName not in oldItemNameList: # new item not exist
newItem = Item(item = itemName, win = 0, lose = 0, rate = 0, parent = c.key())
newItem.put()
for item in items: # get old items
if item.item not in newItemNameList: # old item not in new list, delete
item.delete()
importMessage = 'Import existed category "%s" successfully.' % categoryName
self.redirect("/category?importMessage=%s" % importMessage)