本文整理汇总了Python中models.Item.price方法的典型用法代码示例。如果您正苦于以下问题:Python Item.price方法的具体用法?Python Item.price怎么用?Python Item.price使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.price方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commit_item_changes
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import price [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())
示例2: add_inventory_item_html
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import price [as 别名]
def add_inventory_item_html(form):
name = form.name.data.strip()
description = form.description.data.strip()
quantity = form.quantity.data
price = form.price.data
item = Item.query.filter_by(name=name).first()
if item is None:
item = Item(name=name, description=description, quantity=quantity,
price=price)
db.session.add(item)
else:
item.name = name
item.quantity = quantity
item.price = price
if description != "":
item.description = description
db.session.commit()
return True
示例3: add_inventory_item_json
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import price [as 别名]
def add_inventory_item_json(data):
name = data['name']
description = data['description']
quantity = int(data['quantity'])
price = int(data['price'])
item = Item.query.filter_by(name=name).first()
if item is None:
item = Item(name=name, description=description, quantity=quantity,
price=price)
db.session.add(item)
else:
item.name = name
item.quantity = quantity
item.price = price
if description != "":
item.description = description
db.session.commit()
return jsonify(status="success")
示例4: get_items
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import price [as 别名]
def get_items(soup):
"""
接收 parase() 方法传递的 beautifulsoup 对象,得到包含着Item对象的列表
:param soup: beautifulsoup 对象
:return: 包含着Item对象的列表
"""
ul_container = soup.select('.leftWrap.discovery_list')[0] # 获取包含着所有物品的那个<ul>标签
all_items = ul_container.select('li')
items = [] # 一个装着Item对象的列表
for item in all_items: # 循环中,每一个item都代表<ul>标签下的一个<li>标签
this_item = Item() # 实例化一个新的Item对象
this_item.articleid = item['articleid'] # 获取该<li>标签的 articleid 属性
this_item.link = item.select_one('.picBox')['href'] # 获取链接
this_item.title = item.select_one('.itemName').select_one('.black').text # 获取这个商品的标题
this_item.price = item.select_one('.itemName').select_one('.red').text # 获取这个商品的价格
this_item.date = item.select_one('.time').text
items.append(this_item) # 添加当前的Item对象到items列表
return items
示例5: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import price [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')
示例6: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import price [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')