本文整理汇总了Python中product.Product类的典型用法代码示例。如果您正苦于以下问题:Python Product类的具体用法?Python Product怎么用?Python Product使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Product类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: manage_beverages_add
def manage_beverages_add():
if request.method == 'POST':
p = Product()
error = None
logging.info(request)
p.name = request.form['name']
#if request.form['price'].isnumeric():
p.price = float(request.form['price'])
#else:
# error = "Preis muss eine Nummer sein."
if 'isshown' in request.form:
p.isshown = True
else:
p.isshown = False
pic = request.files['file']
logging.info(pic.filename)
if pic:
extension = pic.filename.rsplit('.', 1)[1].lower()
logging.info(extension)
if extension == "png" or extension == "jpg":
pic.seek(0) # Move cursor back to beginning so we can write to disk
fpath = os.path.join("./app/static/", "product_%s.png" % p.name)
pic.save(fpath)
if error is None:
add_product(p)
return render_template('manage_beverages_add.html', success="Konsumat hinzugefuegt.", user=get_user_by_name(session.get('name')))
return render_template('manage_beverages_add.html', error=error, user=get_user_by_name(session.get('name')))
return render_template('manage_beverages_add.html', user=get_user_by_name(session.get('name')))
示例2: __init__
def __init__(self, path):
global netCdfReady
Product.__init__(self, path)
print " init class netCDF_Product"
self.netCdfReady=netCDFloaded
self.type=Product.TYPE_NETCDF
self.dataset=None
示例3: get_product_by_name
def get_product_by_name(name):
row = query_db("SELECT * FROM PRODUCTS WHERE NAME = ?", [str(name)], one=True)
p = Product()
p.id = row[0]
p.name = row[1]
p.price = row[2]
p.isshown = row[3]
return p
示例4: get_product_by_id
def get_product_by_id(id):
row = query_db("SELECT * FROM PRODUCTS WHERE ID = ?", [str(id)], one=True)
# print row
p = Product()
p.id = row[0]
p.name = row[1]
p.price = row[2]
p.isshown = row[3]
return p
示例5: addNewProduct
def addNewProduct():
form = AddNewProductForm()
if request.method == "POST" and form.validate():
# Add the new product.
newProduct = Product(form.name.data, float(form.price.data), int(form.stock.data))
newProduct.category = form.category.data
newProduct.description = form.description.data
db.session.add(newProduct)
db.session.commit()
# We should, also, add the product specifications.
# Specifications are sent as a json string. We do this because it
# is really hard to generate dynamic for fields on the client with wtforms.
# The solution is to have a single string field generated with wtforms and
# to simulate the rest of the string fields on the client, when the client
# will submit the form, the values of that fields will be collected and saved
# in that master field. We use a javascript object on the client to track
# the fields an their values, so at the submission the master field will
# contain the json representation of that object.
specifications = json.loads(form.specifications.data)
for spec_name, spec_value in specifications.iteritems():
db.session.add(ProductSpecifications(newProduct.id, spec_name, spec_value))
db.session.commit()
# Now add the images.
pictures = json.loads(form.pictures.data)
for pictureLink in pictures:
db.session.add(ProductPictures(pictureLink, newProduct.id))
db.session.commit()
# Now that the product has an id we can add the rest of the components.
# First, if the product's category is not already in the database we should add it.
category = Categories.query.filter_by(name=newProduct.category).first()
if category is None:
newCategory = Categories(newProduct.category)
db.session.add(newCategory)
db.session.commit()
else:
# The product category may exist, but is unavailable, because there
# are no products available left in it. We should make it available.
if not category.available:
category.available = True
db.session.add(category)
db.session.commit()
return redirect(url_for('productAddedSuccessfully', name=newProduct.name))
flashErrors(form.errors, flash)
return render_template('add_new_product.html',
form=form)
示例6: Main
class Main(Controler):
def __init__(self):
Controler.__init__(self)
self.__sql = core.Sql()
self._brand = Brand()
self._product = Product()
def main(self):
self._product.menu()
示例7: get_products
def get_products():
rows = query_db("SELECT * FROM PRODUCTS")
products = []
for row in rows:
p = Product()
p.id = row[0]
p.name = row[1]
p.price = row[2]
p.isshown = row[3]
products.append(p)
return products
示例8: test_readAndSum
def test_readAndSum(self):
sold=SalesProductList()
sold.addProductsCSV("./csvs/stock-sales_TEST.csv")
eA = Product()
eA.setAddStyle(SalesAddBehavior())
eA=eA.addStyle.addItem(eA, -4, 5, 10) #calculated manually
assert sold['602'].totalCost == eA.totalCost
assert sold['602'].count == eA.count
assert sold['602'].retail == eA.retail
示例9: next_turn
def next_turn(self):
"Reset the city for the next turn"
if self.current_progress >= Product.cost [self.current_product]:
self.current_progress -= Product.cost [self.current_product]
if Product.isUnit(self.current_product):
print ("{:s} has produced product id {:s}".format (self.name, self.current_product))
return Unit (self.x, self.y, self.current_product)
elif Product.isBuilding(self.current_product):
self.city_improvements.append (self.current_product)
self.current_product = Product.NONE
self.current_progress += self.productivity
return None
示例10: test_totalSalesBySKU
def test_totalSalesBySKU(self):
sold = SalesProductList()
sold.addProductsCSV("./csvs/stock-sales_TEST.csv")
eA = Product()
eA.setAddStyle(behavior_accumulate_retail())
eA = eA.addStyle.addItem(eA, -6, 5, 10) # calculated manually
assert sold['602'].totalCost == eA.totalCost
assert sold['602'].count == eA.count
assert sold['602'].retail == eA.retail
assert sold['602'].totalCost == -30
assert sold['602'].count == -6
assert sold['602'].retail == -60
示例11: get_cost
def get_cost(self, connection, run_size=1):
''' Get the total project BOM cost and unit price for a given production run size.
Returns a pair (unit_price, total_cost).'''
self.set_prod_counts(connection)
project_prod_counts = self.prod_counts.copy()
unit_price = 0
total_cost = 0
if 'NULL' in project_prod_counts.keys():
raise NullProductInProjectException(self.get_cost.__name__, 'Warning: Cost calculation does not account for parts with no product assigned!')
for x in project_prod_counts.keys():
project_prod_counts[x] = self.prod_counts[x] * run_size
for x in project_prod_counts.items():
# Find x[0] (the dict key) in the product DB
# x is [manufacturer_pn, qty]
if x[0] == 'NULL':
pass
else:
prod = Product.select_by_pn(x[0], connection)[0]
listing = prod.best_listing(project_prod_counts[x[0]])
price_break = listing.get_price_break(x[1])
unit_price += (price_break[1] * self.prod_counts[x[0]]) + listing.reel_fee
total_cost += (price_break[1] * project_prod_counts[x[0]]) + listing.reel_fee
return (unit_price, total_cost)
示例12: __init__
def __init__(self):
Controler.__init__(self)
self.__sql = core.Sql()
self._brand = Brand()
self._product = Product()
示例13: __add_data_to_dict
def __add_data_to_dict(self):
print("Collecting data to dictionary:")
data = ReturnData()
for pdf in self.pdf_list:
notes = Notes()
try:
pdf_without_notes, notes = notes.extract_notes(pdf)
except:
continue #check impact
else:
if notes is None:
data.files_skipped += 1
print("NOT PREPPED: ", pdf_without_notes[:7])
else:
product = Product.factory(pdf_without_notes, notes)
row = product.merge_notes_without_csv()
key = notes["stock"]
if notes["type"] == "FLAT":
data.rows_flat.setdefault(key,[]).append(row)
elif notes["type"] == "BOUND":
data.rows_bound.setdefault(key, []).append(row)
print("ADDED!!: ", pdf[:7])
data.files_added_to_csv += 1
print("All data in dictionary!")
return data
示例14: test_search_sanity
def test_search_sanity(self):
our_products = []
products = self.seach.search(self.product_group, self.keyword)
our_products_item = self.api.item_search(self.product_group, Keywords=self.keyword)
for index, item in enumerate(our_products_item):
if index == self.MAX_RESULTS:
break
browse_nodes = self.api.item_lookup(ItemId=item.ASIN, ResponseGroup='OfferListings,\
BrowseNodes,\
OfferSummary,\
Offers,\
Images')
product = Product(item, browse_nodes)
if (product.get_img_url('SmallImage') == 'null') or \
(product.get_img_url('MediumImage') == 'null' and product.get_img_url('LargeImage') == 'null'):
index -= 1
continue
if product.get_rating() == 'null' or \
product.get_review() == 'null' or product.get_price() == 'null':
index -= 1
continue
our_products.append(product)
products_ASIN = [product.ASIN for product in products]
our_products_ASIN = [product.ASIN for product in our_products]
self.assertItemsEqual(products_ASIN,our_products_ASIN)
示例15: write
def write(user_id, password, model, odoo_id, vals):
_check_user(user_id, password)
if model not in ["customer", "product"]:
raise Fault("unknown_model", "Reference model does not exist!")
if model == "customer":
try:
customer = Customer.get(Customer.odoo_id == odoo_id)
except Customer.DoesNotExist:
raise Fault("unknown_registry", "Customer not found!")
q = Customer.update(**vals).where(Customer.odoo_id == odoo_id)
else:
try:
product = Product.get(Product.odoo_id == odoo_id)
except Product.DoesNotExist:
raise Fault("unknown_registry", "Product not found!")
q = Product.update(**vals).where(Product.odoo_id == odoo_id)
q.execute()
return True