本文整理汇总了Python中models.Item.put方法的典型用法代码示例。如果您正苦于以下问题:Python Item.put方法的具体用法?Python Item.put怎么用?Python Item.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [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('newItem')
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())
if items.get() == None:
newItem = Item(item = item, win = 0, lose = 0, rate = 0, parent = c.key()) # post a new item
newItem.put() # save
else:
errorMessage = "Item %s already exists!" % item
self.redirect("/manageCategory?category=%s&error=%s" % (category, errorMessage))
return
self.redirect("/manageCategory?category=%s" % category)
示例2: save_edited_category
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [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)
示例3: commit_item_changes
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def commit_item_changes(self,item=None):
creation=not(item)
if not item: item=Item(parent=self.current_user.key())
item_name=self.request.get('name')
item_price=self.request.get('price')
item_description=rich_text.from_style_runs(self.request.get('description'))
item_picture=self.request.get('picture_512')
errors=[]
if item_name=="": errors.append("The item name must not be blank.")
if item_description=="": errors.append("The item description must not be blank.")
try:
item_price=float(item_price)
except ValueError:
errors.append("The price must be a number.")
if item_price <=0: errors.append("The price must be greater than zero.")
if len(errors):
self.render_template('items/form.html',title="Add an Item",item_picture_data=item_picture,item_picture=("data:image/png;base64,%s"%item_picture if item_picture or creation else item.url(named=False,action="picture")),errors=errors,item_expiry=datetime.now()+Item.EXPIRATION_DELTA,item_name=item_name,item_description=item_description,item_price=item_price)
else:
item.name=item_name
item.price=item_price
item.description=item_description
if item_picture: item.picture=base64.b64decode(item_picture)
item.put()
self.log("item %s"%("created" if creation else "edited"))
self.flash("'%s' was %s!"%(item_name,"created" if creation else "edited"))
self.redirect(self.current_user.url())
示例4: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def post(self):
name = self.request.get('name')
itemNum = self.request.get('itemNum')
origin = self.request.get('origin')
item_post = Item(name=name, itemNum=itemNum, origin=origin)
item_post.put()
self.redirect('/')
示例5: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def post(self):
try:
newitem = Item(name = self.request.get('name'),
price = int(self.request.get('price')),
quantity = int(self.request.get('quantity')),
description = self.request.get('description'))
newitem.put()
except ValueError:
return self.error(500)
self.redirect('/')
示例6: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [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)
示例7: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def post(self):
checklist = Checklist.get(Key(self.request.get('cl_key')))
if not helpers.checkPermissionAndRespond(self, cl=checklist): return
item = Item(
title=self.request.get('title'),
checklist=checklist,
deleted=False)
item.put()
helpers.createResponse(self, 'new_item.html', {'item': item})
示例8: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def post(self):
user = users.get_current_user()
if user is None:
login_url = users.create_login_url('/home')
template_data = {}
template_data['login_url'] = login_url
template = JINJA_ENVIRONMENT.get_template('login.html')
self.response.write(template.render(template_data))
return
residence = Residence.get_residence_by_user(user)
category = self.request.get('category')
name = self.request.get('name')
price = self.request.get('price')
room_name = self.request.get("room")
if name.strip() == '' or category.strip() == '':
if room_name == "miscellaneous":
self.redirect("home")
else:
self.redirect("/room-tour?room=" + urllib.quote(room_name))
return
price = float(price)
inventory = Inventory.get_inventory_by_user(user)
item = Item(category=category, name=name, price=price, parent=inventory.key)
item.put()
residence = Residence.get_residence_by_user(user)
room = Room.query(ancestor=residence.key).filter(Room.name==room_name).get()
if room is None:
room = Room(name=room_name, parent=residence.key)
room.put()
relation = ItemRoomRelation(item=item.key, room=room.key, parent=inventory.key)
relation.put()
if room_name == "miscellaneous":
self.redirect("/home")
return
self.redirect("/room-tour?room=" + urllib.quote(room_name))
示例9: save_new_category
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [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)
示例10: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def post(self):
user = users.get_current_user()
item_name = self.request.get("item_name")
item_description = self.request.get("item_description")
item_price = float(self.request.get("item_price"))
memento_user_query = ndb.gql("SELECT * from MementoUser WHERE user_name = :1", user.nickname())
curr_memento_user = memento_user_query.get()
curr_memento_user_key = curr_memento_user.key
existing_items = Item.query(ancestor=curr_memento_user_key)
alreadyExists = existing_items.filter(ndb.GenericProperty("item_name") == item_name)
if (alreadyExists.count(limit=1000) == 0):
new_item = Item(parent = curr_memento_user_key, item_name = item_name, item_price = item_price, item_description = item_description)
new_item.put()
curr_memento_user.user_data.get().inventory.append(new_item.key)
curr_memento_user.user_data.get().put()
self.redirect("/VendorHub")
示例11: add_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [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()
示例12: item_create
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def item_create(replace_key=None):
if replace_key:
item = replace_key.get()
else:
url_safe_name = make_url_safe(request.form.get('name'))
item = Item(id = url_safe_name)
item.populate(
name = request.form.get('name'),
description = request.form.get('description'),
count = int(request.form.get('count')) if request.form.get('count') else 1,
prices = [float(request.form.get('price_int')) if request.form.get('price_int') else 0,
float(request.form.get('price_ext')) if request.form.get('price_ext') else 0,
float(request.form.get('price_com')) if request.form.get('price_com') else 0,
float(request.form.get('price_buy')) if request.form.get('price_buy') else 0,
],
tax_per_day = True if request.form.get('tax_per_day') else False,
category = request.form.get('category'),
)
id = item.put().id()
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
示例13: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def post(self):
#Getting Inputs
itemname=self.request.get("item_name")
itemtype=self.request.get("item_type")
itemdescription=self.request.get("item_description")
itemprice=self.request.get("item_price")
itemstock=self.request.get("item_stock")
#Placing data in model
item=Item()
item.name=itemname
item.type=itemtype
item.description=itemdescription
item.price=itemprice
item.stock=itemstock
item.owner=users.get_current_user().email()
item.put()
self.redirect('success')
示例14: crawl_something
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def crawl_something(something):
import json
o = open('output.json', 'r')
j = json.loads(o.read())
for item in j:
widgets = {}
if item['widgets']['image_carousel']:
widgets['image_carousel'] = item['widgets']['image_carousel']
if item['widgets']['amazon_highlights']:
widgets['review_highlights'] = review_highlights_(item['widgets']['amazon_highlights'])
attributes = ""
if item['']
item_ = Item(name=item['name'][0], widgets=widgets, )
item_.put()
def warmup():
"""App Engine warmup handler
See http://code.google.com/appengine/docs/python/config/appconfig.html#Warming_Requests
"""
return ''
示例15: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import put [as 别名]
def post(self):
url = urlfetch.fetch(self.request.get('content'))
doc = lxml.html.fromstring(url.content)
for sku in doc.cssselect('span'):
if sku.get('id') == 'displaySkuCode':
item_id = sku.text
registry_item = Item.get_by_id(item_id)
if registry_item is None:
registry_item = Item(id=item_id, parent=ndb.Key("Website", self.request.get('website')))
for tag in doc.cssselect('title'):
registry_item.title = tag.text.encode('utf-8')
for img in doc.cssselect('link'):
if img.get('rel') == 'image_src':
registry_item.img = img.get('href')
for price in doc.cssselect('div'):
if price.get('class') == 'sale-price':
for savings in price.cssselect('strong'):
registry_item.sale = savings.text.encode('utf-8')
if price.get('class') == 'reg-price':
registry_item.price = price.text.encode('utf-8').replace("Reg.", "")
registry_item.category = self.request.get('category')
registry_item.for_who = self.request.get('for_who')
registry_item.put()
link = URL.get_by_id(item_id)
if link is None:
link = URL(id=item_id, parent=ndb.Key("Website", self.request.get('website')))
link.url = self.request.get('content')
link.last_scrape = datetime.datetime.now()
link.put()
self.redirect('/listings')