当前位置: 首页>>代码示例>>Python>>正文


Python Product.get_by_key_name方法代码示例

本文整理汇总了Python中models.Product.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Product.get_by_key_name方法的具体用法?Python Product.get_by_key_name怎么用?Python Product.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Product的用法示例。


在下文中一共展示了Product.get_by_key_name方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_reserved

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def test_reserved(self):
     qty = random.randint(1,10)
     print ' To reserve: ',qty,
     if Product.reserve(self.name,qty):
         p = Product.get_by_key_name(self.name)
         print ' AVAILABLE: ',p.available
         self.assertEqual(p.available, p.stock - qty, 'Not reserving correctly')
     else:
         p = Product.get_by_key_name(self.name)
         print ' Not enough stock', p.available
         self.assertGreater(qty, p.available, 'Not reserving correctly')
开发者ID:itaogit,项目名称:shopapp,代码行数:13,代码来源:tests-cart.py

示例2: test_stocked

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def test_stocked(self):
     qty = random.randint(1,10)
 
     print ' To buy: ',qty,
     if Product.reserve(self.name,qty):
         p = Product.get_by_key_name(self.name)
         before = p.reserved
         Product.remove_stock(self.name,qty)
         p = Product.get_by_key_name(self.name)
         print ' AVAILABLE: ',p.available
         self.assertEqual(p.available, p.stock, 'Not lowering stock correctly ')
         self.assertEqual(before - qty,p.reserved, 'Not lowering reserves correctly')
     else:
         p = Product.get_by_key_name(self.name)
         print ' Not enough stock', p.available
         self.assertGreater(qty, p.available, 'Not reserving correctly')
开发者ID:itaogit,项目名称:shopapp,代码行数:18,代码来源:tests-cart.py

示例3: get

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def get(self, subdomain=None):
     #args
     item = self.request.get('item','-')
     qty = int(self.request.get('qty',1))
     
     '''NAMESPACE CHANGE (memcache and datastore)'''
     namespace = namespace_manager.get_namespace()
     namespace_manager.set_namespace(subdomain)
     
     #15 mins session (900 secs), if a previous session does not exist it creates a new one
     self.session = self.session_store.get_session(name='mc_session',max_age=900,backend='memcache')
     try:
         cart = self.session['cart']
         logging.info('cart found in memcache :)')
     except:
         return self.response.write('Not cart in session or the session has expired')
         
     
     product = Product.get_by_key_name(item)
     
     if not product: return self.response.write('The product does not exist')
     elif product.unreserve(qty):
         '''It was not removed from stock'''
         cart.remove_item(CartItem(product),qty)
     else:
         self.response.write('Some products were not reserved. Probably the session expired')
         
         
     self.session['cart'] = cart
     self.session_store.save_sessions(self.response)
     '''NAMESPACE CHANGE'''
     namespace_manager.set_namespace(namespace)
     
     return self.response.write(str(cart))
开发者ID:itaogit,项目名称:shopapp,代码行数:36,代码来源:checkout.py

示例4: details_search

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
def details_search(request):
    p = Product.get_by_key_name(request.GET["app"], None)
    if not p:
        raise Http404("Product cannot be found")
    return render_to_response('store/details.html', 
                              { 'p': p }, 
                              RequestContext(request))
开发者ID:nicocrm,项目名称:Sailfish.Web,代码行数:9,代码来源:views.py

示例5: post_delete

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def post_delete(self, obj_key):
     obj = Product.get_by_key_name(obj_key)
     # For some reason, obj.user.key.name doesn't work here, so we just figure out what the user key is using the email address.
     # This is a hack which WILL NOT work if we change how user keys work. Need to figure out the right way to do this.
     obj_user_key = obj.user.email.split('@')[0]
     if obj_user_key == self.session['user_key']:
         Crud.post_delete(self, obj_key)
         self.redirect('/user/r/'+self.session['user_key'])
     else:
         self.redirect('/error/not_owner')
开发者ID:maedayx,项目名称:swapshire2,代码行数:12,代码来源:main.py

示例6: test_price_tax_cart

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def test_price_tax_cart(self):   
     value_tax_included = 0.0
     for i in range(3):
         p = Product.get_by_key_name(self.products[i])
         cart_item = CartItem(p)
         qty = random.randint(1,10)
         #qty = 1
         value_tax_included += cart_item.final_price*qty
         self.cart.add_item(cart_item, qty)
     #print value_tax_included, self.cart.total_without_tax, self.cart.sub_total_tax, self.cart.sub_total_price, self.cart.total
     self.assertEqual(round(value_tax_included,2), round(self.cart.sub_total_price,2), 'taxes not being calculated well')
开发者ID:itaogit,项目名称:shopapp,代码行数:13,代码来源:tests-cart.py

示例7: test_price_cart

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def test_price_cart(self):
     #3 random products in cart
     value = 0.0
     for i in range(3):
         p = Product.get_by_key_name(self.products[i])
         #print p.price,
         value += p.price
         
         self.cart.add_item(CartItem(p),1)
     #print value, self.cart.total_without_tax, self.cart.sub_total_tax, self.cart.sub_total_price, self.cart.total
     self.assertEqual(round(value,2), round(self.cart.total_without_tax,2), 'price not matching')
开发者ID:itaogit,项目名称:shopapp,代码行数:13,代码来源:tests-cart.py

示例8: setUp

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def setUp(self):
     self.products = []
     self.cart = Cart()
     for i in range(1,10):
         product = Product(product_id=i, key_name="test_product_"+str(i),price=round(random.uniform(1,10),2),tax_percent=18.00)
         product.put()
         product.add_stock("test_product_"+str(i),10)
         self.products.append("test_product_"+str(i))
         p = Product.get_by_key_name("test_product_"+str(i))
         self.cart.add_item(CartItem(p), random.randint(1,10))
     
     random.shuffle(self.products)
开发者ID:itaogit,项目名称:shopapp,代码行数:14,代码来源:tests-cart.py

示例9: activate

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
def activate(request):
    """
    Make sure the user has the product (identify using PIN), and return
    activation code.
    """
    pin = request.GET['pin']
    p = Product.get_by_key_name(request.GET["app"], None)
    if not p:
        raise Http404("Product not found")
    userproduct = UserProduct.gql("where pin = :1 and product = :2", 
                                  pin, p).get()
    if not userproduct:
        raise Http404("Activation data not found")
    return HttpResponse(userproduct.get_activation_code(), mimetype='text/plain')
开发者ID:nicocrm,项目名称:Sailfish.Web,代码行数:16,代码来源:views.py

示例10: test_reserved_stock

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def test_reserved_stock(self):
     #3 random products in cart
     value = 0.0
     result = 0
     items_no = 0
     for i in range(3):
         qty = random.randint(1,10)
         print 'product: ', self.products[i], ' to reserve: ',qty,
         if Product.reserve(self.products[i],qty):
             p = Product.get_by_key_name(self.products[i])
             #print p.stock, p.reserved
             self.cart.add_item(CartItem(p),qty)
             result += qty
             items_no +=1
         #p = Product.get_by_key_name(self.products[i])
     print self.cart.total_different_items, items_no
     self.assertEqual(self.cart.total_different_items, items_no, 'Error in total different items')
     self.assertEqual(self.cart.total_items, result, 'Error in total_items')
开发者ID:itaogit,项目名称:shopapp,代码行数:20,代码来源:tests-cart.py

示例11: test_totals_with_delivery

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
 def test_totals_with_delivery(self):
     print '----------------- TEST RfB TOTALS --------------------'
     
     self.cart.delivery = {'price':2.5,'tax':15.0,'name':'testDelivery'}
     self.cart.recalc()
     delivery_gross = self.cart.delivery['price'] + self.cart.delivery['price'] * self.cart.delivery['tax']/100
     delivery_tax = self.cart.delivery['price'] * self.cart.delivery['tax'] / 100
     delivery_net = self.cart.delivery['price']
     print 'DELIVERY ','price:', self.cart.delivery['price'], 'plus tax:', delivery_gross, 'tax percent:', self.cart.delivery['tax'],'price tax:', delivery_tax
     
     sub_total_tax_items = self.cart.sub_total_tax_items #TAX Items
     sub_total_price = self.cart.sub_total_price #GROSS Items
     total = self.cart.total #GROSS Items + GROSS Delivery
     total_without_tax = self.cart.total_without_tax  #NET Items + NET Delivery
     total_tax =  self.cart.total_tax #TAX items + TAX Delivery
     
     for i in range(3):
         qty = random.randint(1,10)
         qty=1
         p = Product.get_by_key_name(self.products[i])
         print self.products[i],'price:', p.price, 'plus tax:', p.price + p.price * p.tax_percent / 100,'tax percent: ',p.tax_percent, 'price tax:',p.price * p.tax_percent / 100, 'qty:',qty
         sub_total_tax_items -= (p.price * p.tax_percent / 100)*qty
         sub_total_price -=  (p.price + p.price * p.tax_percent / 100)*qty
         total -= (p.price + p.price * p.tax_percent / 100)*qty
         total_without_tax -=  (p.price)*qty
         total_tax -= (p.price * p.tax_percent / 100)*qty
         
         self.cart.remove_item(CartItem(p),qty)
     
     print 'sub_total_tax_items: ', sub_total_tax_items, ' CART sub_total_tax_items: ',self.cart.sub_total_tax_items
     self.assertAlmostEqual(sub_total_tax_items, self.cart.sub_total_tax_items,7, 'Error calculating sub_total_tax_items')
     
     print 'sub_total_price: ', sub_total_price, ' CART sub_total_price: ',self.cart.sub_total_price
     self.assertEqual(round(sub_total_price,2), round(self.cart.sub_total_price,2), 'Error calculating sub_total_price')
     
     print 'total: ', total, ' CART total: ',self.cart.total
     self.assertEqual(round(total,2), round(self.cart.total,2), 'Error calculating total')
     
     print 'total_without_tax: ', total_without_tax, ' CART total_without_tax: ',self.cart.total_without_tax
     self.assertEqual(round(total_without_tax,2), round(self.cart.total_without_tax,2), 'Error calculating total_without_tax')
     
     print 'total_tax: ', total_tax, ' CART total_tax: ',self.cart.total_tax
     self.assertEqual(round(total_tax,2), round(self.cart.total_tax,2), 'Error calculating total_tax')
     print '----------------- END TEST -----------------------' 
开发者ID:itaogit,项目名称:shopapp,代码行数:46,代码来源:tests-cart.py

示例12: purchase_search

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import get_by_key_name [as 别名]
def purchase_search(request):
    return purchase_do(request, Product.get_by_key_name(request.GET["app"], None))
开发者ID:nicocrm,项目名称:Sailfish.Web,代码行数:4,代码来源:views.py


注:本文中的models.Product.get_by_key_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。