本文整理汇总了Python中Helper.Helper.getCategoryKey方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.getCategoryKey方法的具体用法?Python Helper.getCategoryKey怎么用?Python Helper.getCategoryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helper.Helper
的用法示例。
在下文中一共展示了Helper.getCategoryKey方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getCategoryKey [as 别名]
def post(self):
user = users.get_current_user()
message=""
if user:
category = self.request.get("category")
isExport = self.request.get("isExport")
owner = self.request.get("owner")
if isExport:
self.exportToXml(owner,category)
else:
newItemName = self.request.get("item_name").strip()
ifAlreadyExists = Item.gql("WHERE name = :1 AND ANCESTOR IS :2",newItemName,Helper.getCategoryKey(user.email(), category))
if (ifAlreadyExists.count() == 0) and newItemName:
item = Item(parent=Helper.getCategoryKey(user.email(), category))
item.name = self.request.get("item_name")
item.wins = 0
item.loses = 0
item.put()
else:
if newItemName:
message = "Item already exists"
else:
message = "Item name cannot be empty or spaces"
items = db.GqlQuery("SELECT * FROM Item WHERE ANCESTOR IS :1",Helper.getCategoryKey(user.email(), category))
template_values = {
'items' : items,
'category' : category,
'message' : message,
'logoutURL' : users.create_logout_url('./'),
'user':user,
'owner' : owner
}
path = os.path.join(os.path.dirname(__file__), './html/items.html')
self.response.out.write(template.render(path, template_values))
else:
self.redirect(users.create_login_url(self.request.uri))
示例2: post
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getCategoryKey [as 别名]
def post(self):
itemName = self.request.get("itemName")
categoryName = self.request.get("categoryName")
userEmail = self.request.get("userEmail")
comment = self.request.get("comment")
owner = self.request.get("owner")
comment = str(comment).strip()
message = ""
if comment:
ifAlreadyExists = []
#self.response.out.write("Key is "+ str(Helper.getItemKey(userEmail, categoryName, itemName)))
ifAlreadyExists = ItemComment.gql("WHERE ANCESTOR IS :1",Helper.getItemKey(userEmail, categoryName, itemName))
#self.response.out.write("Key is "+ str(Helper.getItemKey(userEmail, categoryName, itemName)))
#self.response.out.write("Count is "+ str(ifAlreadyExists.count()))
if (ifAlreadyExists.count() == 0):
#self.response.out.write("Adding comment for " + itemName + " " + categoryName + " " + userEmail)
itemComment = ItemComment(parent=Helper.getItemKey(userEmail, categoryName, itemName))
itemComment.comment = comment
itemComment.commenter = userEmail
itemComment.item = itemName
itemComment.category = categoryName
itemComment.put()
message="Comment Saved"
else:
message="You can comment only once on an item"
else:
#self.response.out.write("empty comment")
message = "Cannot enter empty comment"
items = Item.gql("WHERE ANCESTOR IS :1",Helper.getCategoryKey(owner, categoryName))
template_values = {
'items' : items,
'owner': owner,
'user' : users.get_current_user(),
'category' : categoryName,
'logoutURL' : users.create_logout_url('./'),
'message' : message
}
path = os.path.join(os.path.dirname(__file__), './html/items.html')
self.response.out.write(template.render(path, template_values))
示例3: exportToXml
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getCategoryKey [as 别名]
def exportToXml(self, owner, category):
self.response.headers['Content-Type'] = 'text/xml'
file_name = category.replace(' ', '_')
self.response.headers['Content-Disposition'] = "attachment; filename=" + str(file_name) + ".xml"
# create xml file
# get all items in the chosen category
items = db.GqlQuery("SELECT * "
"FROM Item "
"WHERE ANCESTOR IS :1 ",
Helper.getCategoryKey(owner, category))
root = Element('CATEGORY')
categoryName = SubElement(root, 'NAME')
categoryName.text = category
# create intermediate nodes for each item
for item in items:
itemTag = SubElement(root, 'ITEM')
itemNameTag = SubElement(itemTag, 'NAME')
itemNameTag.text = item.name
self.response.out.write(tostring(root, encoding="us-ascii", method="xml"))
示例4: get
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getCategoryKey [as 别名]
def get(self):
user = users.get_current_user()
if user:
category = self.request.get("category")
owner = self.request.get("owner")
newCategoryName = self.request.get("newCategoryName").strip()
newItemName = self.request.get("newItemName").strip()
oldItemName = self.request.get("oldItemName").strip()
displayItems = True
if newCategoryName:
owner = user.email()
if newCategoryName != "delete":
ifAlreadyExists = Category.gql("WHERE name = :1 and ANCESTOR IS :2",newCategoryName,Helper.getUserKey(user.email()))
if ifAlreadyExists.count() == 0:
newCategory = Category(parent=Helper.getUserKey(user.email()))
newCategory.name = newCategoryName
newCategory.put()
items = Item.gql("WHERE ANCESTOR IS :1", Helper.getCategoryKey(user.email(), category))
for item in items:
newItem = Item(parent=Helper.getCategoryKey(user.email(), newCategory.name))
newItem.name = item.name
newItem.wins = item.wins
newItem.loses = item.loses
newItem.put()
Item.delete(item)
categoryToEdit = Category.gql("WHERE name = :1 and ANCESTOR IS :2",category,Helper.getUserKey(user.email()))[0]
Category.delete(categoryToEdit)
message = category + " renamed to " + newCategoryName
category = newCategoryName
else:
message = "Category already exists"
displayItems = True
else:
categoryToDelete = Category.gql("WHERE name = :1 and ANCESTOR IS :2",category,Helper.getUserKey(user.email()))[0]
items = Item.gql("WHERE ANCESTOR IS :1", Helper.getCategoryKey(user.email(), category))
for item in items:
Item.delete(item)
Category.delete(categoryToDelete)
message = category + " deleted "
#self.redirect("./categories", permanent=False)
categories = db.GqlQuery("SELECT * "
"FROM Category ")
# "WHERE ANCESTOR IS :1",
# Helper.getUserKey(user.email()))
template_values = {
'categories' : categories,
'user':user,
'logoutURL' : users.create_logout_url('./'),
'message' : message
}
displayItems = False
path = os.path.join(os.path.dirname(__file__), './html/category.html')
self.response.out.write(template.render(path, template_values))
if newItemName:
owner = user.email()
if newItemName != "delete":
ifAlreadyExists = Item.gql("WHERE name = :1 and ANCESTOR IS :2",newItemName, Helper.getCategoryKey(user.email(), category))
if ifAlreadyExists.count() == 0:
itemToEdit = Item.gql("WHERE name = :1 and ANCESTOR IS :2",oldItemName, Helper.getCategoryKey(user.email(), category))[0]
itemToEdit.name = newItemName
itemToEdit.wins = 0
itemToEdit.loses = 0
itemToEdit.put()
message = oldItemName + " renamed to " + newItemName
else:
message = "Item already exists"
displayItems = True
else:
itemToDelete = Item.gql("WHERE name = :1 and ANCESTOR IS :2",oldItemName, Helper.getCategoryKey(user.email(), category))[0]
Item.delete(itemToDelete)
message = oldItemName + " deleted "
displayItems = True
if displayItems:
items = db.GqlQuery("SELECT * FROM Item WHERE ANCESTOR IS :1",Helper.getCategoryKey(owner, category))
template_values = {
'items' : items,
'owner': owner,
'user' : user,
'category' : category,
'logoutURL' : users.create_logout_url('./'),
'ItemComment':ItemComment,
'Helper':Helper
#.........这里部分代码省略.........
示例5: get
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getCategoryKey [as 别名]
def get(self):
user = users.get_current_user()
if user:
#check for key, if not exist show all categories from all users
key = self.request.get("key")
wKey = self.request.get("wKey")
lKey = self.request.get("lKey")
if (key and ( not (wKey and lKey) ) ):
#item_1 = Item.all().order('rand_num').filter('rand_num >=', rand_num).filter(k, value) .get()
key = db.Key(key)
parentCategory = Category.gql("WHERE __key__ = :1",key)
categoryUser = key.parent().name()
items = db.GqlQuery("SELECT * FROM Item WHERE ANCESTOR IS :1",Helper.getCategoryKey(categoryUser, parentCategory[0].name))
if( items.count() >= 2):
item_1 = "Not Enough Items"
item_2 = "Not Enough Items"
randomNumber_1 = random.randint(0,items.count() - 1 )
randomNumber_2 = randomNumber_1
while(randomNumber_1 == randomNumber_2):
randomNumber_2 = random.randint(0,items.count() - 1 )
item_1 = items[randomNumber_1]
item_2 = items[randomNumber_2]
message="Click on one of the Items to vote"
template_values = {
'item_1': item_1,
'item_2': item_2,
'message':message,
'key':key,
'logoutURL' : users.create_logout_url('./')
}
else:
message = "Not enough items in this category. Choose another category."
template_values = {
'message':message,
'key':key,
'logoutURL' : users.create_logout_url('./')
}
path = os.path.join(os.path.dirname(__file__), './html/vote.html')
self.response.out.write(template.render(path, template_values))
elif (key and ( (wKey and lKey) )):
key = db.Key(key)
wKey = db.Key(wKey)
lKey = db.Key(lKey)
winningItem = Item.gql("WHERE __key__ = :1",wKey)[0]
losingItem = Item.gql("WHERE __key__ = :1",lKey)[0]
winningItem.wins = winningItem.wins + 1
winningItem.put()
losingItem.loses = losingItem.loses + 1
losingItem.put()
#self.redirect("./vote?category=%s", permanent=False)
message = winningItem.name + ' wins over ' + losingItem.name
#get 2 new random items
key = self.request.get("key")
key = db.Key(key)
parentCategory = Category.gql("WHERE __key__ = :1",key)
categoryUser = key.parent().name()
items = db.GqlQuery("SELECT * FROM Item WHERE ANCESTOR IS :1",Helper.getCategoryKey(categoryUser, parentCategory[0].name))
item_1 = "Not Enough Items"
item_2 = "Not Enough Items"
if( items.count() != 0):
randomNumber_1 = random.randint(0,items.count() - 1 )
randomNumber_2 = randomNumber_1
while(randomNumber_1 == randomNumber_2):
randomNumber_2 = random.randint(0,items.count() - 1 )
item_1 = items[randomNumber_1]
item_2 = items[randomNumber_2]
#.........这里部分代码省略.........
示例6: get
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getCategoryKey [as 别名]
def get(self):
user = users.get_current_user()
if user:
key = self.request.get('key')
if key:
#do something
key = db.Key(key)
parentCategory = Category.gql("WHERE __key__ = :1",key)
categoryUser = key.parent().name()
items = db.GqlQuery("SELECT * FROM Item WHERE ANCESTOR IS :1 ORDER BY wins DESC",Helper.getCategoryKey(categoryUser, parentCategory[0].name))
# items = Item.gql("WHERE ANCESTOR IS :1",getCategoryKey(user.email(), category))
template_values = {
'items': items,
'logoutURL' : users.create_logout_url('./')
}
else:
categories = db.GqlQuery("SELECT * FROM Category")
template_values = {
'categories': categories,
'logoutURL' : users.create_logout_url('./')
}
path = os.path.join(os.path.dirname(__file__), './html/results.html')
self.response.out.write(template.render(path, template_values))
else:
self.redirect(users.create_login_url(self.request.uri))
示例7: post
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getCategoryKey [as 别名]
def post(self):
user = users.get_current_user()
action = self.request.get("action")
inputXML = self.request.get("chooseFile")
message=" "
if user:
if (action == "import"):
if inputXML:
try:
root = ET.fromstring(inputXML)
#self.response.out.write("ROOT IS - "+ root.tag)
if (root is not None) and (root.tag == "CATEGORY"):
cat = root.find('NAME')
if (cat is not None) and (cat.text):
category = Category.gql("WHERE name = :1 and ANCESTOR IS :2", cat.text ,Helper.getUserKey(user.email()))
if category.count() == 0:
#self.response.out.write( "Cat doesnt exist. Creating new category and adding all new items")
category = Category(parent=Helper.getUserKey(user.email()))
category.name = cat.text
category.put()
for item in root.findall('ITEM'):
if len(item.findall('NAME')) == 1 and (item.find('NAME').text.strip()):
itemName = item.find('NAME').text.strip()
newItem = Item(parent=Helper.getCategoryKey(user.email(), category.name))
newItem.name = itemName
newItem.wins = 0
newItem.loses = 0
newItem.put()
else:
#self.response.out.write("Invalid XML more/less than one name for Item")
message= "Invalid XML more/less than one name for Item"
Category.delete(category)
else:
category = category[0]
#self.response.out.write("<br/>Category already exists<br/>")
#check for new items in XML and add them in datastore
itemsInXml = []
itemsSaved = []
escape = False
for item in root.findall('ITEM'):
#check if there are more than one Item names
if (len(item.findall('NAME')) == 1) and (item.find('NAME').text.strip()):
itemName = item.find('NAME').text.strip()
#self.response.out.write("Checking for Item "+itemName + "<br/>")
newItem = Item.gql("WHERE name = :1 AND ANCESTOR IS :2",itemName,Helper.getCategoryKey(user.email(), category.name))
#self.response.out.write("Count " + str(newItem.count()) +"<br/>")
if newItem.count() == 0:
# self.response.out.write("Item "+ itemName+ " doesnot exist. Adding it<br/>")
newItem = Item(parent=Helper.getCategoryKey(user.email(), category.name))
newItem.name = itemName
newItem.wins = 0
newItem.loses = 0
newItem.put()
itemsSaved.append(item)
itemsInXml.append(itemName)
else:
# self.response.out.write("Invalid XML more/less than one name for Item")
message = "Invalid XML more/less than one name for Item"
for item in itemsSaved:
Item.delete(item)
escape = True
#raise Exception("IGNORE")
if not escape:
#check for items in Datastore that are not in XML. Delete them
#items = Item.all()
items = Item.gql("WHERE ANCESTOR IS :1",Helper.getCategoryKey(user.email(), category.name))
for item in items:
#self.response.out.write("Checking for "+ item.name + " in XML <br/>")
try:
itemsInXml.remove(item.name)
# self.response.out.write(item.name + " is there in XML. Retain it <br/>")
except ValueError:
# self.response.out.write("Item "+ item.name+ " is not there in XML. Deleting<br/>")
Item.delete(item)
else:
#self.response.out.write("Invalid XML no Cat name")
message = "Invalid XML no Cat name"
else:
# self.response.out.write("Invalid XML")
message = "Invalid XML"
except:
# self.response.out.write("Invalid File")
message = "Invalid File"
else:
#self.response.out.write("Please choose file")
message = "Please choose a file"
categories = db.GqlQuery("SELECT * "
"FROM Category ")
#message = "invalid xml"
#.........这里部分代码省略.........