當前位置: 首頁>>代碼示例>>Python>>正文


Python Category.key方法代碼示例

本文整理匯總了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)
開發者ID:ssb402,項目名稱:Vote-or-Skip-Web-App,代碼行數:17,代碼來源:views.py

示例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)
開發者ID:freedomd,項目名稱:Head2Head,代碼行數:56,代碼來源:xmlHandler.py


注:本文中的models.Category.key方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。