本文整理汇总了Python中models.Item.all方法的典型用法代码示例。如果您正苦于以下问题:Python Item.all方法的具体用法?Python Item.all怎么用?Python Item.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveimage
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [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)
示例2: main
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def main():
"""Varrer os itens antigos e excluí-los"""
last_month = datetime.now() - timedelta(days=30)
last_six_months = datetime.now() - timedelta(days=180)
# Remover itens não classificados com mais de um mês
remove_list = Item.all().filter("classified =",False).filter("date <",last_month)
for remove in remove_list:
logging.info("O item %s foi removido" % remove.key().name())
remove.delete()
# Arquivar itens classificados com mais de seis meses
archive_list = Item.all().filter("classified =",True).filter("date <",last_six_months)
for archive in archive_list:
logging.info("O item %s foi arquivado" % archive.key().name())
archive.is_archived = True
archive.put()
示例3: get
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def get(self, subdomain, to_cache):
logging.info(subdomain)
'''Saving current namespace'''
namespace = namespace_manager.get_namespace()
'''Changing the namespace'''
namespace_manager.set_namespace(subdomain)
'''MEMCACHE OF THE NAMESPACE'''
data = memcache.get('lastopinion')
if data:
to_write = 'The last buyer said: <blockquote>%s</blockquote>' %data
if not memcache.set('lastopinion',to_cache):
to_write = 'A cache error happened :('
pass
else:
to_write = 'We have not stored what the last buyer said'
if not memcache.add('lastopinion',to_cache):
to_write = 'A cache error happened 2 :('
query = Item.all().fetch(10)
to_write += '<br>Items in this shop</br>'
for i in query:
to_write += '<blockquote>item: %s qty: %s</blockquote>' %(i.name,i.qty)
namespace_manager.set_namespace(namespace)
self.response.write(to_write)
示例4: save_edited_category
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [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)
示例5: vote_page
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def vote_page(self, category, account):
cat_key = db.Key.from_path("Account", account, "Category", category)
category = db.get(cat_key)
items = Item.all()
items.ancestor(cat_key)
rand1 = -1
rand2 = -1
if items.count() < 2:
self.response.out.write(
"<html><h2>Item number smaller than two, \
please choose another category</h2></html>"
)
self.choose_category_page(account)
return
else:
rand1 = random.randint(0, items.count() - 1)
rand2 = random.randint(0, items.count() - 1)
while rand1 == rand2:
rand2 = random.randint(0, items.count() - 1)
template_values = {
"item1": items[rand1],
"item2": items[rand2],
"account": account,
"category": category,
"logout_url": users.create_logout_url("/"),
}
path = os.path.join(os.path.dirname(__file__), "vote.html")
self.response.out.write(template.render(path, template_values))
示例6: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def post(self):
user = users.get_current_user()
if user == None:
self.redirect("/")
return
# get category information
category = self.request.get('category')
item = self.request.get('item')
if item != "":
cs = Category.all()
cs.filter('user =', user.email()) # get user category
cs.filter('category =', category) # get category
c = cs.get()
if c != None:
items = Item.all()
items.filter('item =', item)
items.ancestor(c.key())
i = items.get()
if i == None:
self.redirect("/manageCategory?category=%s" % category)
return
else:
i.delete()
self.redirect("/manageCategory?category=%s" % category)
示例7: show_results
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def show_results(self, account, category):
items = Item.all()
cat_key = db.Key.from_path("Account", account, "Category", category)
items.ancestor(cat_key)
self.response.out.write("<html>")
for item in items.run():
percent = ""
if (item.win + item.lose) == 0:
percent = "-"
else:
percent = item.win // (item.win + item.lose)
self.response.out.write(
"""
<h2>Item name: %s,
win: %s,
lose: %s,
percentage: %s</h2>
"""
% (item.item_name, item.win, item.lose, percent)
)
self.response.out.write("<h3>Back to <a href='/'> Home </a></h3>")
self.response.out.write("</html>")
示例8: get
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def get(self):
user = users.get_current_user()
if user:
login = True
url = users.create_logout_url(self.request.uri)
else:
login = False
url = users.create_login_url(self.request.uri)
self.redirect("/")
return
creator = self.request.get('creator')
category = self.request.get('category')
cats = Category.all()
cats.filter('user =', creator) # get user category
cats.filter('category =', category) # get category
c = cats.get()
if c == None:
self.redirect("/")
return
items = Item.all()
items.ancestor(c.key()) # get all the items of c
itemList = []
for item in items.run():
itemList.append(item.item)
if len(itemList) > 1:
length = len(itemList)
i = random.randint(0, length - 1)
j = random.randint(0, length - 1)
while i == j:
j = random.randint(0, length - 1)
choice1 = itemList[i]
choice2 = itemList[j]
error = None
else:
choice1 = None
choice2 = None
error = "Options not enough!"
template_values = {
'user': user,
'login': login,
'url': url,
'winner': None,
'loser': None,
'choice1': choice1,
'choice2': choice2,
'creator': creator,
'creatorName': c.username,
'category': category,
'error': error
}
path = os.path.join(os.path.dirname(__file__), 'templates/vote.html')
self.response.out.write(template.render(path, template_values))
示例9: results
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [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,
)
示例10: search
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def search(keywordslist):
keywords = keywordslist.split(" ")
categories = {}
keys = {}
cat_count = {}
for key in keywords:
for category in Category.all():
if category.title.lower().__contains__(key.lower()):
categories[category.title] = Item.all().ancestor(category)
keys[category.title] = category.key()
for key in keywords:
for item in Item.all():
if item.title.lower().__contains__(key.lower()):
categories[item.parent().title] = Item.all().ancestor(item.parent())
keys[item.parent().title] = item.parent().key()
return render_template("search_results.html", categories=categories, keys=keys, keywords=keywordslist)
示例11: get
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def get(self):
for item in Item.all().filter("deleted ==", True):
if item.item_set.count(1) == 0:
item.delete()
for cl in Checklist.all().filter("deleted ==", True):
if cl.checklist_set.count(1) == 0:
cl.delete()
示例12: del_cat
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [as 别名]
def del_cat(self, del_cat, currt_user):
cat_key = db.Key.from_path("Account", currt_user.nickname(), "Category", del_cat)
category = db.get(cat_key)
items = Item.all()
items.ancestor(cat_key)
for item in items.run():
item.delete()
category.delete()
示例13: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [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)
示例14: edit_image
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [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,
)
示例15: post_comment
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import all [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)