本文整理汇总了Python中Helper.Helper.getUserKey方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.getUserKey方法的具体用法?Python Helper.getUserKey怎么用?Python Helper.getUserKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helper.Helper
的用法示例。
在下文中一共展示了Helper.getUserKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getUserKey [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
#.........这里部分代码省略.........
示例2: post
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getUserKey [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"
#.........这里部分代码省略.........