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


Python Item.lose方法代码示例

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


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

示例1: add_item

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import lose [as 别名]
    def add_item(self, currt_user, new_item):
        cat_name = self.request.get("cat_name")
        cat_key = db.Key.from_path('Account', currt_user.nickname(), 'Category', cat_name)

        category = db.get(cat_key)

        items = Item.all()
        items.ancestor(cat_key)
        items.filter("item_name =", new_item)


        if items.count() == 0:
            item = Item(key_name=new_item, parent=category, item_name=new_item)
            item.win = 0
            item.lose = 0
            item.put()
开发者ID:xz565,项目名称:vote-item,代码行数:18,代码来源:manage_handler.py

示例2: post

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import lose [as 别名]
    def post(self):
        upload_files = self.get_uploads()  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        #self.redirect('/serve/%s' % blob_info.key())
        blob_key = blob_info.key()
        blob_reader = blobstore.BlobReader(blob_key)
        document = blob_reader.read()
        #self.response.out.write(document)
        dom = xml.dom.minidom.parseString(document)
        names = dom.getElementsByTagName("NAME")

        xml_cat_name = names[0].toxml() 
        xml_cat_name = xml_cat_name.replace("<NAME>", "")
        xml_cat_name = xml_cat_name.replace("</NAME>", "")

        xml_item_names = []
        for i in range(1, len(names)):
            name = names[i].toxml()
            name = name.replace("<NAME>", "")
            name = name.replace("</NAME>", "")
            xml_item_names.append(name)

        currt_user = users.get_current_user()
        account_key = db.Key.from_path('Account', currt_user.nickname())
        account = db.get(account_key)
        categories = Category.all()
        categories.ancestor(account_key)

        cat_names = []
        for category in categories.run():
            cat_names.append(category.cat_name)


        ### if category exists
        if xml_cat_name in cat_names:
            items = Item.all()
            category = categories.filter("cat_name =", xml_cat_name)
            category = category.get()
            category_key = category.key()
            
            items = items.ancestor(category_key)
            item_names = []
            for item in items:
                item_names.append(item.item_name)

            ### add new items
            for item_name in xml_item_names:
                if item_name not in item_names:
                    item = Item(key_name=item_name, parent=category, item_name=item_name)
                    item.win = 0
                    item.lose = 0
                    item.put()

            ### delete old items
            for item_name in item_names:
                if item_name not in xml_item_names:
                    items = Item.all()
                    items = items.ancestor(category_key)
                    items.filter("item_name =", item_name)
                    item = items.get()
                    item.delete()

        ### if new category
        else:
            cat = Category(key_name=xml_cat_name, parent=account, cat_name=xml_cat_name)
            cat.put()
            for xml_item_name in xml_item_names:
                item = Item(key_name=xml_item_name, parent=cat, item_name=xml_item_name)
                item.win = 0
                item.lose = 0
                item.put()


        self.redirect("/option?option=manage")
开发者ID:xz565,项目名称:vote-item,代码行数:76,代码来源:main.py


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